问题
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