Atmosphere/atmosphere — Issue #43: memory leak when running 2 atmosphere instances in one VM
Author: cproinger
Created: 2011-10-23 21:11:12+00:00
State: open

hi jeanfrancois.

i use atmosphere 0.7.2 (i tried 0.8.0-RC2 but with this version something goes wrong, but i couldn't quite make out what exactly "The current Broadcaster has been destroyed and cannot be re-used. Recreating a new one with the same name. You can turn off that mechanism by adding, in web.xml, org.atmosphere.cpr.recoverFromDestroyedBroadcaster set to false" => turned it off, doesn't work either), jersey 1.9.1 and jetty 7.5.1.v20110908 (Jetty7CometSupport).

heres my scenario. i'm performing benchmark tests with 2 programmatically configured and bootstrapped jetty instances with jersey and atmosphere. (every instance-specific objects i bind in the servletContext) one instance sequentially calls the other using AsyncHTTPClient invoking a atmosphere annotaded method like this.

@Path("/read")
@POST
@Suspend(scope = SCOPE.REQUEST, resumeOnBroadcast = true, outputComments = true, listeners = Listener.class)
public Broadcastable readEntries(
ReadEntriesRequest areq,
@HeaderParam(ResourceConstants.X_REQUEST_ID) final Broadcaster bc) {
//first i put my the broadcaster together with a latch in a map so my worker and AtmosphereResourceListener can
//synchronize with it.
lachtes.put(bc, countDownLatch);
//.. here a thread is started that waits on the latch until the listeners onSuspend-Method is called
// and then calls bc.broadcast(data);
return new Broadcastable(null, bc);
}

//Listener-Class

@Override
public void onSuspend(
AtmosphereResourceEvent event) {
//log.info("on suspend: " + event);
Broadcaster bc = event.getResource().getBroadcaster();
CountDownLatch l = latches.get(bc);
l.countDown();
latches.remove(bc);
}

now my tests make ~200.000 requests like this sequentially. after some time theres no progess anymore. The GC is running all the time but cannot free any memory (i guess it's not throwing a OOM because my client stops requesting too at that time). so i made a heap and i saw that there are many JerseyBroadcasters still in Memory (20.091)

i learned the hard way that atmosphere doesn't destroy those by default but i configured the "org.atmosphere.cpr.broadcasterLifeCyclePolicy" to be EMPTY_DESTROY (before that i ran out of memory much ealier). the heapdump now tells me (i analyzed it with the eclipse MemoryAnalyzerTool. i don't do that often so i may misinterpret this) that those Broadcasters are still in the DefaultBroadcasterFactory's ConcurrentHashMap (store).

i stored the heapdump. zipped it's 30 MB. if you could take a look at it i would really appreciate it. how can i make it available to you? should i create a git-repo for it or do you know an easier way?

greets christian