2

我们使用 OpenLink Virtuoso 作为 NodeJS 项目的主要数据库管理器。我们通过 HTTP SPARQL 端点仅使用 SPARQL 查询来查询数据库。为此,我们使用 request-promise 库,配置如下:

        const queryRequest = rp({
            method: "POST",
            uri: queryObject.fullUrl,
            form: {
                query: queryObject.query,
                maxrows: queryObject.maxRows,
                format: queryObject.resultsFormat
            },
            headers: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            json: true,
            forever : true, // Keep connections alive instead of creating new ones
            timeout : Config.dbOperationTimeout,

        })
            .then(function (parsedBody) {

在运行我们的测试时,我们会启动应用程序(新的 express 应用程序对象和 nodejs 服务器)数百次并尝试干净地关闭它。该应用程序关闭,服务器也关闭,但我认为 virtuoso 连接保持打开状态,因为尽管我们正在尝试重用现有连接,但连接数量仍在缓慢增加。

close() 方法(它会关闭应用程序)运行以下函数:

const closePendingConnections = function(callback)
{
    async.map(Object.keys(self.pendingRequests), function(queryID, cb)
    {
        if(self.pendingRequests.hasOwnProperty(queryID))
        {
            self.pendingRequests[queryID].cancel(cb) //try to abort all requests in the queue
        }
    }, callback);
};

const destroyQueue = function(callback)
{
    self.q.destroy(callback);
};

在大约 150 次测试(启动和关闭)之后,查询开始失败并停止测试。我们尝试使用队列来确保在给定时间每次应用启动时只有一个与 virtuoso 的连接处于活动状态。打印挂起的连接数在队列中不断显示 0 或 1 个请求,所以我知道这不是队列的问题。

运行这些测试后 virtuoso profiler 的屏幕截图在哪里:

在此处输入图像描述

有什么方法可以强制在每次服务器和应用程序关闭后以及再次启动之前关闭所有与 virtuoso 的 HTTP 连接(因为我们必须为每次测试都这样做)?

4

0 回答 0