Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How many concurrent queries per connection can arangodb execute? #379

Closed
p30arena opened this issue Jan 1, 2017 · 13 comments
Closed

How many concurrent queries per connection can arangodb execute? #379

p30arena opened this issue Jan 1, 2017 · 13 comments
Labels
Question Probably not a bug.

Comments

@p30arena
Copy link

p30arena commented Jan 1, 2017

Do I need to create multiple connections and do connection pooling?

@p30arena
Copy link
Author

p30arena commented Jan 1, 2017

Since it uses HTTP 1.1 so there must be 1 query at a time per connection

@p30arena
Copy link
Author

p30arena commented Jan 1, 2017

Connection.agentDefaults = {
maxSockets: 3,
keepAlive: true,
keepAliveMsecs: 1000
}

i found the above in the source code https://github.com/arangodb/arangojs/blob/5387a6e560418380a99fc6dc3c59b433b2570bdf/src/connection.js
is 3 enough?

@StarpTech
Copy link

StarpTech commented Jan 6, 2017

@p30arena you can also create multiple database instances. Or you create a simple pool.

     // create new connection
    db = new Arangojs.Database(arangoOptions)

    // fill pool
    pool[databaseName] = { connections: [], max: maxConnections }
    pool[databaseName].connections.push(db)
 

but I agree after some research its good practice to increase the maxSockets to a high number like 50.

@StarpTech
Copy link

StarpTech commented Jan 6, 2017

but +1 for native connection pool support.

Use case:

  • Multi tenancy environments
  • High traffic

@pluma
Copy link
Contributor

pluma commented Jan 16, 2017

arangojs automatically pools connections and uses keep-alive to reuse existing connections until they time out. There's no point in additionally maintaining a pool of arangojs database objects yourself.

For best results you should set maxSockets to the number of threads ArangoDB is using (this depends on your ArangoDB configuration). Keep in mind that when using multiple arangojs database objects they do not share the connection pool (because when creating a database object you can use different URLs so they might point to different ArangoDB instances) but collection objects will share the connection pool of the database object from which they were created.

@pluma pluma added the Question Probably not a bug. label Jan 16, 2017
@StarpTech
Copy link

StarpTech commented Jan 16, 2017

Hi @pluma when I change my database with useDb on every request how can I avoid to create a seperate connection? (e.g in multi tenancy env) When I look in the source code I cant find any implementation of connection pooling.

Arangojs() is equal with new Database the underlying connection can handle only requests to the same database. I think you talked about the nodejs request pool and I talk about a driver specific connection pool.

When I have 100 clients and 100 databases. I have to create 100 database, 100 connections.
There should be a way to reuse connections.

@pluma
Copy link
Contributor

pluma commented Jan 16, 2017

I'm talking about the connection pool we have implemented in arangojs: https://github.com/arangodb/arangojs/blob/v5.4.2/src/util/request.js -- the node.js request pool is actually not very good for arangojs's use case (i.e. keep-alive with many potentially very small requests).

There's currently no way to share connection pools between multiple database objects because database objects and connection objects are closely tied to support use cases where a specific database is exposed via a proxy (i.e. we can't just assume the database name will always be part of the URL).

If you see a way to refactor the connection object in a way that allows us to support a .database method analogous to the .collection method to create "clones" of the instance that point to different databases on the same server, pull requests are always welcome.

@pluma
Copy link
Contributor

pluma commented Mar 22, 2017

I'm closing this on the assumption that the question has been answered. Feel free to reopen this issue if there's anything missing in the answer.

@pluma pluma closed this as completed Mar 22, 2017
@p30arena
Copy link
Author

p30arena commented Aug 5, 2017

I'm making connections to my Foxx service using nodejs http client.
I'm also using http Agent mentioned above.
But I hit the open files limit, now I have 4096 open files connected to Foxx and none of them Close!

Whats happening????

options.agent = new AJAX._http.Agent({
			maxFreeSockets: 3,
			maxSockets: 3,
			keepAlive: true,
			keepAliveMsecs: 1000
		});

http.request(options, res => {

@pluma
Copy link
Contributor

pluma commented Aug 7, 2017

That looks like you're using the node version of the driver in the browser (at least that's what "AJAX" suggests). In that case you should keep in mind that the socket limits as well as the driver's connection pool will be per client, or more specifically per context (multiple tabs = multiple contexts).

Also it looks like you're making direct requests to the server using http.request rather than using the driver. The driver maintains a connection pool and request queue to limit the number of concurrent requests but this is only true when you are making the requests using the driver. Also this only works in the node.js (server-side) version, not the browser version or a browserified bundle of the node.js version.

@p30arena
Copy link
Author

p30arena commented Aug 7, 2017

@pluma Can I send Foxx requests using the driver? I didn't find anything in the docs.

@pluma
Copy link
Contributor

pluma commented Aug 7, 2017

@p30arena Check the section on arbitrary routes, it includes an example.

If you have more questions please consider using the public ArangoDB Slack community.

@p30arena
Copy link
Author

p30arena commented Aug 7, 2017

I think the issue was with the OS's 7200 sec delay of keep alive probing.
Also it was weird that when keep alive was true, the node.js agent didn't honor the maxSockets limit, when I turned it to false, I experienced a couple of seconds lag with the requests, caused by 3 sockets limit.
Today I switched to ArangoJS, everything's working fine, it seems that you have your own connection pool and not relying solely on node.js's http agent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Probably not a bug.
Projects
None yet
Development

No branches or pull requests

3 participants