0

I have built an embedded web server by extending NanoHTTPD (1.25). It is used for Firefox browser to show its content within the same machine. (SuSE 11)

Since the Firefox needs to show changing content within a very short duration (0.2 sec refreshment), it keeps polling the JSON URLs very quickly.

setInterval(function() {
    $.getJSON("content.json", function(d) {
...
        $('#content_div').html(d);
    })
    .error(function() {
        $('#content_div').html("");
    });
}, 200);

As a result, it creates a lot of unused connections and sometimes cannot get any response from my web server.

netstat -ap |grep "localhost:80" |wc -l
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
2212

Why are there so many TIME_WAIT connections? How can I make my web server healthy and ensure response from my web server?

Stanley Stein
  • 397
  • 1
  • 3
  • 17

1 Answers1

1

There are so many waits because your client is making more requests than your server can handle.

Try to reduce the refresh duration, until the server remains stable and you have found the capacity.

It might a good idea to performance test your server with jmeter or something, so you can determine server throughput and then make better decision about client configuration.

CharlieS
  • 1,432
  • 1
  • 9
  • 10
  • as mentioned, both client and server are on the same machine. It is one-to-one only. As the content keeps changing within msec, it is necessary to have such refresh duration. Previously I compared the performance between setInterval and setTimeout. setInterval can achieve my requirement. Could I make SuSE remove failed connections? – Stanley Stein Oct 30 '14 at 07:08
  • it is irrelevant whether they are localhost or another server. What is one-to-one? No idea if SuSE can do it, but that would be masking the issue, not fixing it. You could try reducing the timeout, so you get the connection free faster. – CharlieS Oct 30 '14 at 23:21
  • Someone suggested enforcing /proc/sys/net/ipv4/tcp_tw_recycle and /proc/sys/net/ipv4/tcp_tw_reuse to be one. I tried this and the result of netstat -ap |grep "localhost:80" |wc -l becomes less than 100. But I don't know whether this system changing way is proper and reliable. – Stanley Stein Dec 04 '14 at 06:06