我目前正在加载测试activemq的默认REST API。 我的所有100个用户都尽可能快地将相同的消息文本写入同一目的地。几秒钟后,我得到:
java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:640)
at org.apache.activemq.thread.TaskRunnerFactory.execute(TaskRunnerFactory.java:92)
at org.apache.activemq.thread.TaskRunnerFactory.execute(TaskRunnerFactory.java:85)
at org.apache.activemq.broker.TransportConnector$1.onAccept(TransportConnector.java:211)
at org.apache.activemq.transport.vm.VMTransportServer.connect(VMTransportServer.java:91)
at org.apache.activemq.transport.vm.VMTransportFactory.doCompositeConnect(VMTransportFactory.java:145)
at org.apache.activemq.transport.vm.VMTransportFactory.doConnect(VMTransportFactory.java:53)
at org.apache.activemq.transport.TransportFactory.doConnect(TransportFactory.java:51)
at org.apache.activemq.transport.TransportFactory.connect(TransportFactory.java:80)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:243)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:258)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:230)
at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:178)
at org.apache.activemq.web.WebClient.getConnection(WebClient.java:246)
at org.apache.activemq.web.WebClient.createSession(WebClient.java:348)
at org.apache.activemq.web.WebClient.getSession(WebClient.java:239)
at org.apache.activemq.web.MessageServletSupport.getDestination(MessageServletSupport.java:319)
at org.apache.activemq.web.MessageServletSupport.getDestination(MessageServletSupport.java:267)
at org.apache.activemq.web.MessageServlet.doPost(MessageServlet.java:110)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:527)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1216)
at org.apache.activemq.web.SessionFilter.doFilter(SessionFilter.java:45)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1187)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:421)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:493)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:930)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:358)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:866)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:456)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113)
at org.eclipse.jetty.server.Server.handle(Server.java:351)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:594)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1059)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:764)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:217)
at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:424)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:506)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:436)
at java.lang.Thread.run(Thread.java:662)
由于我已经使用10G堆空间运行并且只模拟了10个REST用户,我不明白为什么activemq会生成8000个线程。我希望有人可以帮我解决这个问题。
答案 0 :(得分:1)
此内存泄漏的原因在于activemq的连接处理。默认的servlet为每个httpsession创建一个连接(这是一个非常糟糕的主意)。我的负载测试工具不关心会话,也不发送会话ID。因此,发送的每条消息都是一个新连接,是一个新线程,在17.000个线程之后,jvm就完成了。
基本上我将编写一个每个工作线程使用一个连接的新servlet。这应该将线程数限制在最低限度。