Let's create a small example to test batch messaging mode behavior. We will use bulk insert with and without batch messaging configuration.
01private static void fillUpDb(Configuration configuration) throws IOException { 02
System.out.println("Testing inserts"); 03
ObjectContainer container = Db4o.openClient(HOST, PORT, USER, 04
PASS); 05
try { 06
long t1 = System.currentTimeMillis(); 07
for (int i = 0; i < NO_OF_OBJECTS; i++) { 08
Pilot pilot = new Pilot("pilot #" + i, i); 09
container.set(pilot); 10
} 11
long t2 = System.currentTimeMillis(); 12
long diff = t2 - t1; 13
System.out.println("Operation time: " + diff + " ms."); 14
} finally { 15
container.close(); 16
} 17
}
Let's configure the server and run the insert operation first without batch messages, then with batch messages:
01public static void main(String[] args) throws IOException { 02
ObjectServer db4oServer = Db4o.openServer(FILE, PORT); 03
try { 04
db4oServer.grantAccess(USER, PASS); 05
Configuration configuration = Db4o.newConfiguration(); 06
fillUpDb(configuration); 07
configuration.clientServer().batchMessages(true); 08
fillUpDb(configuration); 09
} finally { 10
db4oServer.close(); 11
} 12
}
You can try different values of NO_OF_OBJECTS
constant to see the difference.
If the value of NO_OF_OBJECTS
is high
(>1,000,000) you may notice that the memory consumption increases a lot. In
order to decrease it, try using:
Java:
container.ext().configure().clientServer().maxBatchQueueSize(size);
Specify the size parameter according to the desirable memory consumption limit.