In a scenario when one java application instance can talk to multiple Gremlin servers (say multiple graph instances in CosmosDB). What is the recommendation for creating and caching Gremlin Clients in such a case. Looks like on my mac maximum number of Cluster instances I can create is less than 300. Beyond that I get "Too many files open exception".
caused by: java.io.IOException: Too many open files
java.lang.IllegalStateException: failed to create a child event loop
at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:88)
at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:58)
at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:47)
at io.netty.channel.MultithreadEventLoopGroup.<init>(MultithreadEventLoopGroup.java:59)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:86)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:81)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:68)
at org.apache.tinkerpop.gremlin.driver.Cluster$Factory.<init>(Cluster.java:1065)
Is there a way around it? This is what is being done for many different values of graphUserName .
final Cluster cluster = Cluster.build()
.addContactPoint("host")
.port(443)
.credentials(graphUserName,
"graph-password")
.serializer("serializer)
.enableSsl(true)
.create();
cluster.connect());
You should be creating one
Clusterobject for the life of your application. Assuming you are using sessionless requests, you would then also only create oneClientinstance from thatClusterand re-use it. There may of course be situations where a singleClusterobject may not be sufficient. There are driver configuration options that can only apply to aClusterobject and not theClientinstances it spawns. For example, if you have multiple authentication methods or are connecting to different servers, those settings are bound to theClusterwhich would then require you to have several of those objects.While you always want to take care in managing your settings for the driver, opening a large number of
Clusterobjects with default settings (which is where most people start) will likely trigger the error ofcaused by: java.io.IOException: Too many open filesthat you are seeing. EachClusterobject will open many network resources and unless you have made changes to your default settings in your OS you will likely exceed the file limit. This message is an operating system level issue and there are many resources on the internet for solving it.