Linux application level timers?
I'm writing an application server which receives requests from other applications. For each request received, I want to start a timer so that I can fail the application request if it could not be completed in max specified time.
Which Linux timer facility can be used for this?
I have checked out alarm() and signal() system calls, but these calls doesn't take an argument, so its not possible to associate application request with the matured alarm.
Any inputs?
Thanks in advance,
Tom
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
Try select().
Depending on your architecture (ie: if requests come in via TCP file descriptors) you can use select. Select takes as an argument a timeout value. You can calculate the minimum timeout value for a set of timeouts by finding the minimum, and use that as your select timeout. Before each time you call select, you can figure out all the timeout values to find the minimum select period. This way you can control what you do when with the timeout. After the select, you can then calculate which timeouts have occured and act on them appropriately.
I use this for example to detect when a function should be polled while also waiting on event-driven i/o from a tcp socket. I also use this to detect when a heartbeat message should have been received but was not in the alloted time, causing the socket to close and reconnect.
Thanks
-steve
Quoted 32 lines · Tom Sanders
I'm writing an application server which receives requests from other applications. For each request received, I want to start a timer so that I can fail the application request if it could not be completed in max specified time.
Which Linux timer facility can be used for this?
I have checked out
alarm()andsignal()system calls, but these calls doesn't take an argument, so its not possible to associate application request with the matured alarm.Any inputs?
Thanks in advance,
Tom__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 7 lines · Tom Sanders
I'm writing an application server which receives requests from other applications. For each request received, I want to start a timer so that I can fail the application request if it could not be completed in max specified time.
Quoted 6 lines
Which Linux timer facility can be used for this?
I have checked out
alarm()andsignal()system calls, but these calls doesn't take an argument, so its not possible to associate application request with the matured alarm.
Sounds like a job for POSIX clocks & timers. See here:
http://sourceforge.net/projects/high-res-timers/
-g
Quoted 15 lines
Any inputs?
Thanks in advance,
Tom__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 5 lines
George Anzinger [email protected] High-res-timers: http://sourceforge.net/projects/high-res-timers/ Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
Quoted 6 lines · Tom Sanders
I'm writing an application server which receives requests from other applications. For each request received, I want to start a timer so that I can fail the application request if it could not be completed in max specified time.
Quoted 8 lines
Which Linux timer facility can be used for this?
I have checked out
alarm()andsignal()system calls, but these calls doesn't take an argument, so its not possible to associate application request with the matured alarm.Any inputs?
Write a timer funtion internal to your application that checks an internal list of deadlines and when it gets the signal just check the internal list to see what timer has gone off and set alarm() to the next item.
If you want example code write me off list.
Gerhard
--
Gerhard Mack
<>< As a computer I find your faith in technology amusing.
You can also use the poll() system call. The last arguement of this system call is the timeout value is milli-seconds. When timeout is occurred it will return 0. Refer the manual page for more details.
hope this helps you,
Signature · 6 lines
Narsimha Reddy CH Storage Area Networking, HCL Technologies Contact +91-044 2372 8366 ext 1128 http://san.hcltech.com http://www.hcltech.com
Quoted 28 lines · Tom Sanders
I'm writing an application server which receives requests from other applications. For each request received, I want to start a timer so that I can fail the application request if it could not be completed in max specified time.
Which Linux timer facility can be used for this?
I have checked out
alarm()andsignal()system calls, but these calls doesn't take an argument, so its not possible to associate application request with the matured alarm.Any inputs?
Thanks in advance,
Tom__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 6 lines · Tom Sanders
I'm writing an application server which receives requests from other applications. For each request received, I want to start a timer so that I can fail the application request if it could not be completed in max specified time.
Quoted 9 lines
Which Linux timer facility can be used for this?
I have checked out
alarm()andsignal()system calls, but these calls doesn't take an argument, so its not possible to associate application request with the matured alarm.Any inputs?
Yes, get a book like "Advanced Programming in the UNIX Environment" W. Richard Stevens and look how to use signals and select()/poll() from there.
Also if you are able to use tools to have the protocol defined by ASN.1 that would help, because then you could be able to have tools to generate automatically protocol handling code too with C or C++ etc.
I'm not in the latter business, read and used some code from the above book long time ago, but I've seen nice tools used more and more rather than hand-coding the protocol (because it's very easy get in troubles with hard to find errors of incomplete state-machine etc.)
HTH,
:-) riku
Signature · 1 line
[ This .signature intentionally left blank ]
Quoted 7 lines · Tom Sanders
I'm writing an application server which receives requests from other applications. For each request received, I want to start a timer so that I can fail the application request if it could not be completed in max specified time.
Which Linux timer facility can be used for this?
I used setitimer for a similar task. Since you can only have one timer going at any given time, I set up a linked list of timing events, with each event's timeout expressed as a delta from the previous event. This way changing the time on the system has no effect on the application. The itimer is then set for the first event in the list. When a timer goes off, it optionally re-inserts the event into the list, starts the next itimer, and then calls a callback function for the expired event with an opaque data pointer as an argument.
Works really well.
Chris
Signature · 4 lines
Chris Friesen | MailStop: 043/33/F10 Nortel Networks | work: (613) 765-0557 3500 Carling Avenue | fax: (613) 765-2986 Nepean, ON K2H 8E9 Canada | email: [email protected]
Hi Chris and Tom :))
Quoted 4 lines
Quoted 1 line
Which Linux timer facility can be used for this?
I used setitimer for a similar task. Since you can only have one timer going at any given time, I set up a linked list of timing events, with each event's timeout expressed as a delta from the previous event.
Tom, if you're interested, I coded a timer multiplexor for Linux
(user space, I mean) a time ago, and although it hasn't been released yet, has been in use for a year in The Puto Amo Window Manager, so I think it is pretty stable. It's GPL'd, but not released yet because it lacks documentation by now and I want to change a couple of things.
If you want, I can attach you the code (is pretty simple), or
even better, you can go to www.pleyades.net/~pawm, download the window manager and pick the code from there (is a bit more updated that mine, since has a couple of contributions). The file is called timux.[c,h], and needs too the file chain.c for the data container. Just let me know. And count on any help you need with TiMux ;))
Raúl