- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在 AWS 中运行一个海王星数据库。我们有 1 个作者和 3 个读者实例。几周前,我们发现负载平衡没有按预期工作。我们发现,我们的软件实例只连接到一个阅读器,并保持这种连接直到 EOL。所以其他读者实例永远不会被采用。考虑以下链接 https://docs.aws.amazon.com/neptune/latest/userguide/feature-overview-endpoints.html .有描述,对于海王星负载平衡,您必须在客户端进行,并且一个先决条件是您必须禁用 DNS 缓存。此处描述了客户端实现 https://docs.amazonaws.cn/en_us/neptune/latest/userguide/best-practices-gremlin-java-multiple.html分别https://docs.aws.amazon.com/neptune/latest/userguide/best-practices-gremlin-java-separate.html因为我们分别处理作者和读者集群。我们的软件是用java编写的。因此,我们按如下方式实现了所描述的问题:
在 jvm 中禁用 DNS 缓存:
java.security.Security.setProperty("networkaddress.cache.ttl", "0");
pom.xml 看起来像:
<properties>
<gremlin.version>3.4.10</gremlin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>gremlin-driver</artifactId>
<version>${gremlin.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>tinkergraph-gremlin</artifactId>
<version>${gremlin.version}</version>
</dependency>
<dependency>
<!-- aws neptune db -->
<groupId>org.apache.tinkerpop</groupId>
<artifactId>gremlin-core</artifactId>
<version>${gremlin.version}</version>
</dependency>
</dependencies>
通过 gremlin 驱动程序连接到数据库:
Cluster.Builder writer = Cluster.build().port(8182)
.maxInProcessPerConnection(32).maxSimultaneousUsagePerConnection(32).maxContentLength(4 * 1024 * 1024)
.serializer(Serializers.GRAPHBINARY_V1D0)
.addContactPoint("some aws instance enpoint -- 1 --");
Cluster.Builder reader = Cluster.build().port(8182)
.maxInProcessPerConnection(32).maxSimultaneousUsagePerConnection(32).maxContentLength(4 * 1024 * 1024)
.serializer(Serializers.GRAPHBINARY_V1D0)
.addContactPoint("some aws instance enpoint -- 2 --")
.addContactPoint("some aws instance enpoint -- 3 --");
final Cluster writerCluster = writer.create();
final Cluster readerCluster = reader.create();
DriverRemoteConnection writerConn = DriverRemoteConnection.using(writerCluster);
DriverRemoteConnection readerConn = DriverRemoteConnection.using(readerCluster);
gWriter = AnonymousTraversalSource.traversal().withRemote(writerConn);
gReader = AnonymousTraversalSource.traversal().withRemote(readerConn);
for(int i = 0; i < 10; i++){
NeptuneAdapter.getInstance().setGraph(gWriter);
System.out.println(gWriter.addV("TestVertex" + i + 1).iterate());
System.out.println("Vertex added, now: " + gWriter.V().count().next().toString());
NeptuneAdapter.getInstance().setGraph(gReader);
System.out.println(gReader.V().count().next().toString());
System.out.println(gReader.V().count().next().toString());
System.out.println(gReader.V().count().next().toString());
System.out.println(gReader.V().count().next().toString());
System.out.println(gReader.V().count().next().toString());
System.out.println(gReader.V().count().next().toString());
Thread.sleep(1000);
}
问题是,在运行此代码时,在第一次获取图形时没有任何 react 。经过一些调试我们发现ConnectionPool的构造函数中是阻塞代码。其中,依赖于 minPoolSize,为每个 Connection 创建了一个 CompletableFuture。其中,连接是通过主机建立的。通过 Clusters Manager ScheduledExecutor 执行时,ConnectionPool 构造函数正在加入所有 future 。如此处所述
I want do something as future done order in CompletableFuture List实现似乎是正确的。但是一定有什么东西阻塞了。在检查 gremlin-driver 并注释掉 join-code-line 并设置一个简单的 Thread.sleep() 之后,代码确实按预期工作。现在,负载平衡也开始工作了。添加一些输出后,上面执行的代码的输出如下所示:
CONNECTION_POOL --- constructor --- poolLabel: {address=endpoint -- 1 -- /IP:PORT}
Opening connection pool
LoadBalancingStrategy adding host: Host{address=endpoint -- 1 -- /IP:PORT} host size is now 1
CONNECTION_POOL --- borrowConnection --- host: Host{address=endpoint -- 1 -- /IP:PORT} for next Query
[RemoteStep(DriverServerConnection-address=endpoint -- 1 -- /IP:PORT [graph=g])]
CONNECTION_POOL --- borrowConnection --- host: Host{address=endpoint -- 1 -- /IP:PORT} for next Query
Vertex added, now: 1
CONNECTION_POOL --- constructor --- poolLabel: {address=endpoint -- 2 -- /IP:PORT}
CONNECTION_POOL --- constructor --- poolLabel: {address=endpoint -- 3 -- /IP:PORT}
Opening connection pool
LoadBalancingStrategy adding host: Host{address=endpoint -- 2 -- /IP:PORT} host size is now 1
Opening connection pool
LoadBalancingStrategy adding host: Host{address=endpoint -- 3 -- /IP:PORT} host size is now 2
CONNECTION_POOL --- borrowConnection --- host: Host{address=endpoint -- 2 -- /IP:PORT} for next Query
1
CONNECTION_POOL --- borrowConnection --- host: Host{address=endpoint -- 3 -- /IP:PORT} for next Query
1
CONNECTION_POOL --- borrowConnection --- host: Host{address=endpoint -- 2 -- /IP:PORT} for next Query
1
CONNECTION_POOL --- borrowConnection --- host: Host{address=endpoint -- 3 -- /IP:PORT} for next Query
1
CONNECTION_POOL --- borrowConnection --- host: Host{address=endpoint -- 2 -- /IP:PORT} for next Query
1
CONNECTION_POOL --- borrowConnection --- host: Host{address=endpoint -- 3 -- /IP:PORT} for next Query
1
CONNECTION_POOL --- borrowConnection --- host: Host{address=endpoint -- 1 -- /IP:PORT} for next Query
[RemoteStep(DriverServerConnection-address=endpoint -- 1 -- /IP:PORT [graph=g])]
CONNECTION_POOL --- borrowConnection --- host: Host{address=endpoint -- 1 -- /IP:PORT} for next Query
Vertex added, now: 2
CONNECTION_POOL --- borrowConnection --- host: Host{address=endpoint -- 2 -- /IP:PORT} for next Query
1
CONNECTION_POOL --- borrowConnection --- host: Host{address=endpoint -- 3 -- /IP:PORT} for next Query
1
CONNECTION_POOL --- borrowConnection --- host: Host{address=endpoint -- 2 -- /IP:PORT} for next Query
1
CONNECTION_POOL --- borrowConnection --- host: Host{address=endpoint -- 3 -- /IP:PORT} for next Query
2
CONNECTION_POOL --- borrowConnection --- host: Host{address=endpoint -- 2 -- /IP:PORT} for next Query
2
CONNECTION_POOL --- borrowConnection --- host: Host{address=endpoint -- 3 -- /IP:PORT} for next Query
2
现在的问题是,我们是否以错误的方式使用了 gremlin 驱动程序,还是这是一个错误,我们应该向 tinkerpop-master 存储库添加问题?或者还有其他一些我们不了解的魔法吗?
最佳答案
我们过去曾在 Neptune 读取器节点负载平衡方面遇到过这个问题。我们通过利用
https://github.com/awslabs/amazon-neptune-tools/tree/master/neptune-gremlin-client/gremlin-client
我们不得不稍微调整我们的阅读器客户端,以处理客户端的负载平衡。
创建阅读器客户端的更新方式如下所示:
GremlinClient client;
GremlinCluster cluster;
ClusterEndpointsRefreshAgent clusterEndpointRefreshAgent;
String clusterId = "<your_cluster_id>";
private void createReaderClient(boolean isIAMAuthEnabled) {
EndpointsSelector endpointsSelector = EndpointsType.ReadReplicas;
clusterEndpointRefreshAgent = new ClusterEndpointsRefreshAgent(clusterId, endpointsSelector);
Collection<String> addresses = clusterEndpointRefreshAgent.getAddresses().get(endpointsSelector);
if (isIAMAuthEnabled) {
cluster = createNeptuneGremlinClusterBuilder(addresses);
} else {
cluster = createGremlinClusterBuilder(addresses);
}
client = cluster.connect();
clusterEndpointRefreshAgent.startPollingNeptuneAPI(
addrs -> client.refreshEndpoints(addrs.get(endpointsSelector)), 300,
TimeUnit.SECONDS);
}
private GremlinCluster createGremlinClusterBuilder(Collection<String> addresses) {
GremlinClusterBuilder builder = GremlinClusterBuilder.build().port(8182)
.addContactPoints(addresses).enableSsl(true);
//set other required properties of GremlinCluster
return builder.create();
}
private GremlinCluster createNeptuneGremlinClusterBuilder(Collection<String> addresses) {
NeptuneGremlinClusterBuilder builder = NeptuneGremlinClusterBuilder.build()
.port(8182).addContactPoints(addresses)
.enableSsl(true).enableIamAuth(true);
// set other required properties of NeptuneGremlinClusterBuilder
return builder.create();
}
并且可以在创建
GraphTraversalSource
之前创建此阅读器客户端。像这样:
GraphTraversalSource g;
GraphTraversalSource getGraphTraversalSource(boolean isIAMAuthEnabled) {
if (g == null) {
createReaderClient(isIAMAuthEnabled);
g = AnonymousTraversalSource.traversal().withRemote(DriverRemoteConnection.using(client));
}
return g;
}
关于java - Gremlin 驱动程序在使用多个端点初始化 ConnectionPool 时阻塞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66315332/
我们有一个 Web 服务器,它使用单个连接字符串连接到数据库,这使其成为能够使用连接池的有力候选者。 我们需要一个还是多个 SqlConnection 对象? 即我们应该在共享内存中设置一个连接并每次
我们有一个 Web 服务器,它使用单个连接字符串连接到数据库,这使得它成为能够使用连接池的有力候选者。 我们需要一个 SqlConnection 对象还是多个? 即我们应该在共享内存中建立一个连接,并
在 VB.Net Windows 服务中,我目前正在使用以下工作单元: ThreadPool.QueueUserWorkItem(operation, nextQueueID) 在每个工作单元(或为
在我的应用程序中,我必须与多个 MySQL 交互(只读) DB 一个一个。对于每个数据库,我需要一定数量的连接。与数据库的交互不会一次性发生:我查询数据库,花一些时间处理结果,再次查询数据库,再次处理
我正在使用 tomcat 7 和 tomcat jdbc 连接池来分配 mysql 连接。 在夜间,我们没有任何事件,因此所有连接空闲时间超过 8 小时,并被 mysql 删除。 (mysql 的 w
我在尝试使用 mechanize 抓取网站时遇到此错误。 这是我的代码: agent = Mechanize.new agent.user_agent_alias = 'Mac Safari' age
Redis 连接池的字符集有问题(想处理字符串,而不是字节)。 如果我像这样连接到 Redis: r = redis.StrictRedis(host="localhost", port=6379,
我们正在 AWS 中运行一个海王星数据库。我们有 1 个作者和 3 个读者实例。几周前,我们发现负载平衡没有按预期工作。我们发现,我们的软件实例只连接到一个阅读器,并保持这种连接直到 EOL。所以其他
根据 OrientDB 官方文档,我应该使用以下代码使用对象 API 创建连接池。 // OPEN THE DATABASE OObjectDatabaseTx db= OObjectDatabase
我正在关注“Grails 2 - 快速入门指南”一书中名为 TekDays 的 Grails 应用程序开发。当我开始配置 DataSource 时,我遇到了建立数据库连接的问题。我不知道是什么原因,因
我遇到一个连接池问题,它很快就会耗尽。基本上我已经在应用程序中加载了一个监听器,每当初始化上下文时,计时器就会启动,其中的计时器任务将执行 SQL 查询,该查询使用连接池“我在 Tomcat 6 中复
我正在 Dart 中创建一个后端服务器应用程序,它使用 MySQL 数据库来存储数据。为了进行 SQL 调用,我使用了 SqlJocky 的 ConnectionPool。 应用启动时我做了什么: 创
我是 Grails 新手。在 Datasource.groovy 中进行一些基本配置后,我的 grails 应用程序无法启动。我收到以下错误 Error 2015-07-03 15:27:19,014
我有一个 Web 应用程序,它使用 JNDI 查找来连接到数据库。 连接工作正常并且返回查询没有问题。问题是连接没有正确关闭并停留在“ sleep ”模式(根据 mysql 管理员的说法)。这意味着它
我正在使用 ConnectionPool check out /检入数据库连接。 因此,如果没有异常,一切都会按预期进行。最后 checkin 连接。 但是,如果包含 with_connection
我正在尝试让我的 Rails 应用程序使用 Resque 来管理工作人员。但是,我想继续使用 ConnectionPool gem。 我在初始化程序中有这个: puts ENV["REDISTOGO_
我正在重构一个最初在 20 世纪 90 年代中期设计的遗留系统。那时候,JDBC 连接是一种稀缺资源,没有可靠的连接池实现,因此连接会被尽可能长时间地保留。这导致了如下结构: class Client
如果关闭javax.sql.connectionpooled连接,它不会在数据库中留下任何非 Activity session 。在我的例子中,我可以在数据库(oracle)中看到许多非 Activi
我无法在 rPi 上运行 ScadaLTS。 Aug 17, 2017 7:01:14 AM org.apache.catalina.startup.ClassLoaderFactory valida
在谷歌搜索了一整天后,我看到了很多关于这个问题的讨论,甚至是一个据说可以解决问题的指南[1],但直到现在我还没有找到解决方案。我想配置我的 web 服务,它依赖于 hibernate 3 来使用在我的
我是一名优秀的程序员,十分优秀!