playframework 会在一定时间后释放内存吗?
Does playframework release memory after a certain time?
我是 Play Framework 的新手。我一直在 运行ning Play Framework 2.7.x 生产模式。其实在最简单的代码中:
package controllers
import javax.inject._
import play.api._
import play.api.mvc._
@Singleton
class HomeController @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
def index() = Action { implicit request: Request[AnyContent] =>
Ok(views.html.index())
}
}
转到 运行 我注意到对于每个请求,它都会增加更多的内存使用量。它越来越大。在请求传入增加的阶段,应用程序使用的内存达到 1Gb。我停止发送请求,但我注意到应用程序没有释放任何内存。
我的问题是 - 这个应用程序会释放它占用的内存吗?有没有什么方法可以在不重新启动应用程序的情况下做到这一点?
Play Framework 在 Java Virtual Machine (JVM). JVM usually does not release memory back to the operating system. The memory can be released but it's a rare thing e.g. Java 12 introduced JEP 346: Promptly Return Unused Committed Memory from G1 上运行,但我不确定这对 1 GB 的小堆是否有用。
JVM 通常配置为具有内存消耗上限,并且会保持在该上限以下,或者在不可能时抛出各种 OutOfMemoryError
。您应该配置 JVM,使其对您的服务器具有可接受的内存限制,并让 GC 完成工作。
我是 Play Framework 的新手。我一直在 运行ning Play Framework 2.7.x 生产模式。其实在最简单的代码中:
package controllers
import javax.inject._
import play.api._
import play.api.mvc._
@Singleton
class HomeController @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
def index() = Action { implicit request: Request[AnyContent] =>
Ok(views.html.index())
}
}
转到 运行 我注意到对于每个请求,它都会增加更多的内存使用量。它越来越大。在请求传入增加的阶段,应用程序使用的内存达到 1Gb。我停止发送请求,但我注意到应用程序没有释放任何内存。
我的问题是 - 这个应用程序会释放它占用的内存吗?有没有什么方法可以在不重新启动应用程序的情况下做到这一点?
Play Framework 在 Java Virtual Machine (JVM). JVM usually does not release memory back to the operating system. The memory can be released but it's a rare thing e.g. Java 12 introduced JEP 346: Promptly Return Unused Committed Memory from G1 上运行,但我不确定这对 1 GB 的小堆是否有用。
JVM 通常配置为具有内存消耗上限,并且会保持在该上限以下,或者在不可能时抛出各种 OutOfMemoryError
。您应该配置 JVM,使其对您的服务器具有可接受的内存限制,并让 GC 完成工作。