balancer.h 949 B

123456789101112131415161718192021222324252627
  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. };
  12. // Pool cpu balancer
  13. struct IBalancer {
  14. virtual ~IBalancer() {}
  15. virtual bool AddCpu(const TCpuAllocation& cpuAlloc, TCpuState* cpu) = 0;
  16. virtual bool TryLock(ui64 ts) = 0;
  17. virtual void SetPoolStats(TPoolId pool, const TBalancerStats& stats) = 0;
  18. virtual void Balance() = 0;
  19. virtual void Unlock() = 0;
  20. // TODO: add method for reconfiguration on fly
  21. };
  22. IBalancer* MakeBalancer(const TBalancerConfig& config, const TVector<TUnitedExecutorPoolConfig>& unitedPools, ui64 ts);
  23. }