Spray, Slick, Spark - OutOfMemoryError: PermGen space
Spray, Slick, Spark - OutOfMemoryError: PermGen space
我已经使用 Spray
和 Slick
成功实现了一个简单的 Web 服务,该服务通过 Spark ML 预测管道传递传入请求。一切正常,直到我尝试添加数据层。我选了Slick 好像很受欢迎
但是,我无法ui让它正常工作。我的大部分代码都基于 Hello-Slick Activator Template。我像这样使用 DAO 对象:
object dataDAO {
val datum = TableQuery[Datum]
def dbInit = {
val db = Database.forConfig("h2mem1")
try {
Await.result(db.run(DBIO.seq(
datum.schema.create
)), Duration.Inf)
} finally db.close
}
def insertData(data: Data) = {
val db = Database.forConfig("h2mem1")
try {
Await.result(db.run(DBIO.seq(
datum += data,
datum.result.map(println)
)), Duration.Inf)
} finally db.close
}
}
case class Data(data1: String, data2: String)
class Datum(tag: Tag) extends Table[Data](tag, "DATUM") {
def data1 = column[String]("DATA_ONE", O.PrimaryKey)
def data2 = column[String]("DATA_TWO")
def * = (data1, data2) <> (Data.tupled, Data.unapply)
}
我在我的 Boot
对象中初始化我的数据库
object Boot extends App {
implicit val system = ActorSystem("raatl-demo")
Classifier.initializeData
PredictionDAO.dbInit
// More service initialization code ...
}
我尝试在完成服务请求之前向我的数据库添加一条记录
val predictionRoute = {
path("data") {
get {
parameter('q) { query =>
// do Spark stuff to get prediction
DataDAO.insertData(data)
respondWithMediaType(`application/json`) {
complete {
DataJson(data1, data2)
}
}
}
}
}
当我向我的服务发送请求时,我的应用程序崩溃了
java.lang.OutOfMemoryError: PermGen space
我怀疑我没有正确实施 Slick API。很难从文档中分辨出来,因为它把所有的操作都塞进了一个 main 方法中。
终于,我的conf和激活器一样了ui
h2mem1 = {
url = "jdbc:h2:mem:raatl"
driver = org.h2.Driver
connectionPool = disabled
keepAliveConnection = true
}
有人遇到过这个吗?我正在使用 Slick 3.1
java.lang.OutOfMemoryError: PermGen space
通常不是你使用的问题,这里是oracle says about this。
The detail message PermGen space indicates that the permanent generation is full. The permanent generation is the area of the heap where class and method objects are stored. If an application loads a very large number of classes, then the size of the permanent generation might need to be increased using the -XX:MaxPermSize option.
我不认为这是因为 Slick API 的实施不正确。发生这种情况的原因可能是您正在使用多个加载许多 类.
的框架
您的选择是:
- 增加 perm gen 大小
-XX:MaxPermSize
- 升级到 Java 8. The perm gen space is now replaced with MetaSpace which is tuned automatically
我已经使用 Spray
和 Slick
成功实现了一个简单的 Web 服务,该服务通过 Spark ML 预测管道传递传入请求。一切正常,直到我尝试添加数据层。我选了Slick 好像很受欢迎
但是,我无法ui让它正常工作。我的大部分代码都基于 Hello-Slick Activator Template。我像这样使用 DAO 对象:
object dataDAO {
val datum = TableQuery[Datum]
def dbInit = {
val db = Database.forConfig("h2mem1")
try {
Await.result(db.run(DBIO.seq(
datum.schema.create
)), Duration.Inf)
} finally db.close
}
def insertData(data: Data) = {
val db = Database.forConfig("h2mem1")
try {
Await.result(db.run(DBIO.seq(
datum += data,
datum.result.map(println)
)), Duration.Inf)
} finally db.close
}
}
case class Data(data1: String, data2: String)
class Datum(tag: Tag) extends Table[Data](tag, "DATUM") {
def data1 = column[String]("DATA_ONE", O.PrimaryKey)
def data2 = column[String]("DATA_TWO")
def * = (data1, data2) <> (Data.tupled, Data.unapply)
}
我在我的 Boot
对象中初始化我的数据库
object Boot extends App {
implicit val system = ActorSystem("raatl-demo")
Classifier.initializeData
PredictionDAO.dbInit
// More service initialization code ...
}
我尝试在完成服务请求之前向我的数据库添加一条记录
val predictionRoute = {
path("data") {
get {
parameter('q) { query =>
// do Spark stuff to get prediction
DataDAO.insertData(data)
respondWithMediaType(`application/json`) {
complete {
DataJson(data1, data2)
}
}
}
}
}
当我向我的服务发送请求时,我的应用程序崩溃了
java.lang.OutOfMemoryError: PermGen space
我怀疑我没有正确实施 Slick API。很难从文档中分辨出来,因为它把所有的操作都塞进了一个 main 方法中。
终于,我的conf和激活器一样了ui
h2mem1 = {
url = "jdbc:h2:mem:raatl"
driver = org.h2.Driver
connectionPool = disabled
keepAliveConnection = true
}
有人遇到过这个吗?我正在使用 Slick 3.1
java.lang.OutOfMemoryError: PermGen space
通常不是你使用的问题,这里是oracle says about this。
The detail message PermGen space indicates that the permanent generation is full. The permanent generation is the area of the heap where class and method objects are stored. If an application loads a very large number of classes, then the size of the permanent generation might need to be increased using the -XX:MaxPermSize option.
我不认为这是因为 Slick API 的实施不正确。发生这种情况的原因可能是您正在使用多个加载许多 类.
的框架您的选择是:
- 增加 perm gen 大小
-XX:MaxPermSize
- 升级到 Java 8. The perm gen space is now replaced with MetaSpace which is tuned automatically