OOM Exceptions Max Addressable Space and Apache.NMS

by jmorris 15. June 2010 17:30

I kept running into OutOfMemoryExceptions in one my Unit Tests that tested some very basic pub/sub functionality with Apache.NMS. Basically, I could create aproximently 1835 consumers before the following exception was thrown:

I was a bit perplexed by this exception, first all because it happened at nearly the exact same number of consumers being created. Secondly, because that really wasn't that high of a number...I was expected failures to be in 100K or even 1M range...

Looking at my code, the problem became clear as day: I was creating a session per consumer.

Why is this bad? Little background on JMS (Java Messaging Service), which of course Apache.NMS is based (dotnet for JMS):

  • Each client should have a single connection
  • Each connection should manage less than 500 sessions
  • Each session is a thread
  • Each session can create n consumers/subscribers

The problem I was having is that I was running out of addressable space when I was creating 1:1 session to consumer. Each thread took up approximently 1MB thread stack * ~2000 session objects => 2GB max addressable memory space on a windows x86 process. Given that I was running a unit test with Resharper in VS2008, which undoubtedly consumes more threads, I reached the threshold at slightly lower than 2K threads.

With a simple refactor, I was able to run a subsquent unit test where 100K consumers were created on a single session!

Tags: ,

Apache.NMS | JMS

Pingbacks and trackbacks (2)+

Jeff Morris

Tag cloud

Month List

Page List