A A
RSS

Running Multiple hunchentoot instances

Sun, Sep 6, 2009

Programming

So if you are someone like me and interested in developing  web applications in Common Lisp then you have probably come across hunchentoot by Dr Edi Weitz. Now hunchentoot is not the only common lisp web-server out there and there are those who argue against its design concepts but it is one that I have found to well suit my need. Now I will be writing a list of posts about how to go around setting up things to work for a web application, but for this post i want to talk about multiple hunchentoot instances.

As you might know lisp hosting is not abundant so must of the time you need your own server instance to run your lisp on. However instances are relatively expensive when compare to other hosting options so it might be useful if you could run multiple websites of the same server. And it turns out you can do exactly that with hunchentoot and you do not need multiple instances of your common lisp running (I use SBCL).

Your first option is to visit Cyrus Harmon website and get his hunchentoot vhost code and run it on top of your hunchentoot. The code is clean and understandable and last i checked Cyrus uploaded a new version on 12 June 2009.

Your second option is to use hunchentoot built in capabilities and separate your websites on different ports (you could use a webproxy in front but that is another post). Start by creating your hunchentoot instance in the following manner:

(hunchentoot:start (make-instance ‘hunchentoot:acceptor
:port port
:request-dispatcher dispatcher))

Now the important part is that we started by telling this particular instance that we need hunchentoot to listen to the designated port. The key thing you need to take care of however is the parameter request-dispatcher. It turns out creating a hunchentoot acceptor this way you can no longer use any of hunchentoot built in dispatcher functionality (Which is the price you have to pay). So how to deal with that is to make sure that the dispatcher is actually a function that return the appropriate html.

This function needs to take one argument which is the response object and then return the proper html based on the response. There are different ways to do this that could be fast. One suggestion which I implemented was to create a hash table with the url as the key and the handler function as the value and i simply do a funcall on the handler function. it is that simple :) .

Hope you enjoyed the above and stay tuned for some more information on lisp programming.

Tags:

4 Responses to “Running Multiple hunchentoot instances”

  1. BIlly says:

    Just what I was looking for, thanks!

    If you have time, I would be interested to see a fuller example with multiple dispatchers. I think I’ve settled on using nginx proxy in front with this kind of setup.

  2. Arsento says:

    Are you a professional journalist? You write very well.

Leave a Reply