Connecting EADDRNOTAVAIL to nodejs under heavy load - how to quickly release or reuse TCP ports?

I have a small wiki-like web application based on an express structure that uses elastic search as a source. For each request, it mainly enters only a flexible search database, retrieves an object and returns it using the steering wheel template mechanism. Link to elastic search via HTTP

This works fine as long as I only have one instance of node-js. After I updated my code to use the cluster (as described in nodejs-documentation , I began to encounter the following error: connect EADDRNOTAVAIL

This error appears when I have 3 or more python scripts that constantly retrieve the url from my server. With 3 scripts, I can get ~ 45,000 pages with 4 or more scripts running from 30,000 to 37,000 pages. Running only 2 or 1 scripts, I stopped them after half an hour, when they got 310,000 pages and 160,000 pages, respectively.

I found this similar question and tried to change http.globalAgent.maxSockets, but it had no effect.

This is part of the code that listens for URLs and retrieves data from elastic search.

app.get('/wiki/:contentId', (req, res) ->
    http.get(elasticSearchUrl(req.params.contentId), (innerRes) ->
        if (innerRes.statusCode != 200)
            res.send(innerRes.statusCode)
            innerRes.resume()
        else
            body = ''
            innerRes.on('data', (bodyChunk) ->
                body += bodyChunk
            )
            innerRes.on('end', () ->
                res.render('page', {'title': req.params.contentId, 'content': JSON.parse(body)._source.html})
            )
    ).on('error', (e) ->
        console.log('Got error: ' + e.message)  # the error is reported here
    )
)

UPDATE:

, , . netstat -an | grep -e tcp -e udp | wc -l , , , Linux: EADDRNOTAVAIL ( ). , , EADDRNOTAVAIL, 56677 ( ~ 180 )

, 40 000 (+/- 2000), , script ~ 20 000 ( , node -js ), 3- , , 56677 (~ 60 000). , 3 , , 2.

, : node -js ( )

+3
1

agent false, ,

, : .

26 000. , , , , .

+2

All Articles