From c128865c4c7411c29a59fca9a3a2f95537686d7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= Date: Mon, 20 Jan 2020 18:41:05 +0000 Subject: Move commands to cmd/ and move internal dependencies to internal/ --- server/stats.go | 88 --------------------------------------------------------- 1 file changed, 88 deletions(-) delete mode 100644 server/stats.go (limited to 'server/stats.go') diff --git a/server/stats.go b/server/stats.go deleted file mode 100644 index 01aa121..0000000 --- a/server/stats.go +++ /dev/null @@ -1,88 +0,0 @@ -package server - -import ( - "dtail/config" - "dtail/logger" - "fmt" - "runtime" - "sync" - "time" -) - -// Used to collect and display various server stats. -type stats struct { - mutex sync.Mutex - currentConnections int - lifetimeConnections uint64 -} - -func (s *stats) incrementConnections() { - defer s.logServerStats() - - s.mutex.Lock() - s.currentConnections++ - s.lifetimeConnections++ - s.mutex.Unlock() -} - -func (s *stats) decrementConnections() { - defer s.logServerStats() - - s.mutex.Lock() - s.currentConnections-- - s.mutex.Unlock() -} - -func (s *stats) hasConnections() bool { - s.mutex.Lock() - currentConnections := s.currentConnections - s.mutex.Unlock() - - has := currentConnections > 0 - logger.Info("stats", "Server with open connections?", has, currentConnections) - - return has -} - -func (s *stats) logServerStats() { - s.mutex.Lock() - defer s.mutex.Unlock() - - currentConnections := fmt.Sprintf("currentConnections=%d", s.currentConnections) - lifetimeConnections := fmt.Sprintf("lifetimeConnections=%d", s.lifetimeConnections) - goroutines := fmt.Sprintf("goroutines=%d", runtime.NumGoroutine()) - logger.Info("stats", currentConnections, lifetimeConnections, goroutines) -} - -func (s *stats) serverLimitExceeded() error { - s.mutex.Lock() - defer s.mutex.Unlock() - - if s.currentConnections >= config.Server.MaxConnections { - return fmt.Errorf("Exceeded max allowed concurrent connections of %d", config.Server.MaxConnections) - } - - return nil -} - -func (s *stats) periodicLogServerStats(stop <-chan struct{}) { - for { - select { - case <-time.NewTimer(time.Second * 10).C: - s.logServerStats() - case <-stop: - return - } - } -} - -func (s *stats) waitForConnections() { - for { - select { - case <-time.NewTimer(time.Second).C: - if !s.hasConnections() { - return - } - } - } -} -- cgit v1.2.3