Recommended GremlinClient Lifetime for Web Applications

109 views
Skip to first unread message

Bassem Naguib

unread,
Feb 19, 2021, 6:36:16 AM2/19/21
to Gremlin-users
Hello Everybody!

I am trying to use Gremlin.Net in an ASP.NET web application. And I think I will need to re-use the "GremlinClient" object (or maybe the "DriverRemoteConnection" or the "GraphTraversalSource") to get better performance.

But I am not sure about the right way to do that in a multi-threaded environment like a web application. Should I create a new "GremlinClient" for each HTTP request and dispose of it at the end of the request? Or I should maintain only one "GremlinClient" for the web application lifetime and let all the request handler threads use it in parallel?

I see that the "GremlinClient" maintains a connection pool internally. Does this mean that one instance can handle a large number of parallel requests?

Thanks in advance!

Florian Hockmann

unread,
Feb 19, 2021, 8:18:17 AM2/19/21
to Gremlin-users
Hi,

in short, yes, a GremlinClient instance should be shared across different threads to make best use of the connection pool. Creating the connection pool also comes with some initialization cost as the configured number of connections are created directly. It doesn't make much sense to do that for every incoming HTTP request as it slows your application down and the connections aren't needed any more after the request has been finished.
You might need to adjust the connection pool configuration if you have a high number of concurrent requests. The config is documented here. I would probably just start with the default config and see whether it's able to handle your requests and then adjust the numbers if necessary.

Bassem Naguib

unread,
Feb 19, 2021, 11:54:07 AM2/19/21
to Gremlin-users
Thank you so much Florian for answering! I really appreciate it!

Graham Wallis

unread,
Feb 19, 2021, 12:24:31 PM2/19/21
to gremli...@googlegroups.com
Yes thanks Florian and Bassem,

Your question and answer were very timely. I am just looking at the Gremlin Java client for the first time - and that seems to have similar configuration of the connection pool, which looks like it could provide hours of fun tuning the pool parameters! :-)

Best regards,
 Graham

Graham Wallis
IBM Open Software
Internet: graham...@uk.ibm.com    
IBM, Hursley Park, Hursley, Hampshire SO21 2JN

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
gremlin-user...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/gremlin-users/6ccb377a-6897-4b72-813e-31a3f69a7d6bn%40googlegroups.com.


Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU

Bassem Naguib

unread,
Feb 23, 2021, 4:45:19 AM2/23/21
to Gremlin-users
I wrote an article and made a video and a GitHub project to explain how to use Gremlin.Net to connect and send traversals to a Gremlin server from an ASP.NET Web application. I will post the links here since they are related to this thread.

Florian Hockmann

unread,
Feb 23, 2021, 5:24:53 AM2/23/21
to Gremlin-users
Great video and blog article! You did a really good job in explaining all the necessary steps and configuration options. Hope this will help some new Gremlin.Net users :-)
Reply all
Reply to author
Forward
0 new messages