serializing logging output mult. proc. inst deamon


 
Thread Tools Search this Thread
Top Forums Programming serializing logging output mult. proc. inst deamon
# 1  
Old 01-04-2007
CPU & Memory serializing logging output mult. proc. inst deamon

Hello, i have an interresting topic today

C++ on solaris. lgpl stuff applicable.
My program is a deamon process wich takes input from network, then processes the data, and outputs reformatted to network. We're generating a lot of logging output. the logging is absolutely unbuffered at the moment like a log should be, fire and forget. (to a file ot STDOUT)

I cant run multiple process instances concurrently because there is no file locking implemented. I cant write to the same logfile from different processes. That means that i would end up with one logfile for each process. unusable.

problem:
I want to run multiple instances of the same process at the same time. The log output has to be in one logfile. The chunks wich are a unit must stay consectutive (there has to be buffer somewhere, i guess). And this i the only change i really want to commit to the existing program, 1 line in the code which tells when 1 "unit" is processed.I want as few changes as possible in the existing program.

How would you propose to achieve that?

i exclude all the "housekeeper process which concats all the generated logs once a day or sth." like ideas. This is crap.


And yeah the _MOST_ important thing.
My head is rolling if i lose 1 byte of logging output ever, under all circumstances. That means if you have ideas in client-server style (pipes sockets, shm, whatever) it has to be transactionoriented somehow.

I is an interresting problem, i greatly appreciate every creative idea!!!
Thanks folks!
Heck
# 2  
Old 01-04-2007
Quote:
My head is rolling if i lose 1 byte of logging output ever, under all circumstances
How then are you handling disk full, I/O errors, bus errors, and kernel panic? Personally, I know that it is not possible to prevent file I/O data loss under some circumstances. Even if you trap every signal you can think of.

If you're that worried about the logging data why not let a db handle it?
Use a threaded log server, create a sequential key nomenclature that is unique to the thread - the db can do that - Oracle for example:sessionid & sequence. Guaranteed to be unique to 10^31 iterations. Reading the data back from the db is trivial - read by key.

Or implement a key scheme for regular file i/o.
That means any process can write and flush one record, because the record order is preserved by the key. Example key: date-pid-24hour time in seconds-<counter or ms>
A simple sort on read resurrects the correct order.
# 3  
Old 01-04-2007
Note: you do realize that you have to call aio functions to guarantee completion of a write to disk, right? write() (called by stdio) only "promises" to write to disk sometime sooner or later, unless every i/o call has fdatasync (or fsync or whatever your box has) associated with it which slows down i/o a lot.

See: page 189, M J Rochkind 'Advanced UNIX Programming' 2nd ed
# 4  
Old 01-05-2007
Quote:
How would you propose to achieve that?
Locking the log file- If that was the option for such an I/O intensive operation, that's not to be appreciated.

Because once I deliberately switched logfile locking from shared memory resource locking to a simple file locking method for threaded application, the performance drastically came down just because they have to wait for the logfile to be unlocked ( that was done as staling the process untill the file lock on the log file was released )

Since other constraints about having one more process or additional resource utilization was not mentioned, am suggesting this idea. (Not sure whether its creative or trustworthy Smilie )

for the logs from 'n' different processes to a single log file 'lf'
a) stamp the log messages ( precision to be decided based on the frequency in which log messages are dumped consecutively ) such that they are redirected to a temp_log_file 'temp_lf'
b) either you can have an another iterative process or standard utility to parse and feed the actual log file 'lf' from the temp file 'temp_lf'. That is the reason I had requested to stamp the log messages which would be easier while parsing.
c) once done periodically clean the 'temp_lf' file.
d) apart from erratic/strange behaviour I really dont see any situation/condition where you have to worry for a single byte loss Smilie

(Oops! Jim had already mentioned about time-stamping)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Logging the memory consumed by a process with c/C++ without using proc

I need to log the size of physical/virtual memory consumed by any given given process using c/c++ code running on solaris and aix without using the proc filesystem. Please advise. (1 Reply)
Discussion started by: Manisha Paul
1 Replies

2. Shell Programming and Scripting

how to convert string to an integer and how to do calculations like add.,sub.,mult. on it

How to convert string into an integer or number For example : % set tim = `date` % echo $tim Tue Feb 22 16:25:08 IST 2011 here How to increment time by 10 hrs like 16+10 , here 16 is a string in date cmd. .. how to convert 16 to an integer and added to a another nimber ? Thanks... (3 Replies)
Discussion started by: sbhamidi
3 Replies

3. Red Hat

Output of /proc/version

Hi, I am a newbie in Linux. Appended is the output of cat /proc/version and uname -a. # cat /proc/version Linux version 2.6.32.12-115.fc12.i686 (mockbuild@x86-03.phx2.fedoraproject.org) (gcc version 4.4.3 20100127 (Red Hat 4.4.3-4) (GCC) ) #1 SMP Fri Apr 30 20:34:53 UTC 2010 # uname -a... (7 Replies)
Discussion started by: Hari_Ganesh
7 Replies

4. UNIX for Advanced & Expert Users

Serializing script Failing for more commands

I have a reqirement to serialise various rsh scripts that hit my server from an external scheduler. No matter how many scripts come via rsh, only one should execute at a time and others should wait. I have made the scheduler make a request to my shell script with the command to be run as a... (4 Replies)
Discussion started by: nkamatam
4 Replies

5. UNIX for Dummies Questions & Answers

Logging Command Line and Output in Unix

Hi, This might be a bit stupid question, but what command to use to create like a session which logs the command line, and output on to the screen? Basically, a log to a file, where I can review what I had install, uninstall, etc. Thank you (4 Replies)
Discussion started by: kittoinc
4 Replies

6. UNIX for Dummies Questions & Answers

_/proc/stat vs /proc/uptime

Hi, I am trying to calculate the CPU Usage by getting the difference between the idle time reported by /proc/stat at 2 different intervals. Now the 4th entry in the first line of /proc/stat will give me the 'idle time'. But I also came across /proc/uptime that gives me 2 entries : 1st one as the... (0 Replies)
Discussion started by: coderd
0 Replies

7. Solaris

Logging commands and output

I'm looking for a CLI utility that will capture all the commands you type at the Solaris CLI (and their output) into a file. I'm sure it's called "scripter", but I can't find anything on a command called scripter. Does anyone know of a such a command? Your help will be greatly... (3 Replies)
Discussion started by: soliberus
3 Replies

8. Shell Programming and Scripting

Redirection of output (for logging)

Hi, Currently I'm working on a lenghty script so I figured it would be useful to create a logfile so that output that is displayed on the users screen is also stored in the log file for later reference...... kinda like the whole point of a log file! Anyway, I was just wondering if there was an... (3 Replies)
Discussion started by: _Spare_Ribs_
3 Replies

9. UNIX for Advanced & Expert Users

logging ps output

i want to log the output of ps. i want to see the ps outpıt line by line as i see in the stdout but when i write it to a file it concatenates all lines do you have any suggestion? what i am using: echo `ps -ef -o cmd,cpu,pcpu,cputime,nswap`>>log.txt what i am getting: Mon Sep 11... (3 Replies)
Discussion started by: gfhgfnhhn
3 Replies

10. UNIX for Dummies Questions & Answers

Inst. Solaris10

I just download solaris 10, from sun.com, I have them ziped in my HD, How can I install them, so I can run solaris10, my present os is RH9; THANKS (5 Replies)
Discussion started by: mxlst14
5 Replies
Login or Register to Ask a Question