关于eXtremeDB连接问题

在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.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值