Your problem may be related to strong guarantees of the durability of the databases you use.
Basically, for any ACID compatible database, you will need at least one fsync () call to commit the database. This should happen in order to guarantee durability (otherwise, updates may be lost in the event of a system failure), but also guarantee the internal consistency of the database on disk. The database API will not return from the insert operation until the fsync () call completes.
fsync () can be a very difficult operation for many operating systems and disk hardware, even on SSDs. (The exception is SSDs with battery or capacitor support - they can handle flash cleanup operations mostly as no-op to avoid exactly the delay you are likely to experience.)
The solution is to make all your stores inside one big transaction. I do not know about Berkeley DB, but for sqlite performance can be significantly improved this way.
To see if this is your problem at all, you can try looking at the process of writing the database with strace and look for frequent fsync () calls (more than every second will be a pretty strong hint).
Update: If you are absolutely sure that you do not need durability, you can try the answer Optimize application performance in Berkeley DB ; if you do, you should learn the TDS (Transaction Data Storage) feature in Berkeley DB.
source share