New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Huge performance degradation after upgrade to Postgres 0.8.4 #477
Comments
We have seen a similar issue at pgjdbc/r2dbc-postgresql#334 with similar dependency arrangements. Right now, it seems tricky to trace down the issue. I'd suggest building a minimal reproducer that just uses R2DBC SPI and then incrementally adding dependencies/components to find out how we can reproduce the issue. |
I have the exact same thing. I noticed that the degradation of performance occurred when moving :
I have overrided the version r2dbc-postgres to 0.8.2.RELEASE in each configuration so it always this one. So it's not because of r2dbc-postgres. |
Okay, after hours of adding/removing dependencies & tweaking configuration I managed to find what actually creates this mess: r2dbc-pool. With r2dbc-pool enabled, my lowest query time is 3ms with average 41 et max 89. Without r2dbc-pool, it becomes 1.4ms / 2.7ms / 7.2ms I'll continue more investigation to confirm this behavior on a r2dbc app without spring (just to make sure this issue has nothing to do with spring-data-r2dbc) and continue on @mp911de link (pgjdbc/r2dbc-postgresql#334) or raise a new one in the r2dbc-pool project. |
@cambierr I use r2dbc pool too. I will try to remove It to see if something change. On my side the issue occurs when I switch r2dbc-postgres from 0.8.3 to 0.8.4. |
@cambierr yes I am using using it. But it's the same code and same configuration on my side before updating spring-boot. |
@cambierr I have try on my reproducer project (an api with 1 insertion), and using
|
@jroucou I was also using r2dbc-pool before and after the upgrade, and it's only after the upgrade that I have issues. Moreover, after the upgrade, without changing anything but removing r2dbc-pool, I get back the original performances despite a new connection having to be created for each request. @deblockt regarding your tests, I see the exact same thing: before upgrading to boot 2.3.x, performance are fine both with and without r2dbc-pool. But as soon as I upgrade, performances get crappy. I also was able to see the same thing on a very simple project with only r2dbc-pool & r2dbc-postgres so this is definitely not related to spring or sleuth tracing overhead. One thing I noticed through TCP tracing is this: I could be wrong but my understanding of this trace is that each time r2dbc sends a Parse command, Postgres takes tens of millis to reply which is where 95% of the time is wasted. This only happen when using r2dbc-pool and was able to reproduce this behavior ~ 90% of the time (the 10 other % it works with almost normal performances) and I tested the exact same query (both through native sql using jdbc driver, through jpa, and using a naked psql session) and wasn't able to reproduce, so this clearly seems to be something wrong with r2dbc-pool. @mp911de knowing you're one of the early authors of the r2dbc project, would you have any advice on where to start to help diagnose this ? |
by the way, we should probably move this to https://github.com/r2dbc/r2dbc-pool at this point. Not familiar enough with github issue tracker to know if there is a way to move/duplicate this issue there ? |
Parse frames are used to prepare a parameterized SQL statement. Once a statement is prepared, it is expected to be executed only by submitting the statement name and bind parameters. The driver caches prepared statements using the actual SQL query and type OIDs. That being said, running a statement twice that uses the same parameter types should result in a single parse and two execute frames. Note that prepared statement caching is connection-local. Using a fresh connection (i.e. not using Enabling debug logging gives you a lot of insight. When the pool reports |
Until we've sorted where the issue comes from, let's stick with this ticket. |
Ok, I may have found something that would mean it's not actually linked to r2dbc-pool: I wrote a very simple
I'd expect this to have the best performances for a simple use case since we keep a connection open but instead... i have exactly one quick transaction, followed by one slow, then one quick, then.... your got it. I'll attach a pcap with 4 calls in this order: slow, fast, slow, fast: I'll continue looking into this... |
Looking at wireshark, the only difference betwwen the "fast" and the "slow" flows seems to be that in the fast flow, r2dbc is sending:
while in the "slow" flow:
Don't know if this can help in any way but... well, I'll continue trying to understand what causes this |
Not really sure about fast/slow flows since the difference seems to be 5ms (or are the values above 0.2ms, 0.45ms)? However, the numbers are all pretty close. |
yep, in the "fast" (a.k.a "normal") flow, times are 0.2ms to 0.45ms while in the "slow" flow, the time is 40ms |
That's interesting. Do you have a simple reproducer for the two cases? |
I had a look at the capture provided by @cambierr. What's interesting is that that the |
I'll try to build the simplest reproducer I can. Meanwhile, using a single persistent connection, I can see that exactly one request every two is slow... this is... wtf. Will keep digging into this through the smallest app possible (will also try with another postgres version, just in case) |
FTR, tried Postgres versions 11 and 13 |
Here is the simplest reproducer I could come up with: https://gist.github.com/cambierr/910c92e48de9c089831e4fcd0e5967ed |
Thanks a lot, will have a look. |
I wasn't able to reproduce the issue. I'm using the exact same dependencies, I attached my log output to https://pastebin.com/EyhnHdnE (I even incremented the number of iterations to increase the likelihood of reproducing the issue). I'm running the test on a Mac using nio. Switching to kqueue (adding |
Can you confirm the boot version you're using ? I'm on |
I'm not using Spring Boot at all (as per the reproducer that consists of Spring Data R2DBC and the Postgres driver only) |
my bad, you're right... I'll check with other configurations of netty & postgres |
Well, just tested again with
which gives the "best" performances so there is something wrong but I have a really hard time finding out why haha |
OK, finally found out what has an impact:
gives a normal (good) response time, while
(as well as 0.8.5.RELEASE) gives a 40ms penalty. Time to track the issue at postgres side ? |
Yes. Closing this ticket in favor of |
@mp911de sure, It'll be a pleasure to help fixing this thing haha |
Hi,
After upgrading from boot
2.2.x
to2.3.x
we observed database access time exploding from an average 1.3 ms for afind by id
to about 45 ms for the exact same query.Here are the more precise chinks of information I can get for now:
To me, the interesting part is
that seems to show that the issue would be on the communication with the DB, taking most of the time but
2.3.x
version is impactedAt this time, I have to admit that I don't know how to go deeper in the analysis... feel free to suggest any "next step" you think may be worth a try: this is impacting several of our platforms since the overall API responsiveness has peaked up to 5* the average time.
Thank you guys
The text was updated successfully, but these errors were encountered: