PostgreSQL async lib with ratpack

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

PostgreSQL async lib with ratpack

Massimo Lusetti
Hi,
  Does anyone have experience with alaisi/postgres-async-driver within ratpack?
Reply | Threaded
Open this post in threaded view
|

Re: PostgreSQL async lib with ratpack

danveloper
Administrator
Hi Massimo! Thanks for the question!

I pinged the community channel, but it seems like there's not a lot of activity on this subject. That said, Ratpack gives you the ability to make any third-party library async through its Promise API. That way, you can use the regular blocking APIs, but wrap them in a Blocking.get { ... } call.

Something worth looking at is the example-books project. For example: https://github.com/ratpack/example-books/blob/latest/src/main/groovy/ratpack/example/books/BookDbCommands.groovy#L35

Hope this helps!
Reply | Threaded
Open this post in threaded view
|

Re: PostgreSQL async lib with ratpack

Luke Daley
Administrator
In reply to this post by Massimo Lusetti
Hi Massimo,

I haven't used the pg async driver, but I took a quick look at its docs. It would be easy to integrate Ratpack's promises and executions here…

Db db = ...;
Promise.of(d -> db.query("select 'Hello world!' as message", d::success, d::error));
Reply | Threaded
Open this post in threaded view
|

Re: PostgreSQL async lib with ratpack

Massimo Lusetti
Do you believe there will be a potential gain using postgresql-async with the async model of Ratpack versus (rather then) Ratpack blocking support with a standard JDBC driver ?
rus
Reply | Threaded
Open this post in threaded view
|

Re: PostgreSQL async lib with ratpack

rus
I would say yes but I can't back that up with any figures.  Even more so if the driver could share the same event loop group as Ratpack.  I think using the blocking thread pool will only scale so far.  But it depends on your load and how long the blocks are.  I will defo get around to measuring this in the near future.

Also, looking at the code it seems they are returning Observables which integrate even nicer with Ratpack!
Reply | Threaded
Open this post in threaded view
|

Re: PostgreSQL async lib with ratpack

Luke Daley
Administrator

One thing to keep in mind here is that you are giving up any kind of JDBC tooling, like Hibernate, JOOq, JDBI, Spring Transactions etc. 

 It’s almost certain that you’ll get better throughput using postgres-async, but there’s a big cost.
Reply | Threaded
Open this post in threaded view
|

Re: PostgreSQL async lib with ratpack

Massimo Lusetti
I agree with you Luke.

I didn't consider that cost to be too much cause the app is very small, just 5 APIs all stateless (using JWT token auth).

Is used by other services to collect data and serve reporting based on that data.

Anyway I'll keep that in mind.

Thank you very much, really appreciated.