khaldoun kassem wrote:

After Testing SQLite, I guessed that the "wite to file" is the fastest way
to save information to disk.
Yes, there is minimal overhead this way.

I can't use transactions because the aim of the logs is that if my shutdown
incorrectly I can know where is the problem, if I use transactions I'll
loose last actions and may be the cause of the problem
If you use a log file, you must also flush the buffer to disk after every write to ensure that the last log entry will be in the file after a "shutdown". This will cause the same slowdown you are seeing with SQLite since it is flushing its buffers to disk on every commit.

You didn't explain exactly what you mean by "shutdown incorrectly". Are you referring to your application crashing or are you referring to your computer losing power?

If it is application crashes that are the problem, you could probably do your logging from a separate program. Your main application could log to a pipe that a second program reads. The second program can then write the logs to a disk file in batches (using either a database or text file). The main application can flush to the pipe after every write (which should be very fast). It will simply wait if the pipe is full. The log program reads entries from the pipe, waiting if it is empty, writes them to the log file, and flushes after every batch or only when the program exits. As long as the log program doesn't crash too, you will always have the last entry logged by the main application in the log file after it crashes. Effectively your main application is logging to memory (instead of disk) which can be safely read after it has crashed.

HTH
Dennis Cote

Reply via email to