tags:

views:

150

answers:

3

I need to implement a daemon that needs to extract data from a database, load the data to memory, and according to this data perform actions like sending emails or write/update files. These actions need to be performed every 30 minutes.

I really don't know what to decide. Compile a c++ program that will do the task or use scripts and miscellaneous Linux tools (sed/awk).

What will be the fastest way to do this? To save cpu and memory.

The dilemma is about marinating this process if it's script it does not need compilations and I can just drop it into any machine linux/unix but if it's native it's more harder.

What do you think?

+3  A: 

Use cron(1) to start your program every 30 minutes.

So called scripting languages will definitely enable you to write your program more quickly than C++. But doing this with shell and sed an/or awk, while definitly possible, is very difficult when you have to cope with all corner cases, particularly regarding strings escaping (think quotes, “&”’s “;”’s…).

I suggest you go with a more full featured “scripting” language such as Perl or Python.

kmkaplan
+1  A: 

Why are you trying to save CPU & Memory? Are you absolutely sure this is a real requirement (or just "premature optimization")?

Unless performance is critical, there's absolutely no reason to code such a thing in C++. It seems to be a sort of maintenance process (right?). I say write it in the highest level script language you know. Python or PHP seem like good candidates. Even if you don't know these languages, it would still take you less time to familiarize yourself with them than it would take you to do it in C++.

Assaf Lavie
A: 

I'd go with a Python/Perl/Ruby implementation with a cron entry to schedule the script to run every 30 minutes.

If performance becomes an issue you can add a column to you DB that tracks the last time you ran calculations for the account and then split the processing of your records into groups of 2 or 3 or 4, running them ever 15, 10, 5 minutes respectively.

If after splitting your calculations into groups, you still have performance demands then consider C++/C/Java.

I'd still run this using cron though. No need to be a daemon unless you are providing on-demand services.

ceretullis