Improving Performance by using the PoolableBroadcasterFactory - Atmosphere/atmosphere GitHub Wiki

PoolableBroadcasterFactory (2.3.0+)

The DefaultBroadcasterFactory keeps references to all created Broadcasters, and for applications that heavily creates new Broadcasters, executing the retrieval operation can cause serious performance issues. If your application creates a lot of Broadcasters, you can take a look at the PoolableBroadcasterFactory, which can be used to significantly improve throughput of an application. By default, Apache Commons Pool2 is used, so you need to add the following dependency:

  <groupId>org.apache.commons</groupId>
  <artifactId>commons-pool2</artifactId>
  <version>2.3</version>

Next, in your web.xml, define:

<init-param>
    <param-name>org.atmosphere.cpr.broadcasterFactory</param-name>
    <param-value>org.atmosphere.pool.PoolableBroadcasterFactory</param-value>
</init-param>

By default the PoolableBroadcastFactory uses an unbounded Apache commons-pool2 implementation. There is also a bounded version available.

Finally, you can configure or define your own pool provider by adding in web.xml:

<init-param>
    <param-name>org.atmosphere.pool.poolableProvider</param-name>
    <param-value>your class that implements org.atmosphere.pool.PoolableProvider</param-value>
</init-param>

For example, to use the BoundedApachePoolableProvider, set

<init-param>
    <param-name>org.atmosphere.pool.poolableProvider</param-name>
    <param-value>org.atmosphere.pool.BoundedApachePoolableProvider</param-value>
</init-param>

and then it max size

<init-param>
    <param-name>org.atmosphere.pool.BoundedApachePoolableProvider.size</param-name>
    <param-value>200</param-value>
</init-param>

The complete implementation can be found here.

⚠️ **GitHub.com Fallback** ⚠️