Code Monkey home page Code Monkey logo

Comments (4)

pluma avatar pluma commented on June 14, 2024 1

Instead of passing in the agent itself, just pass in agentOptions: {maxSockets: 5}. The HTTP Agent provided by node.js does not use keep-alive by default, which may explain why you're running out of sockets. The agent option is only really useful if you want to provide your own agent implementation (which is not normally necessary).

from arangojs.

samuelgoldenbaum avatar samuelgoldenbaum commented on June 14, 2024

Thanks Alan. I did as suggested, below is the script:

var moment = require('moment');

var db = require('arangojs')({
    url: 'http://localhost:8000',
    agentOptions: {maxSockets: 5},
    databaseName: 'loadtest'
});

var recs = 1000000,
    startDoc = 10122492 + 1,
    currentDoc = 0,
    type,
    start = new Date(),
    collection;

function save() {
    type = Math.round(Math.random() * 10) + 1;
    collection
        .save({
            'id': startDoc + currentDoc,
            'type': type,
            'connections': [
                Math.round(Math.random() * 100) + 1,
                Math.round(Math.random() * 100) + 1,
                Math.round(Math.random() * 100) + 1,
                Math.round(Math.random() * 100) + 1
            ],
            'positions': [
                {
                    'time': new Date(),
                    'type': type,
                    'position': {'lat': -122.423246, 'lng': 37.779388, 'radius': 250}
                }
            ]
        },
        function (err, result) {
            if (err || result.error) {
                return console.error(err);
            }
            console.log('inserted ' + currentDoc + ' of ' + recs);
            if (currentDoc === recs) {
                return console.log('inserted ' + currentDoc + ' in ' + moment.utc(moment(new Date(), "DD/MM/YYYY HH:mm:ss").diff(moment(start, "DD/MM/YYYY HH:mm:ss"))).format("HH:mm:ss"));
            }
            currentDoc++;
            save();
        });
}

db.collection('load', function (err, result) {
    if (err) {
        console.error(err);
        return;
    }
    collection = result;
    console.info('starting: ' + start);
    save();
});

after a few seconds I get:

{ [Error: connect ETIMEDOUT]
  code: 'ETIMEDOUT',
  errno: 'ETIMEDOUT',
  syscall: 'connect',
  request: 
   { domain: null,
     _events: { response: [Object], error: [Function] },
     _maxListeners: 10,
     output: [],
     outputEncodings: [],
     writable: true,
     _last: false,
     chunkedEncoding: false,
     shouldKeepAlive: true,
     useChunkedEncodingByDefault: true,
     sendDate: false,
     _headerSent: true,
     _header: 'POST /_db/loadtest/_api/document/?collection=load HTTP/1.1\r\ncontent-type: application/json\r\ncontent-length: 170\r\nx-arango-version: 20300\r\nHost: localhost:8000\r\nConnection: keep-alive\r\n\r\n',
     _hasBody: true,
     _trailer: '',
     finished: true,
     _hangupClose: false,
     socket: 
      { _connecting: false,
        _handle: null,
        _readableState: [Object],
        readable: false,
        domain: null,
        _events: [Object],
        _maxListeners: 10,
        _writableState: [Object],
        writable: false,
        allowHalfOpen: false,
        onend: [Function: socketOnEnd],
        destroyed: true,
        bytesRead: 0,
        _bytesDispatched: 0,
        _pendingData: 'POST /_db/loadtest/_api/document/?collection=load HTTP/1.1\r\ncontent-type: application/json\r\ncontent-length: 170\r\nx-arango-version: 20300\r\nHost: localhost:8000\r\nConnection: keep-alive\r\n\r\n{"id":10136661,"type":6,"connections":[11,38,2,42],"positions":[{"time":"2015-06-21T15:33:36.022Z","type":6,"position":{"lat":-122.423246,"lng":37.779388,"radius":250}}]}',
        _pendingEncoding: 'utf8',
        parser: [Object],
        _httpMessage: [Circular],
        ondata: [Function: socketOnData],
        _idleNext: null,
        _idlePrev: null,
        _idleTimeout: -1 },
     connection: 
      { _connecting: false,
        _handle: null,
        _readableState: [Object],
        readable: false,
        domain: null,
        _events: [Object],
        _maxListeners: 10,
        _writableState: [Object],
        writable: false,
        allowHalfOpen: false,
        onend: [Function: socketOnEnd],
        destroyed: true,
        bytesRead: 0,
        _bytesDispatched: 0,
        _pendingData: 'POST /_db/loadtest/_api/document/?collection=load HTTP/1.1\r\ncontent-type: application/json\r\ncontent-length: 170\r\nx-arango-version: 20300\r\nHost: localhost:8000\r\nConnection: keep-alive\r\n\r\n{"id":10136661,"type":6,"connections":[11,38,2,42],"positions":[{"time":"2015-06-21T15:33:36.022Z","type":6,"position":{"lat":-122.423246,"lng":37.779388,"radius":250}}]}',
        _pendingEncoding: 'utf8',
        parser: [Object],
        _httpMessage: [Circular],
        ondata: [Function: socketOnData],
        _idleNext: null,
        _idlePrev: null,
        _idleTimeout: -1 },
     agent: 
      { domain: null,
        _events: [Object],
        _maxListeners: 10,
        options: [Object],
        requests: {},
        sockets: [Object],
        maxSockets: 5,
        createConnection: [Function] },
     socketPath: undefined,
     method: 'POST',
     path: '/_db/loadtest/_api/document/?collection=load',
     _headers: 
      { 'content-type': 'application/json',
        'content-length': 170,
        'x-arango-version': 20300,
        host: 'localhost:8000' },
     _headerNames: 
      { 'content-type': 'content-type',
        'content-length': 'content-length',
        'x-arango-version': 'x-arango-version',
        host: 'Host' },
     parser: 
      { _headers: [],
        _url: '',
        onHeaders: [Function: parserOnHeaders],
        onHeadersComplete: [Function: parserOnHeadersComplete],
        onBody: [Function: parserOnBody],
        onMessageComplete: [Function: parserOnMessageComplete],
        socket: [Object],
        incoming: null,
        maxHeaderPairs: 2000,
        onIncoming: [Function: parserOnIncomingClient] } } }

Process finished with exit code 0

This is only the case when wait for sync is set to false.

from arangojs.

pluma avatar pluma commented on June 14, 2024

The ETIMEDOUT confirms that the root issue is on the server and that the EADDRNOTAVAIL was just a symptom caused by using node's default behaviour. I'm closing this issue in favour of the arangodb issue. Thanks for bringing this to our attention.

from arangojs.

samuelgoldenbaum avatar samuelgoldenbaum commented on June 14, 2024

Cool, will keep track of the progress

from arangojs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.