限制服务器端的并发连接数?

时间:2022-10-02 20:48:28

I'm writing my own webserver and I don't yet handle concurrent connections properly. I get massive page loading lag due to inappropriately handling concurrent connections (I respond to SYN, but I lose the GET packet somehow. The browser retries after a while, but it takes 3 seconds!) I'm trying to figure out if there's a way to instruct the browser to stop loading things concurrently, because debugging this is taking a long time. The webserver is very stripped down, is not going to be public and is not the main purpose of this application, which is why I'm willing to cut corners in this fashion.

我正在编写自己的网络服务器,但我还没有正确处理并发连接。由于不恰当地处理并发连接,我得到了大量的页面加载滞后(我响应SYN,但我以某种方式丢失了GET数据包。浏览器在一段时间后重试,但需要3秒!)我试图找出是否存在指示浏览器同时停止加载的方法,因为调试这需要很长时间。网络服务器非常简单,不会公开,也不是这个应用程序的主要目的,这就是我愿意以这种方式偷工减料的原因。

It'd be nice to just limit the concurrent connections to 1, because modifying that parameter using a registry hack for IE and using about:config for Firefox both make things work perfectly.

将并发连接限制为1会很好,因为使用IE的注册表黑客修改该参数并使用about:config for Firefox可以使事情完美地运行。

Any other workaround ideas would be useful, too. A couple I can think of:

任何其他解决方法的想法也会很有用。我能想到的一对夫妇:

1 - Instruct the browser to cache everything with no expiration so the slow loads (.js, .css and image files) happen only once. I can append a checksum to the end of the file (img src="/img/blah.png?12345678") to make sure if I update the file, it's reloaded properly.

1 - 指示浏览器缓存所有没有过期的内容,以便缓慢加载(.js,.css和图像文件)只发生一次。我可以在文件的末尾附加一个校验和(img src =“/ img / blah.png?12345678”)以确保我是否更新了文件,它已正确重新加载。

2 - Add the .js and .css to load inline with the .html files - but this still doesn't fix the image issue, and is just plain ugly anyway.

2 - 添加.js和.css以使用.html文件加载内联 - 但这仍然无法解决图像问题,并且无论如何都是简单的丑陋。

2 个解决方案

#1


I don't believe it's possible to tell a browser like Firefox to not load concurrently, at least not for your users via some http header or something.

我不相信可以告诉像Firefox这样的浏览器不能同时加载,至少不能通过某些http标头或其他东西为你的用户加载。

#2


So I never found a way to do this.

所以我从来没有找到办法做到这一点。

My underlying issue was too many requests were coming in and overflowing my limited receive buffers in emac ram. Overflowing receive buffers = discarded packets. The resolution was to combine all .js and all .css files into 1 .js and 1 .css file in order to get my requests down. I set all image, js and css pages to have a year's expiration. The html pages are set to expire immediately. I wrote a perl script to append md5 checksums to files so changed files are refetched. Works great now. Pages load instantly after the first load caches everything.

我的根本问题是太多请求进入并且在emac ram中溢出了我有限的接收缓冲区。溢出的接收缓冲区=丢弃的数据包。解决方案是将所有.js和所有.css文件合并为1个.js和1个.css文件,以便减少我的请求。我将所有图像,js和css页面设置为一年到期。 html页面设置为立即过期。我编写了一个perl脚本来将md5校验和附加到文件中,以便重新获取更改的文件。现在很棒。在第一次加载缓存所有内容后,页面立即加载。

#1


I don't believe it's possible to tell a browser like Firefox to not load concurrently, at least not for your users via some http header or something.

我不相信可以告诉像Firefox这样的浏览器不能同时加载,至少不能通过某些http标头或其他东西为你的用户加载。

#2


So I never found a way to do this.

所以我从来没有找到办法做到这一点。

My underlying issue was too many requests were coming in and overflowing my limited receive buffers in emac ram. Overflowing receive buffers = discarded packets. The resolution was to combine all .js and all .css files into 1 .js and 1 .css file in order to get my requests down. I set all image, js and css pages to have a year's expiration. The html pages are set to expire immediately. I wrote a perl script to append md5 checksums to files so changed files are refetched. Works great now. Pages load instantly after the first load caches everything.

我的根本问题是太多请求进入并且在emac ram中溢出了我有限的接收缓冲区。溢出的接收缓冲区=丢弃的数据包。解决方案是将所有.js和所有.css文件合并为1个.js和1个.css文件,以便减少我的请求。我将所有图像,js和css页面设置为一年到期。 html页面设置为立即过期。我编写了一个perl脚本来将md5校验和附加到文件中,以便重新获取更改的文件。现在很棒。在第一次加载缓存所有内容后,页面立即加载。