balancer.h 1.0 KB

123456789101112131415161718192021222324252627282930
  1. #pragma once
  2. #include "defs.h"
  3. #include "config.h"
  4. #include "cpu_state.h"
  5. namespace NActors {
  6. // Per-pool statistics used by balancer
  7. struct TBalancerStats {
  8. ui64 Ts = 0; // Measurement timestamp
  9. ui64 CpuUs = 0; // Total cpu microseconds consumed by pool on all cpus since start
  10. ui64 IdleUs = ui64(-1); // Total cpu microseconds in spinning or waiting on futex
  11. ui64 WorstActivationTimeUs = 0;
  12. ui64 ExpectedLatencyIncreaseUs = 0;
  13. };
  14. // Pool cpu balancer
  15. struct IBalancer {
  16. virtual ~IBalancer() {}
  17. virtual bool AddCpu(const TCpuAllocation& cpuAlloc, TCpuState* cpu) = 0;
  18. virtual bool TryLock(ui64 ts) = 0;
  19. virtual void SetPoolStats(TPoolId pool, const TBalancerStats& stats) = 0;
  20. virtual void Balance() = 0;
  21. virtual void Unlock() = 0;
  22. virtual ui64 GetPeriodUs() = 0;
  23. // TODO: add method for reconfiguration on fly
  24. };
  25. IBalancer* MakeBalancer(const TBalancerConfig& config, const TVector<TUnitedExecutorPoolConfig>& unitedPools, ui64 ts);
  26. }