Cassandra, .NET, Connection Pools and TCP/IP Port Exhaustion

posted in
The Cassandra Thrift client does not contain any connection pools.  Since it connects via TCP/IP, you will inevitably run out of sockets if you call the Cassandra often.

The error you will see (at least in .NET) is:

"Only one usage of each socket address (protocol/network address/port) is normally permitted".

Here's some code that will cause this error:

If you run netstat -n after you run this code, you'll see this:

TCP/IP ports do not close right away.  Instead, they go into a TIME_WAIT state for 240 seconds.  

So, in order to use Cassandra in any high volume application, you'll have to implement your own connection pool.

The three .NET cassandra clients seem to implement connection pooling. 

   This comment seems to imply that the connection pooling code in Hector Sharp is problematic.  After briefly looking at it, it made me nervous.  Anyone have any experience with it?

  Fluent Cassandra Connection Pool Code (requires .NET 4.0)

Alternatively, you can implement your own connection pooling mechanism.
Find a problem or mistake? File a bug or better yet, submit a pull request
Copyright © 2010 - 2022 - Doug Tarr