} else {
for(File f: bdbDir.listFiles())
f.delete();
}
environment = new Environment(bdbDir, environmentConfig);
final Database db = environment.openDatabase(null, "test", databaseConfig);
final Random rand = new Random();
int iterations = totalSize / increment;
long[] readTimes = new long[iterations];
long[] writeTimes = new long[iterations];
ExecutorService service = Executors.newFixedThreadPool(threads);
for(int i = 0; i < iterations; i++) {
System.out.println("Starting iteration " + i);
List<Future<Object>> results = new ArrayList<Future<Object>>(increment);
long startTime = System.currentTimeMillis();
final int fi = i;
for(int j = 0; j < increment; j++) {
final int fj = j;
results.add(service.submit(new Callable<Object>() {
public Object call() throws Exception {
db.put(null,
new DatabaseEntry(Integer.toString(fi * increment + fj).getBytes()),
new DatabaseEntry(Integer.toString(fi * increment + fj).getBytes()));
return null;
}
}));
}
for(int j = 0; j < increment; j++)
results.get(j).get();
writeTimes[i] = System.currentTimeMillis() - startTime;
System.out.println("write: " + (writeTimes[i] / (double) increment));
results.clear();
startTime = System.currentTimeMillis();
for(int j = 0; j < increment; j++) {
results.add(service.submit(new Callable<Object>() {
public Object call() throws Exception {
int value = rand.nextInt((fi + 1) * increment);
return db.get(null,
new DatabaseEntry(Integer.toString(value).getBytes()),
new DatabaseEntry(Integer.toString(value).getBytes()),
null);
}
}));