Fork me on GitHub
#sql
<
2017-05-18
>
plins03:05:02

hello everyone, i know jdbc is synchronous, but is anyone aware of somekind of thread pool which can be consumed by an async api? (a dedicated threadpool for database access)

tanzoniteblack17:05:10

plins: Which DB are you using?

plins17:05:08

atm mysql

tanzoniteblack17:05:35

if you’re really worried about the async bit, you can use https://github.com/alaisi/postgres.async with postgres. Don’t know of a good alternative with mysql

tanzoniteblack17:05:02

you can also work around this by adding some kind of intermediary function that runs the SQL query via a threadpool, which once the query completes puts it onto a core.async channel. However, when I’ve played with things like this in the past, I’ve found it to be way more of a headache then it was actually worth, based off of the performance changes

tanzoniteblack17:05:51

you’re generally better off spending the time to reduce the number of DB calls you’re making and the performance of those calls, and just let the JVM do it’s stuff with thread switching

tanzoniteblack17:05:07

obvious depends on your usecase and what’s causing you to want this

plins16:05:27

i was thinking about heading down the road of thread pool + core.async … im coming from nodejs development and now compojure supports async routes so i was wondering if it was possible/worth to wrap sync jdbc calls on a thread pool with an async interface, maybe using channels

plins16:05:52

im actually quite surprised that theres not a stable solution implemented

Shantanu Kumar17:05:55

@plins You can create a thread-pool (using Java interop) and submit JDBC jobs to it. Would that work for you?