Commit 49694be0 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Matchmaker stats capture improvements.

parent 7f4afe35
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -154,7 +154,7 @@ func main() {
	if err != nil {
		startupLogger.Fatal("Failed initializing runtime modules", zap.Error(err))
	}
	matchmaker := server.NewLocalMatchmaker(logger, startupLogger, config, router, runtime)
	matchmaker := server.NewLocalMatchmaker(logger, startupLogger, config, router, metrics, runtime)
	partyRegistry := server.NewLocalPartyRegistry(logger, matchmaker, tracker, streamManager, router, config.GetName())
	tracker.SetPartyJoinListener(partyRegistry.Join)
	tracker.SetPartyLeaveListener(partyRegistry.Leave)
+1 −0
Original line number Diff line number Diff line
@@ -181,6 +181,7 @@ func (s *testMetrics) CountWebsocketOpened(delta int64)
func (s *testMetrics) CountWebsocketClosed(delta int64)                                     {}
func (s *testMetrics) GaugeSessions(value float64)                                          {}
func (s *testMetrics) GaugePresences(value float64)                                         {}
func (s *testMetrics) Matchmaker(tickets, activeTickets float64, processTime time.Duration) {}
func (s *testMetrics) PresenceEvent(dequeueElapsed, processElapsed time.Duration)           {}
func (s *testMetrics) CustomCounter(name string, tags map[string]string, delta int64)       {}
func (s *testMetrics) CustomGauge(name string, tags map[string]string, value float64)       {}
+13 −2
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ type LocalMatchmaker struct {
	node    string
	config  Config
	router  MessageRouter
	metrics Metrics
	runtime *Runtime

	active      *atomic.Uint32
@@ -207,7 +208,7 @@ type LocalMatchmaker struct {
	revCache         map[string]map[string]bool
}

func NewLocalMatchmaker(logger, startupLogger *zap.Logger, config Config, router MessageRouter, runtime *Runtime) Matchmaker {
func NewLocalMatchmaker(logger, startupLogger *zap.Logger, config Config, router MessageRouter, metrics Metrics, runtime *Runtime) Matchmaker {
	cfg := BlugeInMemoryConfig()
	indexWriter, err := bluge.OpenWriter(cfg)
	if err != nil {
@@ -221,6 +222,7 @@ func NewLocalMatchmaker(logger, startupLogger *zap.Logger, config Config, router
		node:    config.GetName(),
		config:  config,
		router:  router,
		metrics: metrics,
		runtime: runtime,

		active:      atomic.NewUint32(1),
@@ -273,10 +275,19 @@ func (m *LocalMatchmaker) OnMatchedEntries(fn func(entries [][]*MatchmakerEntry)
func (m *LocalMatchmaker) Process() {
	matchedEntries := make([][]*MatchmakerEntry, 0, 5)

	startTime := time.Now()

	m.Lock()

	activeIndexCount := len(m.activeIndexes)
	indexCount := len(m.indexes)

	defer func() {
		m.metrics.Matchmaker(float64(indexCount), float64(activeIndexCount), time.Now().Sub(startTime))
	}()

	// No active matchmaking tickets, the pool may be non-empty but there are no new tickets to check/query with.
	if len(m.activeIndexes) == 0 {
	if activeIndexCount == 0 {
		m.Unlock()
		return
	}
+3 −2
Original line number Diff line number Diff line
@@ -1662,7 +1662,7 @@ func createTestMatchmaker(t fatalable, logger *zap.Logger, tickerActive bool, me
		return res, true, nil
	}

	matchMaker := NewLocalBenchMatchmaker(logger, logger, cfg, messageRouter, runtime, tickerActive)
	matchMaker := NewLocalBenchMatchmaker(logger, logger, cfg, messageRouter, metrics, runtime, tickerActive)

	return matchMaker.(*LocalMatchmaker), func() error {
		matchMaker.Stop()
@@ -1672,7 +1672,7 @@ func createTestMatchmaker(t fatalable, logger *zap.Logger, tickerActive bool, me
}

// Create a new matchmaker with an additional argument to make the ticker optional
func NewLocalBenchMatchmaker(logger, startupLogger *zap.Logger, config Config, router MessageRouter, runtime *Runtime, tickerActive bool) Matchmaker {
func NewLocalBenchMatchmaker(logger, startupLogger *zap.Logger, config Config, router MessageRouter, metrics Metrics, runtime *Runtime, tickerActive bool) Matchmaker {
	cfg := BlugeInMemoryConfig()
	indexWriter, err := bluge.OpenWriter(cfg)
	if err != nil {
@@ -1686,6 +1686,7 @@ func NewLocalBenchMatchmaker(logger, startupLogger *zap.Logger, config Config, r
		node:    config.GetName(),
		config:  config,
		router:  router,
		metrics: metrics,
		runtime: runtime,

		active:      atomic.NewUint32(1),
+9 −0
Original line number Diff line number Diff line
@@ -56,6 +56,8 @@ type Metrics interface {
	GaugeSessions(value float64)
	GaugePresences(value float64)

	Matchmaker(tickets, activeTickets float64, processTime time.Duration)

	PresenceEvent(dequeueElapsed, processElapsed time.Duration)

	CustomCounter(name string, tags map[string]string, delta int64)
@@ -413,6 +415,13 @@ func (m *LocalMetrics) GaugePresences(value float64) {
	m.PrometheusScope.Gauge("presences").Update(value)
}

// Record a set of matchmaker metrics.
func (m *LocalMetrics) Matchmaker(tickets, activeTickets float64, processTime time.Duration) {
	m.PrometheusScope.Gauge("matchmaker_tickets").Update(tickets)
	m.PrometheusScope.Gauge("matchmaker_active_tickets").Update(activeTickets)
	m.PrometheusScope.Timer("matchmaker_process_time").Record(processTime)
}

// Count presence events and time their processing.
func (m *LocalMetrics) PresenceEvent(dequeueElapsed, processElapsed time.Duration) {
	m.PrometheusScope.Counter("presence_event_count").Inc(1)