views:

135

answers:

1

I'd like to have a small (not doing too damn much) daemon running on a little server, watching a directory for new files being added to it (and any directories in the main one), and calling another Clojure program to deal with that new file.

Ideally, each file would be added to a queue (a list represented by a ref in Clojure?) and the main process would take care of those files in the queue on a FIFO basis.

My question is: is having a JVM up running this little program all the time too much a resource hog? And do you have any suggestions as to how go about doing this?

Thank you very much!

EDIT: Another question I should ask: should I run this as its own instance (using less memory) and have it launch a new JVM when a file is seen, or have it on the same JVM the Clojure code that will process the file?

+1  A: 

As long as it is running fine now and it has no memory leaks it should be fine.

From the daemon terminology I gather it is on a unix clone, and in this case best is to start it from an init script, or from the rc.local script. Unfortunately details differ from OS to OS to be more specific.

Limit the memry using -Xmx=64m or something to make sure it fails before taking down the rest of the services. Play a bit with the number to find the lowest reliable size.

Also, since clojures claim to fame is its ability to deal with concurrency it make a lot of sense to only run one JVM with all functionality running on it in multiple threads. The overhead of spawning new processes is already very big and if it is a JVM which needs to JIT and warm up its memory management, doubly so. On a resource constrained machine could pose a problem. and on a resource rich machine this is a waste.

I always found that the JVM is not made to quickly run something script like and exit again. It is really not made for that use case in my opinion .

Peter Tillemans
The JVM actually consumes more memory then its max heap setting. Although I love clojure for such a simple app running a JVM seems tremendous overhead.
Bozhidar Batsov