fix: failed to evenly distribute the spawn-rate to each worker

This commit is contained in:
徐聪
2022-07-14 14:26:55 +08:00
parent 461366c28a
commit 683c0e5374
2 changed files with 22 additions and 10 deletions

View File

@@ -1158,24 +1158,35 @@ func (r *masterRunner) start() error {
log.Error().Err(err).Msg("copy workerProfile failed")
return err
}
cur := 0
ints := builtin.SplitInteger(int(r.profile.SpawnCount), numWorkers)
log.Info().Msg("send spawn data to worker")
// spawn count
spawnCounts := builtin.SplitInteger(int(r.profile.SpawnCount), numWorkers)
// spawn rate
spawnRate := workerProfile.SpawnRate / float64(numWorkers)
if spawnRate < 1 {
spawnRate = 1
}
// max RPS
maxRPSs := builtin.SplitInteger(int(workerProfile.MaxRPS), numWorkers)
r.updateState(StateSpawning)
log.Info().Msg("send spawn data to worker")
cur := 0
r.server.clients.Range(func(key, value interface{}) bool {
if workerInfo, ok := value.(*WorkerNode); ok {
if workerInfo.getState() == StateQuitting || workerInfo.getState() == StateMissing {
return true
}
if workerProfile.SpawnCount > 0 {
workerProfile.SpawnCount = int64(ints[cur])
}
if workerProfile.SpawnRate > 0 {
workerProfile.SpawnRate = workerProfile.SpawnRate / float64(numWorkers)
}
if workerProfile.MaxRPS > 0 {
workerProfile.MaxRPS = workerProfile.MaxRPS / int64(numWorkers)
workerProfile.SpawnCount = int64(spawnCounts[cur])
}
workerProfile.MaxRPS = int64(maxRPSs[cur])
workerProfile.SpawnRate = spawnRate
workerInfo.getStream() <- &messager.StreamResponse{
Type: "spawn",
Profile: ProfileToBytes(workerProfile),

View File

@@ -406,6 +406,7 @@ func (s *grpcServer) close() {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
s.stopServer(ctx)
cancel()
close(s.disconnectedChan)
}
func (s *grpcServer) recvChannel() chan *genericMessage {