instance

package
v0.0.131 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextCanceledError

type ContextCanceledError struct {
	Message string
}

func (ContextCanceledError) Error

func (e ContextCanceledError) Error() string

type CoreInstanceHolder

type CoreInstanceHolder struct {
	Instance   interface{}
	Name       string
	CoreID     int64
	ModelPaths []string
	BatchSize  int64
	Thread
}

CoreInstanceHolder is a instance which is used by core (gpu or cpu or npu).

type DeleteFunc

type DeleteFunc func(instance interface{})

type EmptyPoolOption

type EmptyPoolOption struct{}

EmptyPoolUrlOption does not alter the Pooluration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type GlobalInitFunc

type GlobalInitFunc func() error

type GlobalReleaseFunc

type GlobalReleaseFunc func() error

type LoadBalanceMode

type LoadBalanceMode int
const (
	RoundRobinBalanceMode LoadBalanceMode = 0
	RandomLoadBalanceMode LoadBalanceMode = 1
	LeastLoadBalanceMode  LoadBalanceMode = 2
)

type LocalInitFunc

type LocalInitFunc func(instance interface{}) error

type LocalReleaseFunc

type LocalReleaseFunc func(instance interface{}) error

type NewFunc

type NewFunc func() interface{}

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool(newFunc NewFunc, opts ...PoolOption) (*Pool, error)

func (*Pool) ApplyOptions

func (o *Pool) ApplyOptions(options ...PoolOption) *Pool

func (*Pool) Get

func (p *Pool) Get(ctx context.Context) (*CoreInstanceHolder, error)

func (*Pool) GetByCoreId

func (p *Pool) GetByCoreId(ctx context.Context, coreID int64) (*CoreInstanceHolder, error)

func (*Pool) GetWithRoundRobinMode

func (p *Pool) GetWithRoundRobinMode(ctx context.Context) (*CoreInstanceHolder, error)

until get instance, unless context canceled

func (*Pool) GlobalInit

func (p *Pool) GlobalInit(ctx context.Context) error

func (*Pool) GlobalRelease

func (p *Pool) GlobalRelease(ctx context.Context) error

func (*Pool) Invoke

func (p *Pool) Invoke(
	ctx context.Context,
	f func(ctx context.Context, instance interface{}) (interface{}, error),
) (response interface{}, err error)

func (*Pool) Put

func (p *Pool) Put(ctx context.Context, holder *CoreInstanceHolder) error

type PoolOption

type PoolOption interface {
	// contains filtered or unexported methods
}

A PoolOption sets options.

func WithBatchSize

func WithBatchSize(batchSize int64) PoolOption

func WithCapacityPoolSizePerCore

func WithCapacityPoolSizePerCore(capacityPoolSizePerCore int64) PoolOption

func WithCoreIDs

func WithCoreIDs(coreIDs []int64) PoolOption

func WithDeleteFunc

func WithDeleteFunc(f DeleteFunc) PoolOption

func WithEnabledPrintCostTime

func WithEnabledPrintCostTime(enabled bool) PoolOption

func WithGlobalInitFunc

func WithGlobalInitFunc(f GlobalInitFunc) PoolOption

func WithGlobalReleaseFunc

func WithGlobalReleaseFunc(f GlobalReleaseFunc) PoolOption

func WithLoadBalanceMode

func WithLoadBalanceMode(loadBalanceMode LoadBalanceMode) PoolOption

func WithLocalInitFunc

func WithLocalInitFunc(f LocalInitFunc) PoolOption

func WithLocalReleaseFunc

func WithLocalReleaseFunc(f LocalReleaseFunc) PoolOption

func WithModelPaths

func WithModelPaths(modelPaths []string) PoolOption

func WithName

func WithName(name string) PoolOption

func WithResevePoolSizePerCore

func WithResevePoolSizePerCore(resevePoolSizePerCore int64) PoolOption

func WithWaitTimeoutOnce

func WithWaitTimeoutOnce(waitTimeout time.Duration) PoolOption

func WithWaitTimeoutTotal

func WithWaitTimeoutTotal(waitTimeout time.Duration) PoolOption

type PoolOptionFunc

type PoolOptionFunc func(*Pool)

PoolOptionFunc wraps a function that modifies Pool into an implementation of the PoolOption interface.

type PoolOptions

type PoolOptions struct {
	// contains filtered or unexported fields
}

type Thread

type Thread struct {
	// contains filtered or unexported fields
}

func NewThread

func NewThread(enableOsThread bool) *Thread

func (*Thread) Do

func (t *Thread) Do(ctx context.Context, f func()) error

func (*Thread) DoInOSThread

func (t *Thread) DoInOSThread()

type TimeoutError

type TimeoutError struct {
	Message string
}

func (TimeoutError) Error

func (e TimeoutError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL