[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why does it take so long to...

Last message for today ;)

The following code shows the differences between client side and server side

       long start = System.currentTimeMillis();
       int num = Integer.parseInt (args[0]);
       for (int i=0; i<num; i++) {
           Auto auto = (Auto)db.createObject (AutoImpl.class.getName(), Database.Private, null);
           auto.setAge (10);
       System.out.println (System.currentTimeMillis() - start);

       start = System.currentTimeMillis();
       Garage garage = (Garage)db.createObject (GarageImpl.class.getName(), Database.Private, null);
       garage._populate (new Integer(num));
       System.out.println (System.currentTimeMillis() - start);

The _populate() method does exactly the same as the loop above, except that
it runs inside the server. On my system I get the following output:


This means the server-side _populate() method runs 27 times faster than the
client side loop. Besides, the the client side loop is probably not correct.
Most likely all the cars should be created and initialized together. If one
car failes, none should be created. So the loop should run inside one
transaction. And the best way doing this is to put it in a method of a
database object. So the lack of explicite transaction demarcation leads to
fast and correct code. (at least in my eyes. other ideas?)

Ok, with 0.4 you can have a transaction around the loop even on the client side.
This is more correct but this is as slow as the above version. So think twice
before you use external transactions. ;)

Falko Braeutigam                         mailto:falko@softwarebuero.de
softwarebuero m&b (SMB)                    http://www.softwarebuero.de