db4o Developer Community

db4o open source object database, native to Java and .NET
Welcome to db4o Developer Community Sign in | Join
in Search
More Search Options

Performance issues with order by

Last post 07-19-2008, 02:08 PM by matiljuk. 2 replies.
Sort Posts: Previous Next
  •  07-19-2008, 05:34 AM 50221

    Performance issues with order by

    Hi everyone,

    Last weeks I evaluated Db4o features and functions. I'm very impressed by database performance and how easy Db4o is to use.

    But, queries with order by definition I have huge performance issues.

    Here is my example test case:
    I have 100 000 objects in database and my query have to list last ten added elements of these 100 000 objects

    -- Data object --
    public class TestElement
    {
       private String name
       private int insertIndex
    ... and setters and getters for these fields
    }

    -- Db4o Configuration --

    Configuration config = Db4o.newConfiguration();
    config.objectClass(TestElement.class).objectField("insertIndex").indexed(true);
    config.optimizeNativeQueries(true);
    config.queries().evaluationMode(QueryEvaluationMode.SNAPSHOT);


    -- SODA: query --
    Constraint cons = query.constrain(TestElement.class);
    query.descend("insertIndex").orderDescending();


    -- Results--
    Execution time:1500 – 2000ms / operation.
    Repeat same query again many times: execution times are the same

    -- Resource usege --
    100 % CPU usage.
    no any iowait


    With this query and this configuration, execution times are linear with objects in database. I hope that someone can show what is wrong with this case. Is there some kind of order by index available ... or something ... please help. Current response times and resource usage are too much for my application.

  •  07-19-2008, 07:56 AM 50222 in reply to 50221

    Re: Performance issues with order by

    Hi,

    any chance to restrict your object-set via an additional constraint? If I remember correctly, db4o doesn't use indices for ordering an object-set (at least this is true if the resulting object-set is too large).

    The following example (additional constraint is marked as bold) executes "your" query in about 2 milliseconds. Maybe your application can remember some kind of "watermark"-index for the last inserted items.

    Cheers, Maik

    import java.io.File;

    import com.db4o.Db4o;
    import com.db4o.ObjectContainer;
    import com.db4o.config.Configuration;
    import com.db4o.query.Query;

    public class OrderTest {

        private int index;

        public OrderTest(int index) {
            this.index = index;
        }

        public String toString() {
            return "" + index;
        }

        public static void main(String[] args) {
            new File("test.yap").delete();

            Configuration config = Db4o.newConfiguration();
            config.objectClass(OrderTest.class).objectField("index").indexed(true);

            ObjectContainer db4o = Db4o.openFile(config, "test.yap");
            for (int i = 0; i < 100000; i++) {
                db4o.store(new OrderTest(i));
            }
            db4o.commit();

            Query query = db4o.query();
            query.constrain(OrderTest.class);
            query.descend("index").constrain(99900).greater();
            query.descend("index").orderDescending();

            for (int i = 0; i < 20; i++) {
                long start = System.currentTimeMillis();
                System.out.println(query.execute().subList(0,10));
                System.out.println(System.currentTimeMillis() - start);
            }
           
            db4o.close();
        }
    }
     


    http://db4o.blogspot.com/
  •  07-19-2008, 02:08 PM 50224 in reply to 50222

    Re: Performance issues with order by

    Thanks,

    Good point.

View as RSS news feed in XML