1

As I understand it, load-balancing with nginx is typically based on requests, i.e. each request is forwarded somewhere different, be it to remote machines or to instances of a local service. However, I need to configure it to be session-based: nginx should spawn a new (local) process of nodejs for each client it's talking to, i.e. one per session. For a single session, every request should then be forwarded to that process. The process should be terminated when the session is closed or when it times out.

The reason why I want to do this is because nodejs has to contact a database, and it would probably be too inefficient if it had to connect and disconnect for every request. Instead it should connect to the database once per session. When the session is closed, nodejs should be terminated gracefully so it has the opportunity to properly close the connection to the db.

How can I do this? If it is not possible, how can I avoid having to connect to the database on each request?

0

You must log in to answer this question.

Browse other questions tagged .