我正在使用 gremlin javascript 客户端 (3.4.2) 通过 gremlin 服务器查询 janusgraph。我注意到在开发过程中让服务器运行一段时间后,一些查询图形的请求开始保持挂起状态(在 gremlin-server 上设置的超时量)。
查看服务器控制台我可以看到这条消息:
Pausing response writing as writeBufferHighWaterMark exceeded on RequestMessage{, requestId=9697c61a-34de-4764-a8c4-72d7f7a154ac, op='bytecode', processor='traversal', args={gremlin=[[], [V(), has(User, identityid, NQ05cGsB3uhLm-BIAGPq), outE(worked), choose([[], [values(dateto)]], [[], [project(vertexId, role, businessId, business, relationId, dateinsert, datefrom, dateto), by([[], [inV(), hasLabel(Job), id()]]), by([[], [inV(), hasLabel(Job), values(role)]]), by([[], [inV(), hasLabel(Job), outE(), hasLabel(at), inV(), id()]]), by([[], [inV(), hasLabel(Job), outE(), hasLabel(at), inV(), values(name)]]), by(id), by(dateinsert), by(datefrom), by(dateto)]], [[], [project(vertexId, role, businessId, business, relationId, dateinsert, datefrom), by([[], [inV(), hasLabel(Job), id()]]), by([[], [inV(), hasLabel(Job), values(role)]]), by([[], [inV(), hasLabel(Job), outE(), hasLabel(at), inV(), id()]]), by([[], [inV(), hasLabel(Job), outE(), hasLabel(at), inV(), values(name)]]), by(id), by(dateinsert), by(datefrom)]])]], aliases={g=refeenet}}} - writing will continue once client has caught up
然后过了一会儿出现超时警告。
我不确定为什么会这样,而且我没有找到任何有用的解决方案。
我正在使用 typescript 。
这是管理遍历源的类:
import gremlin from "gremlin";
const GREMLIN_URL = "ws://localhost:8182/gremlin";
const GRAPH_NAME = "maingraph";
const { Graph } = gremlin.structure;
const { DriverRemoteConnection } = gremlin.driver;
export class GremlinApi {
public static g: gremlin.process.GraphTraversalSource;
public static connection: gremlin.driver.DriverRemoteConnection;
public static getTraversalSource() {
if (!GremlinApi.g) {
const graph = new Graph();
GremlinApi.connection = new DriverRemoteConnection(GREMLIN_URL, { traversalSource: GRAPH_NAME });
GremlinApi.g = graph.traversal().withRemote(GremlinApi.connection);
}
return GremlinApi.g;
}
public static closeTraversal() {
if (GremlinApi.connection && GremlinApi.connection.close) {
GremlinApi.connection.close();
GremlinApi.connection = null;
GremlinApi.g = null;
}
}
}
这是我通常如何使用遍历的示例:
import { GremlinApi } from "../db/gremlinApi/gremlinApi";
// Get the traversal
const g = GremlinApi.getTraversalSource();
// Do something with the traversal
GremlinApi.closeTraversal();
这通常发生在 3/4 的查询彼此非常接近的情况下。其中一些会超时。
知道是什么导致了这个问题吗?
最佳答案
该消息通常意味着客户端跟不上服务器正在尝试写入的内容,因此服务器暂停其响应,直到客户端 catch 缓冲区中的内容。我想这可能是一个缓慢的客户端导致了问题,或者可能是网络问题,但无论如何暂停的目的是通过继续在内存中缓冲结果来避免服务器上的内存不足错误。鉴于这种情况,我想您会明白为什么像您在对问题的评论中提到的那样,间隔查询会有所帮助。
您可以微调 Gremlin 服务器 yaml 文件中的“水印”- writeBufferHighWaterMark
和 writeBufferLowWaterMark
.您还可以查看您发送的遍历。您没有指定它们是什么,但您应该查看是否可以精简或消除返回的结果。我通常看到用户在数据加载时遇到这个问题,很多时候可以通过调用 iterate()
忽略返回结果来消除它。在遍历结束时而不是 next()
, toList()
等等,这需要返回一个实际结果,而这些结果无论如何都不会在客户端使用。
关于javascript - Gremlin 暂停响应写入,因为 RequestMessage 超出了 writeBufferHighWaterMark,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56672809/