atomic logging

  • Follow


hi

I want to write to a single log file from multiple Lisp processes.
Is there a way to do this safely (so multiple processes writing at same time 
won't mess up, e.g. no records will be lost etc.)?

I'm using SBCL on Linux. 

0
Reply Captain 9/10/2010 8:44:01 AM

Captain Obvious wrote:
> hi
>
> I want to write to a single log file from multiple Lisp processes.
> Is there a way to do this safely (so multiple processes writing at same
> time won't mess up, e.g. no records will be lost etc.)?
>
> I'm using SBCL on Linux.


You can lock your log file while you are writing to it.
I once submitted a proposal for adding file locking to the CL cookbook.
http://sourceforge.net/tracker/?func=detail&aid=2969914&group_id=46815&atid=447474
Maybe it was a stupid idea, or a stupid implementation, I don'k know, 
nobody ever replied. :-)
0
Reply Giovanni 9/10/2010 8:59:41 AM


On Sep 10, 9:44=A0am, "Captain Obvious" <udode...@users.sourceforge.net>
wrote:
> hi
>
> I want to write to a single log file from multiple Lisp processes.
> Is there a way to do this safely (so multiple processes writing at same t=
ime
> won't mess up, e.g. no records will be lost etc.)?
>
> I'm using SBCL on Linux.

I think you would need to use OS features to achieve this because each
process needs to lock the file whilst it's being written to.
Otherwise you might get concurrent writes that overlap.   Which would
probably corrupt your data.

Linux has a flock()/fcntl() system calls that can be used for this
purpose.   These system calls seems to have some support in SBCL in
the sb-posix contributed module.  So that might be a start.   Can't
say that I've used them though.

My understanding of UNIX file locking though is that it's an advisory
lock.   This means that all processes would need to check the lock,
processes that ignored the lock would still be able to modify the
file.   If you don't have access to the source of all the processes
this might be a problem.

Steve
0
Reply Steve 9/10/2010 9:02:27 AM

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09/10/2010 01:44 PM, Captain Obvious wrote:

> I want to write to a single log file from multiple Lisp processes.
> Is there a way to do this safely (so multiple processes writing at same
> time won't mess up, e.g. no records will be lost etc.)?

An easy way to do this is to use a server that reads from a Unix domain
socket and writes to a file.  Your Lisp processes just write to the socket.

Writes to sockets should be atomic, up to a size of PIPE_BUF (4k on
Linux/x86).


Faried.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyJ+IsACgkQWVufAqdzMWNP8QCfVWalU+EGLXQicEwlcbS4ktdj
1SYAnjOGnIe2E4ZWlANE6nBuOqUDxqLZ
=GBIQ
-----END PGP SIGNATURE-----
0
Reply fn1 (2) 9/10/2010 9:21:20 AM

On 2010-09-10 10:21:20 +0100, Faried Nawaz said:

> 
> An easy way to do this is to use a server that reads from a Unix domain
> socket and writes to a file.  Your Lisp processes just write to the socket.

Or syslog (in one of the variants which speak TCP so it is reliable)

0
Reply Tim 9/10/2010 10:03:28 AM

On Fri, 10 Sep 2010 13:03:28 +0300, Tim Bradshaw <tfb@tfeb.org> wrote:

> On 2010-09-10 10:21:20 +0100, Faried Nawaz said:
>
>>  An easy way to do this is to use a server that reads from a Unix domain
>> socket and writes to a file.  Your Lisp processes just write to the  
>> socket.
>
> Or syslog (in one of the variants which speak TCP so it is reliable)

On Linux/Unix boxes syslog does not have to speak TCP or any other true  
network
protocol: it is more likely to use some sort of local sockets (Unix Domain  
Sockets
or something like that).

Programming a Unix Domain Sockets client is a tiny bit easier than  
programming
a network client.

So syslog should be a nice choice (BTW it also makes it possible to log
messages from several boxes at once).


-- 
Tu ne cede malis, sed contra audentior ito --- LvM
0
Reply Victor 9/10/2010 10:38:24 AM

5 Replies
138 Views

(page loaded in 0.117 seconds)


Reply: