tdebarochez/connect-couchdb — pull request #16 by ianshward (2012-05-31 21:14:39+00:00)
Title: Don't update unchanged session so often - performance issue

This pull request changes how #set() works, whereby if the current session in couch is the same as the session which is about to be `put` to couch, except for timestamps, like lastAccess, expires, and originalMaxAge, and less than 1 minute has passed since the last `put` for this session, then, don't put the session.

Performance wise, the `put` operation is very slow. I've benchmarked the performance impact on a stack of two servers with couchdb replication running for the session database, and observe the current situation (`put` no matter what) at **25 r/s** compared to `put` only if something significant in the session changed or if > 1m has passed since this session was last put at **105 r/s** which is a major improvement.

The consequence of lots of puts at the second or sub-second level leads to couchdb becoming slow, dealing with the flurry of conflicts and replication. Once you have maybe 20 or 40 concurrent users surfing around on your web app this becomes a real bottleneck / scalability breaking point.

I've also written a test that tests a session really is not `put` if nothing significant changes in under a minute, and that the session really is changed if significant data changes and is then attempted to be `set`.