2003-01-22 22:07:55

by Tom Sanders

[permalink] [raw]
Subject: 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


2003-01-22 22:57:31

by Steven Dake

[permalink] [raw]
Subject: Re: Linux application level timers?

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

Tom Sanders wrote:

>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
>-
>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/
>
>
>
>
>

2003-01-22 23:27:26

by George Anzinger

[permalink] [raw]
Subject: Re: Linux application level timers?

Tom Sanders wrote:
>
> 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.

Sounds like a job for POSIX clocks & timers. See here:
http://sourceforge.net/projects/high-res-timers/

-g
>
> 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/

--
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

2003-01-23 04:27:22

by Gerhard Mack

[permalink] [raw]
Subject: Re: Linux application level timers?

On Wed, 22 Jan 2003, Tom Sanders wrote:

> 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?

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

[email protected]

<>< As a computer I find your faith in technology amusing.

2003-01-23 08:40:04

by Narsimha Reddy CH

[permalink] [raw]
Subject: Re: Linux application level timers?


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,
--
Narsimha Reddy CH
Storage Area Networking, HCL Technologies
Contact +91-044 2372 8366 ext 1128

http://san.hcltech.com
http://www.hcltech.com



Tom Sanders wrote:
>
> 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
> -
> 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/

2003-01-23 08:42:33

by Riku Meskanen

[permalink] [raw]
Subject: Re: Linux application level timers?

On Wed, 22 Jan 2003, Tom Sanders wrote:

> 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?
>
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

--
[ This .signature intentionally left blank ]

2003-01-23 16:19:40

by Chris Friesen

[permalink] [raw]
Subject: Re: Linux application level timers?

Tom Sanders wrote:
> 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



--
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]

2003-01-23 17:17:53

by DervishD

[permalink] [raw]
Subject: Re: Linux application level timers?

Hi Chris and Tom :))

> >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 http://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