I'm writing a very simple socket server that acts ...
# announcements
a
I'm writing a very simple socket server that acts as an HTTP2 client and does some measurements on HTTP2 Server Push for some research as the existing codebase does not have support for a proper HTTP2 client. So I've got an HTTP2 client aspect and socket server aspect in my code. The server listens for some JSON to be sent, parses it, and sends it on a socket that the client is listening on in a coroutine. However the time between sending and receiving the data can be very inconsistent. Because the measurements have to be quite accurate and consistent, I need this to be consistent. (Let's ignore the other speed improvements that could be made for now.) The delay can be almost non existent (1ms or so), 500ms, or almost 2 seconds, see below for some simple logs. Below is also the unparsed JSON data that is sent (it is parsed to data classes and sent over the channel as a List), it is definitely not a large amount of data. What could be the reason for this inconsistency?
Copy code
[2019-03-11 16:13:33.075] [INFO] Sending items... 
[2019-03-11 16:13:35.746] [INFO] Items received...
Copy code
[{"segment": 1, "tile": -1, "quality": 0}, {"segment": 1, "tile": -2, "quality": 0}, {"segment": 1, "tile": -3, "quality": 0}, {"segment": 1, "tile": -4, "quality": 0}, {"segment": 1, "tile": -5, "quality": 0}, {"segment": 1, "tile": -6, "quality": 0}, {"segment": 1, "tile": -7, "quality": 0}, {"segment": 1, "tile": -8, "quality": 0}, {"segment": 1, "tile": -9, "quality": 0}, {"segment": 1, "tile": -10, "quality": 0}, {"segment": 1, "tile": -11, "quality": 0}, {"segment": 1, "tile": -12, "quality": 0}, {"segment": 1, "tile": -13, "quality": 0}, {"segment": 1, "tile": -14, "quality": 0}, {"segment": 1, "tile": -15, "quality": 0}, {"segment": 1, "tile": -16, "quality": 0}, {"segment": 1, "tile": -17, "quality": 0}, {"segment": 1, "tile": 1, "quality": 1}, {"segment": 1, "tile": 13, "quality": 1}, {"segment": 1, "tile": 10, "quality": 1}, {"segment": 1, "tile": 9, "quality": 1}, {"segment": 1, "tile": 6, "quality": 1}, {"segment": 1, "tile": 17, "quality": 1}, {"segment": 1, "tile": 14, "quality": 1}, {"segment": 1, "tile": 5, "quality": 1}, {"segment": 1, "tile": 2, "quality": 1}, {"segment": 1, "tile": 16, "quality": 1}, {"segment": 1, "tile": 15, "quality": 1}, {"segment": 1, "tile": 4, "quality": 1}, {"segment": 1, "tile": 3, "quality": 1}, {"segment": 1, "tile": 12, "quality": 1}, {"segment": 1, "tile": 11, "quality": 1}, {"segment": 1, "tile": 8, "quality": 1}, {"segment": 1, "tile": 7, "quality": 1}]
k
Can you try to create a minimal example? Does the http stuff matter? Does the deserializing json part matter? Does the size of the json matter? Cut out everything that doesn't matter.
d
Consider posting stuff like stacktraces and what not in a reply to your own thread
a
I might just open source it and post it along with a netcat cli example so you can test it. I'm just about to leave for a meeting elsewhere in the city. I'll try to continue there.
k
Well you probably need to do some work yourself to isolate the bug.
a
The code is very small and the HTTP2 doesn't matter.
d
Are the peers on the same host?
a
Well that shouldn't matter. The channel is the delaying factor it seems. It'll all be clear when I post it here. About to take off now. I'll try to post it asap when I get there.
I'll have to post it tomorrow or later tonight. I somehow didn't push the branch I created and I'm on a different laptop now. My apologies.
d
I don't think it's affecting us bud, post it when you want
k
If the http doesn't matter then cut it out and post that.
The
Client.watch
is where the items are received from the channel and they're sent from
Socket.handle
defined in
Server
.
Setting up a netcat command so it can be tested.
I've added the example data. You can use it with netcat:
netcat 127.0.0.1 9000 < example-data.json
It will throw a Connection refused, but that's not the problem. You should see that the time difference between "Sending items..." and "Items received..." is sometimes even 2 seconds.
Note that this project requires JDK 11 to build.
I've fixed the problem by wrapping the blocking calls for getInputStream and Jackson's readValue in
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
Thank you all regardless though!