Search code examples
javajavascriptjqueryfirefoxnanohttpd

Reduce unused firefox connection


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?


Solution

  • 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.