在调用AWS lambda handlers`回调时遇到Neptune Gremlin连接问题
我使用[email protected]作为我的带有AWS Lambdas的Node.js 8.10应用程序。对于单个调用,该过程可以正常工作。这是我的示例代码。
const gremlin = require('gremlin');
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const Graph = gremlin.structure.Graph;
exports.handler = (event, context, callback) => {
dc = new DriverRemoteConnection('wss://your-neptune-endpoint:8182/gremlin');
const graph = new Graph();
const g = graph.traversal().withRemote(dc);
try {
const result = await g.V().limit(1).count().next();
dc.close();
callback(null, { result: result });
} catch (exception) {
callback('Error');
throw error;
}
}
当我为单个调用运行此过程时,它似乎工作正常,但是当我尝试运行批处理操作(类似100,000个请求/小时)时,我在CloudWatch日志指标中遇到我的连接未关闭成功。我已经尝试了一些这样的实现,比如callbackWaitForEventLoopEmpty,但是抓住了lambda。当我删除回调(或类似地返回)时,此过程也适用于批处理操作。但我确实希望从这个lambda返回数据,其中包含传递给我的step函数的信息,以根据该信息触发另一个lambda。
回答如下:在做了一些研究之后,我发现问题在于gremlin包如何处理关闭连接的事件并不利于无服务器架构。当触发driver.close()时。当实例化驱动程序时,它会创建客户端实例,它本身会创建连接实例,使用ws库创建websocket实例。现在ws.close()事件正常关闭所有事件,它不会等待在调用我的回调之前调用事件,并且该事件保持打开和泄漏。因此,在连接实例上显式调用dc._client._connection.ws.terminate()之后,dc.close()立即关闭连接。
在调用AWS lambda handlers`回调时遇到Neptune Gremlin连接问题
我使用[email protected]作为我的带有AWS Lambdas的Node.js 8.10应用程序。对于单个调用,该过程可以正常工作。这是我的示例代码。
const gremlin = require('gremlin');
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const Graph = gremlin.structure.Graph;
exports.handler = (event, context, callback) => {
dc = new DriverRemoteConnection('wss://your-neptune-endpoint:8182/gremlin');
const graph = new Graph();
const g = graph.traversal().withRemote(dc);
try {
const result = await g.V().limit(1).count().next();
dc.close();
callback(null, { result: result });
} catch (exception) {
callback('Error');
throw error;
}
}
当我为单个调用运行此过程时,它似乎工作正常,但是当我尝试运行批处理操作(类似100,000个请求/小时)时,我在CloudWatch日志指标中遇到我的连接未关闭成功。我已经尝试了一些这样的实现,比如callbackWaitForEventLoopEmpty,但是抓住了lambda。当我删除回调(或类似地返回)时,此过程也适用于批处理操作。但我确实希望从这个lambda返回数据,其中包含传递给我的step函数的信息,以根据该信息触发另一个lambda。
回答如下:在做了一些研究之后,我发现问题在于gremlin包如何处理关闭连接的事件并不利于无服务器架构。当触发driver.close()时。当实例化驱动程序时,它会创建客户端实例,它本身会创建连接实例,使用ws库创建websocket实例。现在ws.close()事件正常关闭所有事件,它不会等待在调用我的回调之前调用事件,并且该事件保持打开和泄漏。因此,在连接实例上显式调用dc._client._connection.ws.terminate()之后,dc.close()立即关闭连接。