<ul>
<li>What's the optimal level of concurrency that the C++ implementation of BerkeleyDB can reasonably support?</li>
<li>How many threads can I have hammering away at the DB before throughput starts to suffer because of resource contention?</li>
</ul>

<p>I've read the manual and know how to set the number of locks, lockers, database page size, etc. but I'd just like some advice from someone who has real-world experience with BDB concurrency.</p>

<p>My application is pretty simple, I'll be doing gets and puts of records that are about 1KB each. No cursors, no deleting.</p>

[{'answer_id': 530, 'author': 'svrist', 'author_id': 86, 'author_profile': 'https://Stackoverflow.com/users/86', 'pm_score': 3, 'selected': False, 'text': "<p>Doesn't this depend on the hardware as well as number of threads and stuff?</p>\n\n<p>I would make a simple test and run it with increasing amounts of threads hammering and see what seems best.</p>\n"}, {'answer_id': 667, 'author': 'Daan', 'author_id': 197, 'author_profile': 'https://Stackoverflow.com/users/197', 'pm_score': 4, 'selected': False, 'text': '<p>It depends on what kind of application you are building. Create a representative test scenario, and start hammering away. Then you will know the definitive answer.</p>\n\n<p>Besides your use case, it also depends on CPU, memory, front-side bus, operating system, cache settings, etcetera.</p>\n\n<p>Seriously, just test your own scenario.</p>\n\n<p>If you need some numbers (that actually may mean nothing in your scenario):</p>\n\n<ul>\n<li><a href="http://www.oracle.com/technology/products/berkeley-db/pdf/berkeley-db-perf.pdf" rel="noreferrer">Oracle Berkeley DB: \nPerformance Metrics and \nBenchmarks</a></li>\n<li><a href="http://staff.rcost.unisannio.it/visaggio/berkleyDB.pdf" rel="noreferrer">Performance Metrics \n&amp; Benchmarks:<br>\nBerkeley DB</a></li>\n</ul>\n'}, {'answer_id': 1071, 'author': 'Josh', 'author_id': 257, 'author_profile': 'https://Stackoverflow.com/users/257', 'pm_score': 2, 'selected': False, 'text': "<p>What I did when working against a database of unknown performance was to measure turnaround time on my queries.  I kept upping the thread count until turn-around time dropped, and dropping the thread count until turn-around time improved (well, it was processes in my environment, but whatever).  </p>\n\n<p>There were moving averages and all sorts of metrics involved, but the take-away lesson was: just adapt to how things are working at the moment.  You never know when the DBAs will improve performance or hardware will be upgraded, or perhaps another process will come along to load down the system while you're running.  So adapt.</p>\n\n<p>Oh, and another thing: avoid process switches if you can - batch things up.</p>\n\n<hr>\n\n<p>Oh, I should make this clear: this all happened at run time, not during development.</p>\n"}, {'answer_id': 74831, 'author': 'Max Lybbert', 'author_id': 10593, 'author_profile': 'https://Stackoverflow.com/users/10593', 'pm_score': 2, 'selected': False, 'text': '<p>The way I understand things, Samba created <a href="http://sourceforge.net/projects/tdb/" rel="nofollow noreferrer">tdb</a> to allow "multiple concurrent <em>writers</em>" for any particular database file.  So if your workload has multiple writers your performance may be bad (as in, the Samba project chose to write its own system, apparently because it wasn\'t happy with Berkeley DB\'s performance in this case).</p>\n\n<p>On the other hand, if your workload has lots of readers, then the question is how well your operating system handles multiple readers.</p>\n'}, {'answer_id': 199163, 'author': 'yoav.aviram', 'author_id': 25287, 'author_profile': 'https://Stackoverflow.com/users/25287', 'pm_score': 3, 'selected': False, 'text': "<p>I strongly agree with Daan's point: create a test program, and make sure the way in which it accesses data mimics as closely as possible the patterns you expect your application to have. This is extremely important with BDB because different access patterns yield very different throughput.</p>\n\n<p>Other than that, these are general factors I found to be of major impact on throughput:</p>\n\n<ol>\n<li><p>Access method (which in your case i guess is BTREE).</p></li>\n<li><p>Level of persistency with which you configured DBD (for example, in my case the 'DB_TXN_WRITE_NOSYNC' environment flag improved write performance by an order of magnitude, but it compromises persistency) </p></li>\n<li><p>Does the working set fit in cache?</p></li>\n<li><p>Number of Reads Vs. Writes.</p></li>\n<li><p>How spread out your access is (remember that BTREE has a page level locking - so accessing different pages with different threads is a big advantage).</p></li>\n<li><p>Access pattern - meanig how likely are threads to lock one another, or even deadlock, and what is your deadlock resolution policy (this one may be a killer).</p></li>\n<li><p>Hardware (disk &amp; memory for cache).</p></li>\n</ol>\n\n<p>This amounts to the following point:\nScaling a solution based on DBD so that it offers greater concurrency has two key ways of going about it; either minimize the number of locks in your design or add more hardware.</p>\n"}]
['https://Stackoverflow.com/questions/264', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/104/']