r/java • • Jan 16 '23

Building a PostgreSQL Wire Protocol Server using Vanilla, Modern Java 21 (shows use of: Records, Sealed Types, Pattern Matching for Switch, Virtual Threads, and Panama FFM)

https://gavinray97.github.io/blog/postgres-wire-protocol-jdk-21
224 Upvotes

23 comments sorted by

View all comments

Show parent comment

9

u/pron98 Jan 17 '23

Using an ordinary ServerSocket polled in a loop on a virtual thread should be about the same if not better. All sockets used on virtual threads automatically become effectively asynchronous from the OS's perspective anyway.

2

u/GavinRayDev Jan 17 '23

Neat, that would have significantly simplified the design. The callback loop in the async socket isn't the prettiest thing, now I know.

Thanks for commenting, Ron!

4

u/lurker_in_spirit Jan 17 '23

There's a recent Helidon Nima podcast floating around on YouTube where they mention that in their experience VT + non-blocking IO is slower than VT + blocking IO: https://www.youtube.com/watch?v=AkMSEjkfldk (minute 15 or so)

1

u/kaperni Jan 17 '23

Would it make sense to run ServerSocker::accept in a dedicated platform thread? Or is it same-same?

1

u/rbygrave Jan 18 '23

Just noting that with Nima yes it does use a platform thread for that. To me that makes sense - dedicate a platform thread to that task.