node.js - connect EADDRNOTAVAIL in nodejs under high load - how to faster free or reuse TCP ports? -


I have a small Wiki web application that is based on Express-Framework, which uses elastic search because it backs up -end is. For each request it basically only goes to elastic search db, retrieve the object and it is provided by the handlers template engine. The communication with elastic search is over http

It works great till I have only one node-js example running, after updating my code to use the cluster (As I have begun to face the following error: Connect EADDRNOTAVAIL

This error appears when I have 3 more Python scripts running continuously on my server Retrieves some URL from With the script, I can retrieve more than 4,000 pages and more script running it is between 30,000 and 37,000 pages, running only 2 or 1 script, I have 310,000 pages and 160,000 pages respectively.

I have found it and tried to change http.globalAgent.maxSockets , but it has no effect.

This is part of the code that listens for the URL Receives data from elastic search

  app.get ( '/ wiki /: contentId', (req, res) - & gt; http (ElasticSearchUrl (req.params.contentId), (Inrris) - & gt; If (INRIS.States Code! = 200) res.send (innerRes.statusCode) insideROZ.Resume () and Body = '' innerRes.on ('data', (body chuck) -> body + = body chain) Innars.one ('end', () - & gt; res.render ('page', {'title': req.params.contentId, 'content': JSON.parse (body) ._ source HTML})) ) .on ('error', (e) - & gt; console.log ('goto error:' + e.message) # Error reported here))  

< Strong> Update:

After seeing more about this, I understand that the problem is the root cause. I command netstat-a | | Grep -e tcp -e udp | Wc -l Many times during my trial, to see how many ports are used, as per the post. I could see that when I received the EADDRNOTAVAIL error, 56677 ports were used (usually ~ 180 instead of)

In addition, when only 2 simultaneous scripts are used, The number of ports used is approximately 40,000 (+/- 2,000), that means ~ 20,000 ports per script (which is when the node-js clears the old port before it is made new) and 3 scripts For 56677 ports (~ 60,000). It explains why 3 scripts have failed to make a request for the data, but not with 2.

So now my question is changed - how can I do node-js to quickly release ports or can reuse the same port time (better solution)

Thanks

For now, my solution agent Setting the option of my request to false

The connection with an agent exits from the pool, the default request for connection: stop The

As a result, the number of ports used in my number is not more than 26,000 - it is still not a great solution, and even more because I do not understand why the ports work Does not, but it now resolves the problem.


Comments