question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can we close gap on client performance vs blocking sockets?

See original GitHub issue

pgjdbc-ng uses Netty in a client environment and when we compare performance with that of pgjdbc it can be any where from 100% slower (on localhost) to 15% slower (on any remote host).

After extensive investigation and many failed implementations, we’re at a dead end with making it any faster using the currently provided Netty facilities. We desperately want to keep Netty because it makes the implementation drastically simpler but at some point the performance gap needs to be closed.

The mainline driver uses non-blocking sockets and “no threads” which makes it limiting and unable to implement some features of the JDBC specification correctly. Clearly we need to retain the asynchronous nature of the driver and realize that may impose a performance cost above an unthreaded non-blocking implementation; but we need it to be much closer than it is.

FYI, I tried OioSocketChannel and OioEventLoopGroup because the thread-per-connection model seemed promising; realizing they are deprecated. Unfortunately they appear broken in Netty 4. Due to writes being directed to the event loop thread, and the fact that it uses blocking reads with a periodic timeout, the writes are starved until the read time’s out and the event loop thread can process them. I hacked a version that allow writes from any thread but it provides only a small performance improvement (and is a dubious solution given Netty’s requirements).

So, the basic question is… what are we doing wrong and how can we solve this problem? After reading everything available here, on netty.io, on stackoverflow and pretty much any related hit on Google… this is my last hope.

Minimal yet complete reproducer code (or URL to code)

pgjdbc-ng

Netty version

4.1.42

JVM version (e.g. java -version)

8, 9, 10, 11, 13

OS version (e.g. uname -a)

Darwin <hostname>.local 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
kdubbcommented, Oct 2, 2019

I’ve created a simple test project that displays the same issue. https://github.com/impossibl/netty-test

TestServer is a simple server that responds to requests by sending a requested amount of data back to the client with an id. TestClient uses Netty to generate & send requests and wait for responses like pgjdbc-ng does. TestBlockingClient uses a Socket to send the request then does blocking reads to read the response, like pgjdbc does.

TestClient: ~5.8s TestBlockingClient: ~3.7s

0reactions
kdubbcommented, Mar 18, 2021

@Liyixin95 Apparently I missed this comment many months ago… Yes TestClient is synchronous, like TestBlockingClient is, to show that merely switching between Netty and a blocking socket has a performance penalty.

The actual driver implementation pipelines request whenever possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java sockets I/O: blocking, non-blocking and asynchronous
Blocking NIO echo server​​ accept method blocks and returns a SocketChannel object when a connection is accepted. The ServerSocket. read method  ...
Read more >
Blocking, nonblocking, and asynchronous socket calls - IBM
A socket is in blocking mode when an I/O call waits for an event to complete. If the blocking mode is set for...
Read more >
Non-blocking TCP socket and flushing right after send?
All it does is gratuitously close a working socket. Re 'another thing', you are mistaken. select() accepts a timeout in the form of...
Read more >
6.5. Blocking vs. non-blocking sockets
By default, TCP sockets are in "blocking" mode. For example, when you call recv() to read from a stream, control isn't returned to...
Read more >
Head-of-Line Blocking in QUIC and HTTP/3: The Details
One customer buying a lot of items can end up delaying everyone behind them, ... Figure 4: server HTTP/1.1 vs HTTP/2 response for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found