Description
Description
Our service needs to send HTTP requests to a lot of (e.g. 70k) different host names. What's special about those hostnames is that they resolve to only
roughly 60 IPs, i.e., a lot of the different host names resolve to the same IPs.
If we use a plain HttpClient and send requests with host names in URL, it will open a connection for each host name (if I read source code correctly), resulting in 70k outgoing connections and therefore high SNAT usage.
Is there any way to reduce outgoing connections count in this scenario? For example, is there any way to instruct the client to reuse a connection for requests to the same IP (as usual, new connections should be made when it cannot keep up with request volume)?
We are on .Net Core 8
One idea that we come up with is our code can keep a dictionary from IPAddress to HttpClient. Our code will resolve DNS ourselves and get the HttpClient from the dictionary (create new one if it does not exist). Then, when sending the request, we use IP instead of host name in the URL, so that HttpClient would not open a new connection each time (since all requests sent on this HttpClient has the same IP as hostname). One challenge is that we need to override SSL cert validation maybe through ServerCertificateCustomValidationCallback
(since the remote cert does not have IP as subject name), which sounds quite dangerous.