Documentation ¶
Index ¶
- Constants
- func MemTotal() (uint64, error)
- func MemUsed() (uint64, error)
- type ActionOnExceed
- type LogOnExceed
- type PanicOnExceed
- type Tracker
- func (t *Tracker) AttachTo(parent *Tracker)
- func (t *Tracker) BytesConsumed() int64
- func (t *Tracker) BytesToString(numBytes int64) string
- func (t *Tracker) Consume(bytes int64)
- func (t *Tracker) Detach()
- func (t *Tracker) MaxConsumed() int64
- func (t *Tracker) ReplaceChild(oldChild, newChild *Tracker)
- func (t *Tracker) SetActionOnExceed(a ActionOnExceed)
- func (t *Tracker) SetLabel(label fmt.Stringer)
- func (t *Tracker) String() string
Constants ¶
const ( // PanicMemoryExceed represents the panic message when out of memory quota. PanicMemoryExceed string = "Out Of Memory Quota!" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ActionOnExceed ¶
type ActionOnExceed interface { // Action will be called when memory usage exceeds memory quota by the // corresponding Tracker. Action(t *Tracker) // SetLogHook binds a log hook which will be triggered and log an detailed // message for the out-of-memory sql. SetLogHook(hook func(uint64)) }
ActionOnExceed is the action taken when memory usage exceeds memory quota. NOTE: All the implementors should be thread-safe.
type LogOnExceed ¶
type LogOnExceed struct { ConnID uint64 // contains filtered or unexported fields }
LogOnExceed logs a warning only once when memory usage exceeds memory quota.
func (*LogOnExceed) Action ¶
func (a *LogOnExceed) Action(t *Tracker)
Action logs a warning only once when memory usage exceeds memory quota.
func (*LogOnExceed) SetLogHook ¶
func (a *LogOnExceed) SetLogHook(hook func(uint64))
SetLogHook sets a hook for LogOnExceed.
type PanicOnExceed ¶
type PanicOnExceed struct { ConnID uint64 // contains filtered or unexported fields }
PanicOnExceed panics when memory usage exceeds memory quota.
func (*PanicOnExceed) Action ¶
func (a *PanicOnExceed) Action(t *Tracker)
Action panics when memory usage exceeds memory quota.
func (*PanicOnExceed) SetLogHook ¶
func (a *PanicOnExceed) SetLogHook(hook func(uint64))
SetLogHook sets a hook for PanicOnExceed.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker is used to track the memory usage during query execution. It contains an optional limit and can be arranged into a tree structure such that the consumption tracked by a Tracker is also tracked by its ancestors. The main idea comes from Apache Impala:
https://github.com/cloudera/Impala/blob/cdh5-trunk/be/src/runtime/mem-tracker.h
By default, memory consumption is tracked via calls to "Consume()", either to the tracker itself or to one of its descendents. A typical sequence of calls for a single Tracker is: 1. tracker.SetLabel() / tracker.SetActionOnExceed() / tracker.AttachTo() 2. tracker.Consume() / tracker.ReplaceChild() / tracker.BytesConsumed()
NOTE: We only protect concurrent access to "bytesConsumed" and "children", that is to say: 1. Only "BytesConsumed()", "Consume()", "AttachTo()" and "Detach" are thread-safe. 2. Other operations of a Tracker tree is not thread-safe.
func NewTracker ¶
NewTracker creates a memory tracker.
- "label" is the label used in the usage string.
- "bytesLimit < 0" means no limit.
func (*Tracker) AttachTo ¶
AttachTo attaches this memory tracker as a child to another Tracker. If it already has a parent, this function will remove it from the old parent. Its consumed memory usage is used to update all its ancestors.
func (*Tracker) BytesConsumed ¶
BytesConsumed returns the consumed memory usage value in bytes.
func (*Tracker) BytesToString ¶
BytesToString converts the memory consumption to a readable string.
func (*Tracker) Consume ¶
Consume is used to consume a memory usage. "bytes" can be a negative value, which means this is a memory release operation.
func (*Tracker) MaxConsumed ¶
MaxConsumed returns max number of bytes consumed during execution.
func (*Tracker) ReplaceChild ¶
ReplaceChild removes the old child specified in "oldChild" and add a new child specified in "newChild". old child's memory consumption will be removed and new child's memory consumption will be added.
func (*Tracker) SetActionOnExceed ¶
func (t *Tracker) SetActionOnExceed(a ActionOnExceed)
SetActionOnExceed sets the action when memory usage is out of memory quota.