worker

package
v0.4.15 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LabelStep = "step"
	LabelData = "data"
)

Variables

View Source
var (
	UpdateUserRecommendTotal = promauto.NewGauge(prometheus.GaugeOpts{
		Namespace: "gorse",
		Subsystem: "worker",
		Name:      "update_user_recommend_total",
	})
	OfflineRecommendStepSecondsVec = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: "gorse",
		Subsystem: "worker",
		Name:      "offline_recommend_step_seconds",
	}, []string{LabelStep})
	OfflineRecommendTotalSeconds = promauto.NewGauge(prometheus.GaugeOpts{
		Namespace: "gorse",
		Subsystem: "worker",
		Name:      "offline_recommend_total_seconds",
	})
	CollaborativeFilteringIndexRecall = promauto.NewGauge(prometheus.GaugeOpts{
		Namespace: "gorse",
		Subsystem: "worker",
		Name:      "collaborative_filtering_index_recall",
	})
	MemoryInuseBytesVec = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: "gorse",
		Subsystem: "worker",
		Name:      "memory_inuse_bytes",
	}, []string{LabelData})
)

Functions

This section is empty.

Types

type FeedbackCache added in v0.3.0

type FeedbackCache struct {
	*config.Config
	Client    data.Database
	Types     []string
	Cache     cmap.ConcurrentMap
	ByteCount uintptr
}

FeedbackCache is the cache for user feedbacks.

func NewFeedbackCache added in v0.3.0

func NewFeedbackCache(worker *Worker, feedbackTypes ...string) *FeedbackCache

NewFeedbackCache creates a new FeedbackCache.

func (*FeedbackCache) Bytes added in v0.4.3

func (c *FeedbackCache) Bytes() int

func (*FeedbackCache) GetUserFeedback added in v0.3.0

func (c *FeedbackCache) GetUserFeedback(ctx context.Context, userId string) ([]string, error)

GetUserFeedback gets user feedback from cache or database.

type HealthStatus added in v0.4.10

type HealthStatus struct {
	DataStoreError      error
	CacheStoreError     error
	DataStoreConnected  bool
	CacheStoreConnected bool
}

type ItemCache added in v0.3.0

type ItemCache struct {
	Data      map[string]*data.Item
	ByteCount uintptr
}

ItemCache is alias of map[string]data.Item.

func NewItemCache added in v0.4.3

func NewItemCache() *ItemCache

func (*ItemCache) Bytes added in v0.4.3

func (c *ItemCache) Bytes() int

func (*ItemCache) Get added in v0.4.3

func (c *ItemCache) Get(itemId string) (*data.Item, bool)

func (*ItemCache) GetCategory added in v0.4.3

func (c *ItemCache) GetCategory(itemId string) []string

func (*ItemCache) IsAvailable added in v0.3.0

func (c *ItemCache) IsAvailable(itemId string) bool

IsAvailable means the item exists in database and is not hidden.

func (*ItemCache) Len added in v0.4.5

func (c *ItemCache) Len() int

func (*ItemCache) Set added in v0.4.3

func (c *ItemCache) Set(itemId string, item data.Item)

type LocalCache

type LocalCache struct {
	WorkerName string
	// contains filtered or unexported fields
}

LocalCache for the worker node.

func LoadLocalCache

func LoadLocalCache(path string) (*LocalCache, error)

LoadLocalCache loads cache from a local file.

func (*LocalCache) WriteLocalCache

func (c *LocalCache) WriteLocalCache() error

WriteLocalCache writes cache to a local file.

type ScheduleState added in v0.4.9

type ScheduleState struct {
	IsRunning bool      `json:"is_running"`
	StartTime time.Time `json:"start_time"`
}

type Worker

type Worker struct {
	*config.Settings
	// contains filtered or unexported fields
}

Worker manages states of a worker node.

func NewWorker

func NewWorker(masterHost string, masterPort int, httpHost string, httpPort, jobs int, cacheFile string, managedMode bool) *Worker

NewWorker creates a new worker node.

func (*Worker) Pull

func (w *Worker) Pull()

Pull user index and ranking model from master.

func (*Worker) Recommend

func (w *Worker) Recommend(users []data.User)

Recommend items to users. The workflow of recommendation is: 1. Skip inactive users. 2. Load historical items. 3. Load positive items if KNN used. 4. Generate recommendation. 5. Save result. 6. Insert cold-start items into results. 7. Rank items in results by click-through-rate. 8. Refresh cache.

func (*Worker) ScheduleAPIHandler added in v0.4.9

func (w *Worker) ScheduleAPIHandler(writer http.ResponseWriter, request *http.Request)

func (*Worker) Serve

func (w *Worker) Serve()

Serve as a worker node.

func (*Worker) ServeHTTP added in v0.4.9

func (w *Worker) ServeHTTP()

ServeHTTP serves Prometheus metrics and API.

func (*Worker) SetOneMode added in v0.4.4

func (w *Worker) SetOneMode(settings *config.Settings)

func (*Worker) Sync

func (w *Worker) Sync()

Sync this worker to the master.

Jump to

Keyboard shortcuts

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