worker

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2022 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GenerateRecommendSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
		Namespace: "gorse",
		Subsystem: "worker",
		Name:      "get_recommend_seconds",
	})
	CTRRecommendSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
		Namespace: "gorse",
		Subsystem: "worker",
		Name:      "ctr_recommend_seconds",
	})
	CollaborativeRecommendSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
		Namespace: "gorse",
		Subsystem: "worker",
		Name:      "collaborative_recommend_seconds",
	})
	ItemBasedRecommendSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
		Namespace: "gorse",
		Subsystem: "worker",
		Name:      "item_based_recommend_seconds",
	})
	UserBasedRecommendSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
		Namespace: "gorse",
		Subsystem: "worker",
		Name:      "user_based_recommend_seconds",
	})
	LoadLatestRecommendCacheSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
		Namespace: "gorse",
		Subsystem: "worker",
		Name:      "load_latest_recommend_cache_seconds",
	})
	LoadPopularRecommendCacheSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
		Namespace: "gorse",
		Subsystem: "worker",
		Name:      "load_popular_recommend_cache_seconds",
	})

	MatchingIndexRecall = promauto.NewGauge(prometheus.GaugeOpts{
		Namespace: "gorse",
		Subsystem: "worker",
		Name:      "matching_index_recall",
	})
)

Functions

This section is empty.

Types

type FeedbackCache added in v0.3.0

type FeedbackCache struct {
	Types  []string
	Cache  cmap.ConcurrentMap
	Client data.Database
}

FeedbackCache is the cache for user feedbacks.

func NewFeedbackCache added in v0.3.0

func NewFeedbackCache(client data.Database, feedbackTypes ...string) *FeedbackCache

NewFeedbackCache creates a new FeedbackCache.

func (*FeedbackCache) GetUserFeedback added in v0.3.0

func (c *FeedbackCache) GetUserFeedback(userId string) ([]string, error)

GetUserFeedback gets user feedback from cache or database.

type ItemCache added in v0.3.0

type ItemCache map[string]data.Item

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

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.

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 Worker

type Worker struct {
	// 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) *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) Serve

func (w *Worker) Serve()

Serve as a worker node.

func (*Worker) ServeMetrics

func (w *Worker) ServeMetrics()

ServeMetrics serves Prometheus metrics.

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