I have a networking problem that is more or less haunting me.
I have reduced the problem down to only a… port number!
Let me begin with the setup:
[x] I have a server, with 1gbit ethernet (Linux 2.6.18)
[x] I have a home connection with 1mbit upload (~100KB/sec upload)
[x] I send 4MB (random bytes) from the client to the server, and the server simply accepts,reads,discards the data.
When the ServerSocket is listing on port 2048, everything is well.
The (manually) interleaved STDOUT from the server and client looks (a bit) like this:
CLIENT: 95KB/sec
SERVER: 93KB/sec
CLIENT: 92KB/sec
SERVER: 94KB/sec
CLIENT: 94KB/sec
SERVER: 97KB/sec
CLIENT: 96KB/sec
SERVER: 92KB/sec
CLIENT: 93KB/sec
SERVER: 92KB/sec
...
When the ServerSocket is listing on port 80, everything is b0rked.
The (manually) interleaved STDOUT from the server and client looks (a bit) like this:
CLIENT: 500KB/sec (impossible)
SERVER: 37KB/sec
CLIENT: 37KB/sec
SERVER: 4KB/sec
CLIENT: 19KB/sec
SERVER: 8KB/sec
CLIENT: 0KB/sec
SERVER: 3KB/sec
CLIENT: 72KB/sec
SERVER: 103KB/sec
...
It is literally the same code, but when I change the port, everything goes belly up. The client thinks it sent 500KB in the first second, which is impossible, and after that, the connection is flaky at best, most of the time I/O over port 80 is 4-5x slower than port 2048, often gaps in traffic for 3 seconds, sometimes even dropping the connection.
I looked at the (iptables) firewall, and all is properly setup:
.........
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:110
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:443
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2048
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
Naturally I cannot host the service on port 2048, as it is a publicly available HTTP server.
Note that the test-application is NOT a HTTP server, and so simple it can be considered ‘bug-free’ …
try
{
ServerSocket ss = new ServerSocket(80 <---> 2048, 50, InetAddress.getByName("123.456.789.012"));
while (true)
{
final Socket s = ss.accept();
new Thread(new Runnable()
{
@Override
public void run()
{
try
{
InputStream in = new BufferedInputStream(s.getInputStream());
OutputStream out = s.getOutputStream();
byte[] buf = new byte[8 * 1024];
long last = System.currentTimeMillis();
int accum = 0;
while (true)
{
long now = System.currentTimeMillis();
int got = in.read(buf);
if (got == -1)
throw new EOFException();
accum += got;
if (now - last > 1000L)
{
System.out.println("accum=" + (accum / 1024) + "K");
last += 1000L;
accum = 0;
}
}
}
catch (IOException exc)
{
exc.printStackTrace();
}
}
}).start();
}
}
catch (IOException exc)
{
exc.printStackTrace();
}
Socket.sendBufferSize / Socket.recvBufferSize are 8K.
I’m out of ideas… :persecutioncomplex: I can’t get the TCP connection on port 80 stable and reliable to save my life! You can imagine this is critical to any webapp…
Does somebody have an idea what can cause this?