How do I code my ASP.NET page to parallelize downloads across hostnames?

淺唱寂寞╮ 提交于 2019-12-04 18:12:33

How about this:

1) Code all you links to static resources as, for example, [HOSTNAME]/Images/myimage.jpg
2) Create either an HTTP module or a base class for your pages which implements a response filter.
3) That filter should use a regex to find all instances of [HOSTNAME] and replace with an alternative.

The filter could include logic to check if the current hostname is localhost and then just insert localhost as the hostname. To randomise the distribution of the other hostnames whilst maintaining cacheability you could do the following:

1) Have a list of alternative hostnames
2) You'd need a more complex regex/syntax to find [HOSTNAME] and also locate the file name as well
3) Create a hash of the full path of the file. This could be really simple, like counting the ascii codes of each character in the path and finding the module # of hostnames
4) Use the hash value to pick the hostname from the list.

With this, you should get a spread of requests across each hostname + the same resource will always be served from the same host so it can be cached.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!