Set limit for insert

16 views
Skip to first unread message

Konstantin Palyanichka

unread,
Feb 21, 2017, 4:26:27 AM2/21/17
to Slick / ScalaQuery

Hi, I trying using akka, slick and HikariCP for  insert parsed records from json to postgresql.
At some time, my database return message about many connection at time and than locks and restarting with message No connection could be made because the target machine actively refused it.
For inserting data I am using function like this:

def insertCommentRecords(data:List[(Int, Int, Int, Option[String], String, Option[String], String, java.sql.Timestamp, String, Option[String], Option[String])]){
   val db = Database.forConfig("pg-postgres")
    var korrCommentsRecords: TableQuery[KorrCommentsTable]= TableQuery[KorrCommentsTable]
    val setupAction = DBIO.seq(korrCommentsRecords.schema.create)
    if (Await.result(db.run(MTable.getTables("korr_comments")),  Duration.Inf).toList.isEmpty ==true){
      try {
        Await.result(db.run(setupAction), Duration.Inf)
      } catch {
        case e:Exception => println(e )
      }
    }
    //var insertAction: DBIO[Option[Int]] = korrTextRecords ++= data.toList.map(matchValue)
    val insertAction = DBIO.sequence(data.iterator.map{row =>
      korrCommentsRecords+=row
    })
    Await.result(db.run(insertAction),  Duration.Inf)
    db.close()
  } 

Hikari configs:

pg-postgres = {
  url = "jdbc:postgresql://localhost:5432/news"
  user = "postgres"
  password = some_pass
  driver = org.postgresql.Driver,
  connectionTimeout=300000,
  idleTimeout=600000,
  MaxLifetime=3000000,
}

at the end when i rich limits( 100 connections or over ) i get next message:
com.zaxxer.hikari.util.ConcurrentBag - ConcurrentBag has been closed, ignoring add()
My question is: how i can solve my problem ?

Reply all
Reply to author
Forward
0 new messages