After daemonize a Ruby process (thanks Ruby version 1.9), it is possible
to communicate with on the same machine by using socket on localhost. Do
you know some other methods instead of socket?
After daemonize a Ruby process (thanks Ruby version 1.9), it is possible
to communicate with on the same machine by using socket on localhost. Do
you know some other methods instead of socket?
Sure. In I daemon I've been working on, I just use SQLite as a queue for messages. I use the Amalgalite extension, which is terrific and works well on Ruby 1.9.
When you're going to write to the queue, make sure to grab an "exclusive" lock (via the "transaction" SQL command). When reading, grab an "immediate" lock first. Set a busy handler through Amalgalite that retries for a reasonable time (I use 60 seconds) to grab locks. Add some error handling code for if the lock wait does eventually timeout, but that shouldn't happen under normal operations.
About the only challenges I ran into were deleting data from the queue. Deleting counts as a write, so grab an "exclusive" lock. That was easy of course. The downside is that the SQLite database needs to have the "vacuum" command run on it every so often to reclaim wasted disk space. You can't be holding a lock when you do that though. Thus I locked on an external source about once a day, and vacuumed the database. If it's just a simple queue you need (with no long term storage), you could also just nuke the file and rebuild it periodically.
Anyway, I hope that gives you some fresh ideas.
James Edward Gray II
···
On May 10, 2009, at 4:22 PM, Paul A. wrote:
After daemonize a Ruby process (thanks Ruby version 1.9), it is possible
to communicate with on the same machine by using socket on localhost. Do
you know some other methods instead of socket?
You have got the whole range of IPC at your fingertips
- named FIFO,
- unnamed FIFO if the client is a child process of your daemon,
- Unix domain socket (only on the local machine),
- signals,
- shared memory (with proper locking, e.g. via semaphores),
...
Kind regards
robert
···
On 10.05.2009 23:22, Paul A. wrote:
After daemonize a Ruby process (thanks Ruby version 1.9), it is possible
to communicate with on the same machine by using socket on localhost. Do
you know some other methods instead of socket?
After daemonize a Ruby process (thanks Ruby version 1.9), it is possible
to communicate with on the same machine by using socket on localhost. Do
you know some other methods instead of socket?
You have got the whole range of IPC at your fingertips
- named FIFO,
- unnamed FIFO if the client is a child process of your daemon,
- Unix domain socket (only on the local machine),
- signals,
- shared memory (with proper locking, e.g. via semaphores),
...
And don't forget the simple DRb, if both ends are Ruby:
Also XMLRPC (included in the Ruby standard library, at least it was for
1.8, don't know if it's still in 1.9), and also plenty of ways to embed
a HTTP server into your application (e.g. Webrick, Sinatra)
--
Posted via http://www.ruby-forum.com/\.