Letting BerkeleyDB manage the locks is going to give the best performance. You can find various examples on here using Super Search. If you can't get that to work for you, consider using MLDBM::Sync. It doesn't perform as well, but takes a very safe approach.