Documentation
¶
Index ¶
- type Allocator
- type FixedSizeAllocator
- func (a *FixedSizeAllocator[T]) Allocate(id T, r *Resource) (allocated bool, short *Resource)
- func (a *FixedSizeAllocator[T]) Inspect() map[T]*Resource
- func (a *FixedSizeAllocator[T]) Reallocate(id T, delta *Resource) (allocated bool, short *Resource)
- func (a *FixedSizeAllocator[T]) Release(id T) *Resource
- func (a *FixedSizeAllocator[T]) Used() Resource
- func (a *FixedSizeAllocator[T]) Wait()
- type GroupedAllocator
- func (ga *GroupedAllocator) Allocate(id string, r *Resource) (allocated bool, short *Resource)
- func (ga *GroupedAllocator) GetAllocator(name string) Allocator[string]
- func (ga *GroupedAllocator) Reallocate(id string, delta *Resource) (allocated bool, short *Resource)
- func (ga *GroupedAllocator) Release(id string) *Resource
- type GroupedAllocatorBuilder
- type PhysicalAwareFixedSizeAllocator
- type Resource
- type SharedAllocator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Allocator ¶
type Allocator[T comparable] interface { // Allocate allocates the resource, returns true if the resource is allocated. If allocation failed, returns the short resource. // The short resource is a positive value, e.g., if there is additional 8 bytes in disk needed, returns (0, 0, 8). // Allocate on identical id is not allowed, in which case it returns (false, nil). Use #Reallocate instead. Allocate(id T, r *Resource) (allocated bool, short *Resource) // Reallocate re-allocates the resource on given id with delta resource. Delta can be negative, in which case the resource is released. // If delta is negative and the allocated resource is less than the delta, returns (false, nil). Reallocate(id T, delta *Resource) (allocated bool, short *Resource) // Release releases the resource Release(id T) *Resource // Used returns the used resource Used() Resource // Wait waits for new release. Releases could be initiated by #Release or #Reallocate. Wait() // Inspect returns the allocated resources Inspect() map[T]*Resource // contains filtered or unexported methods }
type FixedSizeAllocator ¶
type FixedSizeAllocator[T comparable] struct { // contains filtered or unexported fields }
func NewFixedSizeAllocator ¶
func NewFixedSizeAllocator[T comparable](limit *Resource) *FixedSizeAllocator[T]
func (*FixedSizeAllocator[T]) Allocate ¶
func (a *FixedSizeAllocator[T]) Allocate(id T, r *Resource) (allocated bool, short *Resource)
func (*FixedSizeAllocator[T]) Inspect ¶
func (a *FixedSizeAllocator[T]) Inspect() map[T]*Resource
func (*FixedSizeAllocator[T]) Reallocate ¶
func (a *FixedSizeAllocator[T]) Reallocate(id T, delta *Resource) (allocated bool, short *Resource)
func (*FixedSizeAllocator[T]) Release ¶
func (a *FixedSizeAllocator[T]) Release(id T) *Resource
func (*FixedSizeAllocator[T]) Used ¶
func (a *FixedSizeAllocator[T]) Used() Resource
func (*FixedSizeAllocator[T]) Wait ¶
func (a *FixedSizeAllocator[T]) Wait()
type GroupedAllocator ¶
type GroupedAllocator struct {
// contains filtered or unexported fields
}
GroupedAllocator is a shared allocator that can be grouped with other shared allocators. The sum of used resources of all children should not exceed the limit.
func (*GroupedAllocator) Allocate ¶
func (ga *GroupedAllocator) Allocate(id string, r *Resource) (allocated bool, short *Resource)
Allocate allocates the resource, returns true if the resource is allocated. If allocation failed, returns the short resource. The short resource is a positive value, e.g., if there is additional 8 bytes in disk needed, returns (0, 0, 8). Allocate on identical id is not allowed, in which case it returns (false, nil). Use #Reallocate instead.
func (*GroupedAllocator) GetAllocator ¶
func (ga *GroupedAllocator) GetAllocator(name string) Allocator[string]
func (*GroupedAllocator) Reallocate ¶
func (ga *GroupedAllocator) Reallocate(id string, delta *Resource) (allocated bool, short *Resource)
func (*GroupedAllocator) Release ¶
func (ga *GroupedAllocator) Release(id string) *Resource
Release releases the resource
type GroupedAllocatorBuilder ¶
type GroupedAllocatorBuilder struct {
// contains filtered or unexported fields
}
func NewGroupedAllocatorBuilder ¶
func NewGroupedAllocatorBuilder(name string, limit *Resource) *GroupedAllocatorBuilder
func (*GroupedAllocatorBuilder) AddChild ¶
func (b *GroupedAllocatorBuilder) AddChild(name string, limit *Resource) *GroupedAllocatorBuilder
func (*GroupedAllocatorBuilder) AddChildGroup ¶
func (b *GroupedAllocatorBuilder) AddChildGroup(allocator *GroupedAllocator) *GroupedAllocatorBuilder
func (*GroupedAllocatorBuilder) Build ¶
func (b *GroupedAllocatorBuilder) Build() *GroupedAllocator
type PhysicalAwareFixedSizeAllocator ¶
type PhysicalAwareFixedSizeAllocator[T comparable] struct { FixedSizeAllocator[T] // contains filtered or unexported fields }
PhysicalAwareFixedSizeAllocator allocates resources with additional consideration of physical resource usage. Note: wait on PhysicalAwareFixedSizeAllocator may only be notified if there is virtual resource released.
func NewPhysicalAwareFixedSizeAllocator ¶
func NewPhysicalAwareFixedSizeAllocator[T comparable](limit *Resource, hwMemoryLimit, hwDiskLimit int64, dir string) *PhysicalAwareFixedSizeAllocator[T]
func (*PhysicalAwareFixedSizeAllocator[T]) Allocate ¶
func (a *PhysicalAwareFixedSizeAllocator[T]) Allocate(id T, r *Resource) (allocated bool, short *Resource)
func (*PhysicalAwareFixedSizeAllocator[T]) Reallocate ¶
func (a *PhysicalAwareFixedSizeAllocator[T]) Reallocate(id T, delta *Resource) (allocated bool, short *Resource)
type Resource ¶
type Resource struct {
Memory int64 // Memory occupation in bytes
CPU int64 // CPU in cycles per second
Disk int64 // Disk occpuation in bytes
}
type SharedAllocator ¶
func (*SharedAllocator) Allocate ¶
func (sa *SharedAllocator) Allocate(id string, r *Resource) (allocated bool, short *Resource)
Allocate allocates the resource, returns true if the resource is allocated. If allocation failed, returns the short resource. The short resource is a positive value, e.g., if there is additional 8 bytes in disk needed, returns (0, 0, 8).
func (*SharedAllocator) Reallocate ¶
func (sa *SharedAllocator) Reallocate(id string, delta *Resource) (allocated bool, short *Resource)
Reallocate re-allocates the resource on given id with delta resource. Delta can be negative, in which case the resource is released. If delta is negative and the allocated resource is less than the delta, returns (false, nil).
func (*SharedAllocator) Release ¶
func (sa *SharedAllocator) Release(id string) *Resource
Release releases the resource