TimeOut key — how long should a job really stay alive?
I'm building a daemon that uses a launchd-provided socket, it seems like a good idea to exit when nothing's connected. I've read that jobs must stay alive for 60 seconds, but launchd is giving me a 30 second timeout at checkin. What's right? How are daemon timeouts supposed to work?
On Aug 7, 2009, at 11:01 AM, Sidney San Martín wrote:
I'm building a daemon that uses a launchd-provided socket, it seems like a good idea to exit when nothing's connected.
I've read that jobs must stay alive for 60 seconds, but launchd is giving me a 30 second timeout at checkin. What's right? How are daemon timeouts supposed to work?
I'm not sure where you read that, but it sounds like someone, somewhere, is misunderstanding something. launchd gives each job a default ThrottleInterval of 10 seconds. This means that, if your job comes alive and then exits two seconds later and then immediately needs to be respawned, launchd will schedule your job to be run 8 seconds from that point. Thus, your job's start times must be at least 10 seconds apart by default, which establishes an effective minimum run time. You can override this with the ThrottleInterval key if you'd like. So if you have an idle exit timeout of 30 seconds, you'll be fine. -- Damien Sorresso BSD Engineering Apple Inc.
Thanks, Damien, that makes sense. I don't remember where I originally heard "60 seconds", but searching the web for "living at least 60 seconds" brings up plenty of log entries from launchd. Where's this figure coming from (i.e. are there certain cases where your job must stay alive for that long)? On Fri, Aug 7, 2009 at 2:12 PM, Damien Sorresso<dsorresso@apple.com> wrote:
On Aug 7, 2009, at 11:01 AM, Sidney San Martín wrote:
I'm building a daemon that uses a launchd-provided socket, it seems like a good idea to exit when nothing's connected.
I've read that jobs must stay alive for 60 seconds, but launchd is giving me a 30 second timeout at checkin. What's right? How are daemon timeouts supposed to work?
I'm not sure where you read that, but it sounds like someone, somewhere, is misunderstanding something. launchd gives each job a default ThrottleInterval of 10 seconds. This means that, if your job comes alive and then exits two seconds later and then immediately needs to be respawned, launchd will schedule your job to be run 8 seconds from that point. Thus, your job's start times must be at least 10 seconds apart by default, which establishes an effective minimum run time.
You can override this with the ThrottleInterval key if you'd like.
So if you have an idle exit timeout of 30 seconds, you'll be fine. -- Damien Sorresso BSD Engineering Apple Inc.
On Aug 7, 2009, at 12:33 PM, Sidney San Martín wrote:
Thanks, Damien, that makes sense.
I don't remember where I originally heard "60 seconds", but searching the web for "living at least 60 seconds" brings up plenty of log entries from launchd. Where's this figure coming from (i.e. are there certain cases where your job must stay alive for that long)?
No idea. It's possible that this was the ThrottleInterval in Tiger and was changed in Leopard. I only came into the project during the SnowLeopard timeframe. -- Damien Sorresso BSD Engineering Apple Inc.
participants (2)
-
Damien Sorresso
-
Sidney San Martín