Scala Slick 3 high query latency

自古美人都是妖i 提交于 2019-12-25 08:00:43

问题


I am running a very simple query using Slick. The actual database call, according to the logs, only takes ~500µs, but the time between my db.run call and the result is much higher (around 200ms)

Please find below the code snippets that runs the query. It very naively prints timestamps before and after query execution ;) The predictions table is a very simple 4 columns table mapped to a case class.

def getPredictionById(predictionId: Int) = {
    println(new Date().getTime())
    val r = Await.result(db.run(Tables.Predictions.filter(p => p.predictionId === predictionId).result.head), 1 second)
    println(new Date().getTime())
    r
  }

The logs in debug mode are very long so I've put them in a pastebin.

http://pastebin.com/UpuGQJKd

I am expecting a total latency of perhaps a few ms, but I am unsure as of how to achieve it.

I am using SQL Server 2016, freeslick and net.sourceforge.jtds


回答1:


Problem solved using the official Microsoft driver instead of jtds

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>sqljdbc4</artifactId>
    <version>4.0</version>
</dependency>

FYI the driver class is com.microsoft.sqlserver.jdbc.SQLServerDriver

Total time is now ~20ms. Then, adding C3PO, my latency is around 4ms, which is around what I was expecting.



来源:https://stackoverflow.com/questions/40747655/scala-slick-3-high-query-latency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!