How to limit the number of instances UpStart can simultaneously start or respawn
Asked Answered
K

2

8

I have a UpStart service job that has many (~100) instance that need to be started. Each of them is a resource-heavy process that does a lot of disk reading/writing during startup. When all of them start or respawn at the same time, they cause trouble due to excessive disk read/write requests.

I need a way to limit the number of instances that UpStart tries to start or respawn simultaneously. For example, is there a way to let UpStart hold off launching another instance until, say 30 seconds, after the startup or respawning of another instance has begun?

Kress answered 13/5, 2015 at 20:36 Comment(3)
If your job is a shell script, you could insert either a random pause, so that when 10 start at the same time they each pause a different number of seconds and space themselves out -- or you could have all jobs lock a certain file when doing the intensive startup. But that is a shell scripting solution that has nothing to do with upstart.Thurston
can you show a upstart script? are they al somewhat the same?Lively
I think the lock method mentioned by @Thurston is cool. But that'll require changes to the app code itself (btw, it is not a shell script. It is a full compiled application). It is surprising that UpStart doesn't have some builtin functionality to automatically hold and queue service instances (?).Kress
L
5

You can start them in sequence by using

start on started otherUpstartService
Lively answered 16/5, 2015 at 7:18 Comment(1)
When is a service considered "started" by UpStart? As soon as the process is launched? If it is too soon, it might not help with spreading the load out in time. If it is too late, there may be too much delay.Kress
D
1

You can use pre-start or post-stop to pause after each job. E.g post-stop exec sleep 5

Deckle answered 21/5, 2015 at 8:50 Comment(2)
If they all sleep for the same amount of time at start up, then the issue is still there. Is there a way to make the sleep time random?Kress
You could do something like post-stop exec sleep $(( ( RANDOM % 10 ) + 1 )) to get sleeps between 1 and 10 seconds. Just change the 10 to any other integer to get a wider rangeDeckle

© 2022 - 2024 — McMap. All rights reserved.