Search code examples
herokuclojurejettycompojure

Limiting the number of threads Compojure spawns


I'm running compojure on Heroku. They have a limit of a 100 threads per process. So when I go over that limit, I get: java.lang.OutOfMemoryError: unable to create new native thread. Compojure is using the jetty ring adapter. Is there away of configuring the the server to only accept a hundred threads to the servlet at a time?


Solution

  • The solution comes from Chris Perkins over at the compojure google group.

    (run-jetty app {:configurator #(.setThreadPool % (QueuedThreadPool. 5))})
    

    This initializes a QueuedThreadPool (with a concurrent limit of five threads) to the jetty instance, before it starts.