Unix Programming - Program that wakes up every hour

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > March 2007 > Program that wakes up every hour





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Program that wakes up every hour
Digital Puer

2007-03-22, 1:24 am

I have a C++ program running on Red Hat Linux
that needs to wake up every hour, read a database
through ODBC, and perform accumulations and
other calculations (e.g. to count inventory sold
in the last hour). The problem is such that there
are so many transactions around the world that
real-time aggregation is not feasible, so it must
be done hourly.

I have several design choices:

1. The program can always be running. It can call
sleep() to sleep the remaining minutes until the next
hour.

2. The program can block on, say, a named pipe,
and another hourly program can write to the named
pipe to wake it up. This hourly program can be
started by cron.

3. The program can itself be stateless and kicked
off by cron. When it's started, it reads the database,
runs calculations, and writes back immediately
to the database.

Any opinions?

Ian Collins

2007-03-22, 1:24 am

Digital Puer wrote:
> I have a C++ program running on Red Hat Linux
> that needs to wake up every hour, read a database
> through ODBC, and perform accumulations and
> other calculations (e.g. to count inventory sold
> in the last hour). The problem is such that there
> are so many transactions around the world that
> real-time aggregation is not feasible, so it must
> be done hourly.
>
> I have several design choices:
>
> 1. The program can always be running. It can call
> sleep() to sleep the remaining minutes until the next
> hour.
>
> 2. The program can block on, say, a named pipe,
> and another hourly program can write to the named
> pipe to wake it up. This hourly program can be
> started by cron.
>
> 3. The program can itself be stateless and kicked
> off by cron. When it's started, it reads the database,
> runs calculations, and writes back immediately
> to the database.
>
> Any opinions?
>

3 - that's what cron is for!

--
Ian Collins.
waiting for

2007-03-22, 7:30 am

On 3=D4=C222=C8=D5, =CF=C2=CE=E712=CA=B115=B7=D6, "Digital Puer" <digital_p=
..=2E.@hotmail.com> wrote:
> I have a C++ program running on Red Hat Linux
> that needs to wake up every hour, read a database
> through ODBC, and perform accumulations and
> other calculations (e.g. to count inventory sold
> in the last hour). The problem is such that there
> are so many transactions around the world that
> real-time aggregation is not feasible, so it must
> be done hourly.
>
> I have several design choices:
>
> 1. The program can always be running. It can call
> sleep() to sleep the remaining minutes until the next
> hour.
>
> 2. The program can block on, say, a named pipe,
> and another hourly program can write to the named
> pipe to wake it up. This hourly program can be
> started by cron.
>
> 3. The program can itself be stateless and kicked
> off by cron. When it's started, it reads the database,
> runs calculations, and writes back immediately
> to the database.
>
> Any opinions?


I think using a timer is a good idea! Isn't it?

Lew Pitcher

2007-03-22, 7:30 am

On Mar 22, 12:15 am, "Digital Puer" <digital_p...@hotmail.com> wrote:
> I have a C++ program running on Red Hat Linux
> that needs to wake up every hour, read a database
> through ODBC, and perform accumulations and
> other calculations (e.g. to count inventory sold
> in the last hour). The problem is such that there
> are so many transactions around the world that
> real-time aggregation is not feasible, so it must
> be done hourly.
>
> I have several design choices:
>
> 1. The program can always be running. It can call
> sleep() to sleep the remaining minutes until the next
> hour.


Of course, when your CIO or CFO comes back and tells you that he needs
inventory levels collected at half-hour intervals /for next month
only/, you'll have to implement a couple of program changes.

> 2. The program can block on, say, a named pipe,
> and another hourly program can write to the named
> pipe to wake it up. This hourly program can be
> started by cron.


Hmmmm... one program blocks on a resource that is only released by a
program run by cron.
*Why not just use cron to run the first program??*

> 3. The program can itself be stateless and kicked
> off by cron. When it's started, it reads the database,
> runs calculations, and writes back immediately
> to the database.


Good choice - no program changes, no convoluted operational setup, and
uses a simple tool which is /meant/ for the task.

> Any opinions?


C: cron - final answer.

--
Lew

David T. Ashley

2007-03-22, 1:27 pm

"Digital Puer" <digital_puer@hotmail.com> wrote in message
news:1174536916.769154.249640@y80g2000hsf.googlegroups.com...
>I have a C++ program running on Red Hat Linux
> that needs to wake up every hour, read a database
> through ODBC, and perform accumulations and
> other calculations (e.g. to count inventory sold
> in the last hour). The problem is such that there
> are so many transactions around the world that
> real-time aggregation is not feasible, so it must
> be done hourly.
>
> I have several design choices:


<SNIP>

This is one of those occasional problems where there is no clear best
choice.

#2 is interesting, because I guess you could in principle have the program
running all the time, but use a short program executed via cron to write to
the named pipe (i.e. a combination of #1 and #3).

I believe #3 is the simplest and the most direct. "cron" is intended for
that purpose. But the other solutions don't seem bad, either.

--
David T. Ashley (dta@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)


Daniel Rudy

2007-03-24, 7:27 am

At about the time of 3/21/2007 9:15 PM, Digital Puer stated the following:
> I have a C++ program running on Red Hat Linux
> that needs to wake up every hour, read a database
> through ODBC, and perform accumulations and
> other calculations (e.g. to count inventory sold
> in the last hour). The problem is such that there
> are so many transactions around the world that
> real-time aggregation is not feasible, so it must
> be done hourly.
>
> I have several design choices:
>
> 1. The program can always be running. It can call
> sleep() to sleep the remaining minutes until the next
> hour.
>
> 2. The program can block on, say, a named pipe,
> and another hourly program can write to the named
> pipe to wake it up. This hourly program can be
> started by cron.
>
> 3. The program can itself be stateless and kicked
> off by cron. When it's started, it reads the database,
> runs calculations, and writes back immediately
> to the database.
>
> Any opinions?
>


Use cron.


--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com