mauricio / postgresql-async

Async, Netty based, database drivers for PostgreSQL and MySQL written in Scala
Apache License 2.0
1.43k stars 222 forks source link

commit 90e4194 causes massive performance degradation #179

Open njeuk opened 8 years ago

njeuk commented 8 years ago

Hi, I'm seeing a massive performance degradation with the commit https://github.com/mauricio/postgresql-async/commit/90e4194adb2d02b229fcccdc754513e486518bb7 . I suspect Postres handles with the numeric conversions badly -- but not really sure that is the root cause yet, or how to work around the issue.

Sample code:

object TestPerf {
  def main(args: Array[String]): Unit = {
    val configuration = URLParser.parse("jdbc:postgresql://someaddress/somedb?user=someuser&password=topsecret")
    val connection: Connection = new PostgreSQLConnection(configuration)
    Await.result(connection.connect, 50.seconds)
    val startTime = LocalDateTime.now()
    for (i <- Range(1, 1000)) {
      val id = Random.nextInt(3000000)
      Await.result(connection.sendPreparedStatement("update companies set name = name where id = ?", Array(id)), 10.seconds)
      val elapsed = java.time.Duration.between(startTime, LocalDateTime.now())
      println(s"$i : ${elapsed.toMillis / i} average mSec per update")
    }
    connection.disconnect
  }

With https://github.com/mauricio/postgresql-async/commit/90e4194adb2d02b229fcccdc754513e486518bb7 applied, I get a response like:

[info] Running com.example.TestPerf 
1 : 1611 average mSec per update
2 : 1463 average mSec per update
3 : 1526 average mSec per update
4 : 1438 average mSec per update

without:

[info] Running com.example.TestPerf 
1 : 68 average mSec per update
2 : 67 average mSec per update
3 : 61 average mSec per update
mauricio commented 8 years ago

Gonna remove that and see if we can come up with a better solution.

augi commented 8 years ago

Maybe we ran into the same issue - we used 0.2.16 and when I updated it to 0.2.20 then few tests started to timeout. Downgrading to 0.2.19 didn't help, 0.2.18 works well (the mentioned commit was added to 0.2.19).

oshai commented 6 years ago

I fixed/reverted this in jasync-sql(fork) 0.8.30: https://github.com/jasync-sql/jasync-sql/pull/16 . more details in the issue: https://github.com/jasync-sql/jasync-sql/issues/15