问题描述
在检查Spray API的吞吐量时。
While checking the throughput of spray api.
场景:同时存在25个用户
Scenario: 25 concurrent users
操作系统:免费BSD
Os: Free BSD
内存:2GB
内核数:2
在大约13个并发用户处,我遇到以下错误。
At around 13 concurrent users i was getting the following error.
[ERROR] [06/29/2015 05:01:56.407] [default-akka.actor.default-dispatcher-2] [ActorSystem(default)] Uncaught error from thread [default-akka.actor.default-dispatcher-2] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled
java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:714)
at scala.concurrent.forkjoin.ForkJoinPool.tryAddWorker(ForkJoinPool.java:1672)
at scala.concurrent.forkjoin.ForkJoinPool.deregisterWorker(ForkJoinPool.java:1795)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:117)
Akka和Spray Conf更改为默认值:
Akka and Spray Conf changes from default:
akka{
tcp{
register-timeout = 20s
}
}
spray.can {
request-timeout = 30 s
bind-timeout = 30s
unbind-timeout = 5s
registration-timeout = 30s
}
http.spray.can {
server{
pipelining-limit = 50
}
}
是什么引起了OutOfMemmoryError。 路由器角色
What is causing the OutOfMemmoryError. The exception is thrown from the router actor
推荐答案
抛出异常,但您可能会阻止参与者( Await.result
或类似行为)。 ForkJoinPool
自动为每个被阻止的线程创建一个新线程。因此,如果您有一个长时间的块,则count_of_threads == count_of_requests(+每个线程都包含引用iside调用堆栈),最终会导致 OutOfMemory
。
can't read mind, but probably you do blocking (Await.result
or similar) inside actors. ForkJoinPool
creates a new thread for every blocked one automatically. So if you have a long-time blocks count_of_threads == count_of_requests (+ every thread holds the references iside call stack), which eventually causes OutOfMemory
.
请参见
PS ,您可能会发现为什么 Await.result
(在内部使用 scala.concurrent.blocking
)导致在 ForkJoinPool (甚至不考虑
maxParallelism
)。
P.S. Here you may find why
Await.result
(which uses scala.concurrent.blocking
inside) leads to unmanageable creation of threads in ForkJoinPool
(even regardless of maxParallelism
).
或者您创建很多
ActorSystem
s,指出:
Or you creating a lot of
ActorSystem
s, same page of akka documentation states:
这篇关于Scala,Spray,Akka-java.lang.OutOfMemoryError:无法创建新的本机线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!