关于eXtremeDB连接问题

2022-07-28 00:00:00 专区 订阅 线程 数据管理 实时

在eXtremeDB中,每个线程都需要有自己的连接,并且这个连接在线程中是不能共享的。

那么,我们是否可以在主线程中预先建立一个连接池,以供其他线程使用呢?答案是否定的。

WRT connection pool: it is important to understand and keep in mind the difference between eXtremeDB and other DBMS. eXtremeDB works in the same address space as the project that is using it. There is no cost for connects/re-connects. Strictly speaking, connecting to an eXtremeDB database costs the same as calling any other function. eXtremeDB does not allocate any additional memory, sync. primates, sockets and etc. for a connection. For In-memory only databases eXtremeDB uses a pre-allocated record from the connection array. For persistent databases it opens file handles for every storage and log file. For shared-memory databases it maps a shared memory region to the local address space for the first connection (all other re-use that mapping). All tasks (threads) runs in-memory (even file handle allocations). Real network-related processing, like TCP/IP dialogues, happen only for HA/Cluster enabled databases or RSQL access and requires using different APIs (not just mco_db_connect()). So, there is no point in maintaining any kind of connection pool.

WRT the question: “And I have another idea for it. we create a connection pool in the main thread and those connections will be used by other threads. Is this way right and feasible?”

In most OS’s, the program's "main thread" is no different from "other threads", except maybe the initial stack size. So there is no difference between the "main thread" and "all other threads". The rule is still the same: very simply "every thread uses its own separate connection to access the database". No exceptions.
————————————————
版权声明:本文为CSDN博主「liyu19870423」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/liyu19870423/article/details/44710117

相关文章