mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 11:36:56 +08:00
fix: failed to evenly distribute the spawn-rate to each worker
This commit is contained in:
@@ -1158,24 +1158,35 @@ func (r *masterRunner) start() error {
|
|||||||
log.Error().Err(err).Msg("copy workerProfile failed")
|
log.Error().Err(err).Msg("copy workerProfile failed")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
cur := 0
|
|
||||||
ints := builtin.SplitInteger(int(r.profile.SpawnCount), numWorkers)
|
// spawn count
|
||||||
log.Info().Msg("send spawn data to worker")
|
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)
|
r.updateState(StateSpawning)
|
||||||
|
log.Info().Msg("send spawn data to worker")
|
||||||
|
|
||||||
|
cur := 0
|
||||||
r.server.clients.Range(func(key, value interface{}) bool {
|
r.server.clients.Range(func(key, value interface{}) bool {
|
||||||
if workerInfo, ok := value.(*WorkerNode); ok {
|
if workerInfo, ok := value.(*WorkerNode); ok {
|
||||||
if workerInfo.getState() == StateQuitting || workerInfo.getState() == StateMissing {
|
if workerInfo.getState() == StateQuitting || workerInfo.getState() == StateMissing {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if workerProfile.SpawnCount > 0 {
|
if workerProfile.SpawnCount > 0 {
|
||||||
workerProfile.SpawnCount = int64(ints[cur])
|
workerProfile.SpawnCount = int64(spawnCounts[cur])
|
||||||
}
|
|
||||||
if workerProfile.SpawnRate > 0 {
|
|
||||||
workerProfile.SpawnRate = workerProfile.SpawnRate / float64(numWorkers)
|
|
||||||
}
|
|
||||||
if workerProfile.MaxRPS > 0 {
|
|
||||||
workerProfile.MaxRPS = workerProfile.MaxRPS / int64(numWorkers)
|
|
||||||
}
|
}
|
||||||
|
workerProfile.MaxRPS = int64(maxRPSs[cur])
|
||||||
|
workerProfile.SpawnRate = spawnRate
|
||||||
|
|
||||||
workerInfo.getStream() <- &messager.StreamResponse{
|
workerInfo.getStream() <- &messager.StreamResponse{
|
||||||
Type: "spawn",
|
Type: "spawn",
|
||||||
Profile: ProfileToBytes(workerProfile),
|
Profile: ProfileToBytes(workerProfile),
|
||||||
|
|||||||
@@ -406,6 +406,7 @@ func (s *grpcServer) close() {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
s.stopServer(ctx)
|
s.stopServer(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
|
close(s.disconnectedChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *grpcServer) recvChannel() chan *genericMessage {
|
func (s *grpcServer) recvChannel() chan *genericMessage {
|
||||||
|
|||||||
Reference in New Issue
Block a user