开发者

30 seconds lag on a java socket?

开发者 https://www.devze.com 2023-04-12 04:35 出处:网络
In my TCP server, which is written in Java, sometimes a random client has a 5 to 60 seconds lag. The server has plenty of free memory and cpu left when this happens. The socket is already opened when

In my TCP server, which is written in Java, sometimes a random client has a 5 to 60 seconds lag. The server has plenty of free memory and cpu left when this happens. The socket is already opened when this happens.

This happens randomly to certain clients. The java p开发者_JAVA技巧rocess continues as if the data was sent, but the server doesn't send / receive the data physically.

I have disabled Nagle but i don't see how Nagle could cause such a latency.

I am not very specific because I'm confused about this. What could theoretically cause this ?

Another thing: When one of the client has such a bad lag, the other clients are running fine. And they are all on the same ethernet interface of the server. I can't explain such a thing.


What could theoretically cause this ?

Theoretical causes include:

  • A bug in the client code. It is hard to say what it would be without looking at the code, but I'd suspect a threading, notification or synchronization issue.

  • A bug in the server code. It is hard to say what it would be ... as above.

  • A JVM bug. Unlikely.

  • An operating system bug. Unlikely.

  • A networking issue. Maybe there is a flakey or misconfigured switch / gateway / firewall between the client and server. Maybe there is an issue with networking and virtualization.

I think you need to use something like WireShark to see if you can see when the packets are going over the wire, etcetera. That should help to narrow it down a bit.


This happens randomly to certain clients. The java process continues as if the data was sent, but the server doesn't send / receive the data physically.

There are some further questions to ask yourself:

  • It only happens to "certain" clients. So what is different about them?

  • The Java process continues "as if" the data was sent. So why does it think that the data has been sent?

  • The server doesn't send / receive the data "physically". What do you mean by "physically"? Why do you know / believe this to be the case? Is the server thread blocked in a read? Or is it blocked in listen? Has the data actually arrived at the server machine at all?


Forgetting to flush the OutputStream to the client could be one cause. Java or the underlying OS may wait for more data to fill a packet.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号