0

I am facing application performance issue because of "An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full" error.

Basically application flow is 1.Application hits to web API and WebAPI hits to the database.

To resolve this issue,

  1. I have increased maxport upto 15000 - https://learn.microsoft.com/en-us/troubleshoot/windows-client/networking/connect-tcp-greater-than-5000-error-wsaenobufs-10055
  2. Verified all the connection closed at the application level. 3.I am using "Using" keyword in my application. 4.I have verified,there are so many connections are available with Time_wait state.

Please let me know if you have any other solution apart from this.

Code

public IHttpActionResult Products([FromBody] ProductRequest productRequest)
    {
        if (productRequest != null)
        {
            var request = Mapper.Map<SolrProductRequest>(productRequest);
            var response = _searchProxy.GetProducts(request);

            return Ok(response);
        }

        return BadRequest();
    }

public string Get(string relativeUrl, IEnumerable<KeyValuePair<string, string>> parameters)
    {
  

        var u = new UriBuilder(_serverUrl);
        u.Path += relativeUrl;
        var request = (HttpWebRequest)WebRequest.Create(u.Uri);
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        var qs = string.Join("&", parameters
            .Select(kv => string.Format("{0}={1}", HttpUtility.UrlEncode(kv.Key), HttpUtility.UrlEncode(kv.Value)))
            .ToArray());
        request.ContentLength = Encoding.UTF8.GetByteCount(qs);
        request.ProtocolVersion = HttpVersion.Version11;
        request.KeepAlive = true;
        try
        {
            using (var postParams = request.GetRequestStream())
            using (var sw = new StreamWriter(postParams))
                sw.Write(qs);
            using (var response = request.GetResponse())
            using (var responseStream = response.GetResponseStream())
            using (var sr = new StreamReader(responseStream, Encoding.UTF8, true))
            {
                var solrResult = sr.ReadToEnd();

                //if (CustomValues != null && CustomValues.Count > 0)
                //{
                //    PopulateCustomValues(solrResult);
                //}
                return solrResult;
            }
        }
        catch (WebException e)
        {
            throw new SolrConnectionException(e);
        }
    }

Thanks

  • You need to provide more information about the first application in which technology? Are both the application on same server? Where are you getting TIME_WAIT on 1st application or second application. – शेखर Nov 05 '20 at 16:08
  • There are few guideline when using http request. https://www.red-gate.com/simple-talk/dotnet/c-programming/working-with-the-httpclient-class/ – शेखर Nov 05 '20 at 16:13
  • Thank you so much Shekhar for your response. 1. Application technologies are .NET with Entity framework, Web API and SQL server. 2. No both are not into the same servers. Time_wait we are getting on second server where we have hosted the WEB.API. 3. To resolve this issue we are doing iis reset from both servers. – Rajesh Somvanshi Nov 06 '20 at 10:25
  • And you are using `httpclient` to call webapi? If yes try to use singlton design pattern. Here are few suggestion https://stackoverflow.com/questions/48778580/singleton-httpclient-vs-creating-new-httpclient-request. – शेखर Nov 06 '20 at 10:29
  • Thank you so much Shekhar for your response. Please see my code in the main Query. – Rajesh Somvanshi Nov 13 '20 at 08:33

0 Answers0