C# 中的 OrientDB 连接池

OrientDB Connection Pool in C#

我正在使用 OrientDB v2.2.16 和 C# driver v0.1.12.0。我找不到任何关于如何使用此驱动程序的新迭代创建连接池的文档。 ODatabase 构造函数有一个 connectionPool 参数:

ODatabase db=new ODatabase("localhost", 2424, "testDb", ODatabaseType.Graph, "USER", "PASSWORD", "Pool");

但是无法创建 "Pool"。旧版驱动在OClient中包含一个CreateDatabasePool函数class:

OClient.CreateDatabasePool("localhost", 2424, "testDb", ODatabaseType.Graph, "USER", "PASSWORD", 10, "Pool");

新的没有。池是否会在第一次调用 ODatabase 构造函数时自发创建自己?如果是这样,我如何控制池大小等参数?

Does the pool spontaneously create itself upon the first call to the ODatabase constructor?

查看the source,构造函数确实自动创建了一个连接池:

public ODatabase(string hostName, int port, string databaseName, ODatabaseType type, string userName, string userPassword)
{
    _connectionPool = new ConnectionPool(hostName, port, databaseName, type, userName, userPassword);
    ClientCache = new ConcurrentDictionary<ORID, ODocument>();
}

If so, how do I control parameters such as pool size?

查看 the code for the ConnectionPool object,没有任何直接的方法可以显式控制池连接数:

public Connection GetConnection()
{
    if (_connectionPool.ContainsKey(_poolAlias))
        return _connectionPool[_poolAlias];

    var connection = new Connection(_hostName, _port, _databaseName, _type, _userName, _userPassword, _sslCerts);
    _connectionPool.AddOrUpdate(_poolAlias, i => connection,
        (i, conn) => _connectionPool[i] = conn);

    return connection;
}

如您所见,在 ODatabase 对象实例的生命周期内保持连接。因此,控制池大小的唯一方法是控制 ODatabase 对象的生命周期,以及用于 "poolAlias."

的值

请注意,在构造此对象时始终会创建一个池,即使您未指定 poolAlias 也是如此。在这种情况下,别名设置为 "Default."