Luca,
I also have errors running the code from 'fabiopedrosa', I
modified his java file 'Main.java' slightly but and get errors
like:
"java.lang.Integer cannot be cast to java.lang.String"
the above seem to be the culprit. Note this message doesn't exist in
'fabiopedrosa's eror trace. See my version of Main.java (below)
and its associated error trace (which is quite different).
FYI, I too have lots of issues in getting working stand alone
Test programs to work especially those that uses indecies -
please refer to my prior Feb 22, 2011 post/thread - subject:
"Need more examples that are simple, easy, and standalone"
which remains unanswered.
Thus when I saw 'fabiopedrosa' code/question I thought I would
try to run/debug it. But once again I can not get things to work
as they should.
Hacking a bit, if I found that if I alter 'age' from an 'int' to a
'String'
then I can get most of his code to run, but it would fail on
OSQLSynchQuery - but if I further altered 'fabiopedrosa's query
block as follows:
from:
db.query(new OSQLSynchQuery<Customer>(
"select * from Customer where age = " +
rnd.nextInt(N))).get(0);
to:
ArrayList res = db.query(new OSQLSynchQuery<Customer>(
"select * from Customer where age = " + rnd.nextInt(N)));
if (res != null && res.isEmpty() == false) {
// System.out.println("" + res);
res.get(0);
}
I can get a clean run (but it is for 'age' being a 'String', I have
no idea why 'age' can not be an 'int' in the the way 'fabiopedrosa'
coded his initial class it seems straigtforward. For the version that
can actual run without an exception see Main2.java (below)
BTW Orient DB in this test case sure does not seem fast - I am
only able to query less than 10 items per second.
5.9 sec. to save [252.228 items/sec.] for 1,500 items
155.5 sec. to load [ 9.640 items/sec.] (i.e. query 1,500 items)
Best Regards,
Jon Strabala
--------------------------------------------------------------
My system a solaris 10 box on svn 0.9.25-SNAPSHOT of OrientDB:
--------------------------------------------------------------
orientdb# uname -a
SunOS orientdb 5.10 Generic_142901-11 i86pc i386 i86pc
orientdb# cat /etc/release
Solaris 10 10/09 s10x_u8wos_08a X86
Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
Use is subject to license terms.
Assembled 16 September 2009
orientdb# pwd
/OrientDB/svn/releases/0.9.25-SNAPSHOT/qsi/test2
--------------------------------------------------------------
I run "1.6.0_21" 32-bit java
--------------------------------------------------------------
orientdb# java -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
Java HotSpot(TM) Client VM (build 17.0-b16, mixed mode, sharing)
--------------------------------------------------------------
It appears 'fabiopedrosa' runs DOS, I run UNIX/Solaris 10
--------------------------------------------------------------
orientdb# grep ODatabaseObjectTx Main.java
// ODatabaseObjectTx db = new ODatabaseObjectTx("local:db\
\db");
ODatabaseObjectTx db = new ODatabaseObjectTx("local:/tmp/
lspeed");
--------------------------------------------------------------
remove OLD db file and run twice.
--------------------------------------------------------------
orientdb# rm -rf /tmp/lspeed
orientdb# java -ea -cp $MYCP Main
All deleted, 0 items
Exception in thread "main"
com.orientechnologies.orient.core.exception.ODatabaseException: Error
on saving record in cluster #-1
at
com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.executeSaveRecord(ODatabaseRecordAbstract.java:
479)
at
com.orientechnologies.orient.core.tx.OTransactionNoTx.save(OTransactionNoTx.java:
50)
at
com.orientechnologies.orient.core.db.record.ODatabaseRecordTx.save(ODatabaseRecordTx.java:
156)
at
com.orientechnologies.orient.core.db.record.ODatabaseRecordTx.save(ODatabaseRecordTx.java:
33)
at
com.orientechnologies.orient.core.db.ODatabaseRecordWrapperAbstract.save(ODatabaseRecordWrapperAbstract.java:
127)
at
com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.save(ODatabaseDocumentTx.java:
148)
at
com.orientechnologies.orient.core.db.object.ODatabaseObjectTx.save(ODatabaseObjectTx.java:
195)
at
com.orientechnologies.orient.core.db.object.ODatabaseObjectTx.save(ODatabaseObjectTx.java:
169)
at Main.main(Main.java:63)
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be
cast to java.lang.String
at java.lang.String.compareTo(String.java:92)
at
com.orientechnologies.common.collection.OMVRBTree.getEntry(OMVRBTree.java:
395)
at
com.orientechnologies.common.collection.OMVRBTree.getEntry(OMVRBTree.java:
347)
at
com.orientechnologies.common.collection.OMVRBTree.get(OMVRBTree.java:
272)
at
com.orientechnologies.orient.core.type.tree.OMVRBTreePersistent.get(OMVRBTreePersistent.java:
707)
at
com.orientechnologies.orient.core.index.OIndexMVRBTreeAbstract.get(OIndexMVRBTreeAbstract.java:
135)
at
com.orientechnologies.orient.core.index.OIndexUnique.checkEntry(OIndexUnique.java:
63)
at
com.orientechnologies.orient.core.index.OPropertyIndex.checkEntry(OPropertyIndex.java:
65)
at
com.orientechnologies.orient.core.index.OPropertyIndexManager.checkIndexedProperties(OPropertyIndexManager.java:
146)
at
com.orientechnologies.orient.core.index.OPropertyIndexManager.onRecordBeforeCreate(OPropertyIndexManager.java:
40)
at
com.orientechnologies.orient.core.hook.ODocumentHookAbstract.onTrigger(ODocumentHookAbstract.java:
68)
at
com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.callbackHooks(ODatabaseRecordAbstract.java:
568)
at
com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.executeSaveRecord(ODatabaseRecordAbstract.java:
427)
... 8 more
du -sk /tmp/lspeed
19164 /tmp/lspeed
orientdb# java -ea -cp $MYCP Main
Exception in thread "main"
com.orientechnologies.orient.core.exception.ODatabaseException: Error
on deleting record #5:0 of class 'Customer'
at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:
39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:
27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:
513)
at
com.orientechnologies.common.log.OLogManager.exception(OLogManager.java:
172)
at
com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.delete(ODatabaseDocumentTx.java:
161)
at
com.orientechnologies.orient.core.db.object.ODatabaseObjectTx.delete(ODatabaseObjectTx.java:
219)
at Main.main(Main.java:54)
Caused by:
com.orientechnologies.orient.core.exception.ODatabaseException: Error
on deleting record in cluster #5
at
com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.executeDeleteRecord(ODatabaseRecordAbstract.java:
510)
at
com.orientechnologies.orient.core.tx.OTransactionNoTx.delete(OTransactionNoTx.java:
57)
at
com.orientechnologies.orient.core.db.record.ODatabaseRecordTx.delete(ODatabaseRecordTx.java:
162)
at
com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.delete(ODatabaseDocumentTx.java:
158)
... 2 more
Caused by: java.lang.ClassCastException: java.lang.String cannot be
cast to java.lang.Integer
at java.lang.Integer.compareTo(Integer.java:37)
at
com.orientechnologies.common.collection.OMVRBTree.getEntry(OMVRBTree.java:
395)
at
com.orientechnologies.common.collection.OMVRBTree.getEntry(OMVRBTree.java:
347)
at
com.orientechnologies.common.collection.OMVRBTree.remove(OMVRBTree.java:
687)
at
com.orientechnologies.orient.core.type.tree.OMVRBTreePersistent.remove(OMVRBTreePersistent.java:
406)
at
com.orientechnologies.orient.core.index.OIndexMVRBTreeAbstract.remove(OIndexMVRBTreeAbstract.java:
269)
at
com.orientechnologies.orient.core.index.OPropertyIndexManager.onRecordAfterDelete(OPropertyIndexManager.java:
129)
at
com.orientechnologies.orient.core.hook.ODocumentHookAbstract.onTrigger(ODocumentHookAbstract.java:
82)
at
com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.callbackHooks(ODatabaseRecordAbstract.java:
568)
at
com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.executeDeleteRecord(ODatabaseRecordAbstract.java:
502)
... 5 more
du -sk /tmp/lspeed
19168 /tmp/lspeed
--------------------------------------------------------------
Failing source almost the same as 'fabiopedrosa's original
orientdb# cat Main.java
--------------------------------------------------------------
import java.io.File;
import java.util.Random;
import org.testng.annotations.Test;
import com.orientechnologies.common.profiler.OProfiler;
import
com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import
com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.intent.OIntentMassiveInsert;
import com.orientechnologies.orient.core.metadata.schema.OProperty;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.tx.OTransaction.TXTYPE;
import
com.orientechnologies.orient.test.database.base.OrientMonoThreadTest;
import com.orientechnologies.orient.core.db.object.*;
import com.orientechnologies.orient.core.sql.query.*;
import com.orientechnologies.orient.core.metadata.schema.OType;
import
com.orientechnologies.orient.core.metadata.schema.OProperty.INDEX_TYPE;
public class Main {
static Random rnd = new Random();
static class Customer {
String name;
int age;
public Customer() { }
public Customer(String name, int age) {
this.name = name;
this.age = age;
}
}
public static void main(String[] args) {
int cnt;
// ODatabaseObjectTx db = new ODatabaseObjectTx("local:db\
\db");
ODatabaseObjectTx db = new ODatabaseObjectTx("local:/tmp/
lspeed");
if (db.exists()) {
db.open("admin", "admin");
} else {
db.create();
}
db.getEntityManager().registerEntityClass(Customer.class);
db.getMetadata().getSchema().getClass(Customer.class).createProperty(
"age", OType.INTEGER).createIndex(INDEX_TYPE.UNIQUE);
cnt = 0;
for (Object obj : db.browseClass(Customer.class)) {
db.delete(obj);
cnt++;
}
System.out.println("All deleted, " + cnt + " items");
int N = 15000;
long startTime = System.currentTimeMillis();
for (int i = 0; i < N; i++) {
db.save(new Customer("name ", i));
}
System.out.println("Saving took " +
(System.currentTimeMillis() - startTime) + "ms");
startTime = System.currentTimeMillis();
for (int i = 0; i < N; i++) {
db.query(new OSQLSynchQuery<Customer>(
"select * from Customer where age = " +
rnd.nextInt(N))).get(0);
}
System.out.println("Loading took " +
(System.currentTimeMillis() - startTime) + "ms");
}
}
--------------------------------------------------------------
Working source altered age from 'int' to 'String'
orientdb# cat Main2.java
--------------------------------------------------------------
import java.io.File;
import java.util.Random;
import java.util.ArrayList;
import org.testng.annotations.Test;
import com.orientechnologies.common.profiler.OProfiler;
import
com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import
com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.intent.OIntentMassiveInsert;
import com.orientechnologies.orient.core.metadata.schema.OProperty;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.tx.OTransaction.TXTYPE;
import
com.orientechnologies.orient.test.database.base.OrientMonoThreadTest;
import com.orientechnologies.orient.core.db.object.*;
import com.orientechnologies.orient.core.sql.query.*;
import com.orientechnologies.orient.core.metadata.schema.OType;
import
com.orientechnologies.orient.core.metadata.schema.OProperty.INDEX_TYPE;
public class Main2 {
static Random rnd = new Random();
static class Customer {
String name;
String age;
public Customer() { }
public Customer(String name, String age) {
this.name = name;
this.age = age;
}
}
public static void main(String[] args) {
int cnt;
// ODatabaseObjectTx db = new ODatabaseObjectTx("local:db\\db");
ODatabaseObjectTx db = new ODatabaseObjectTx("local:/tmp/lspeed");
if (db.exists()) {
db.open("admin", "admin");
} else {
db.create();
}
db.getEntityManager().registerEntityClass(Customer.class);
db.getMetadata().getSchema().getClass(Customer.class).createProperty(
"age", OType.STRING).createIndex(INDEX_TYPE.UNIQUE);
cnt = 0;
for (Object obj : db.browseClass(Customer.class)) {
db.delete(obj);
cnt++;
}
System.out.println("All deleted, " + cnt + " items");
int N = 15000;
long startTime = System.currentTimeMillis();
for (int i = 0; i < N; i++) {
db.save(new Customer("name ", ""+i));
}
System.out.println("Saving took " +
(System.currentTimeMillis() - startTime) + "ms");
startTime = System.currentTimeMillis();
for (int i = 0; i < N; i++) {
ArrayList res = db.query(new OSQLSynchQuery<Customer>(
"select * from Customer where age = \"" + rnd.nextInt(N) +
"\"" ));
if (res != null && res.isEmpty() == false) {
System.out.println("" + res);
res.get(0);
}
}
System.out.println("Loading took " +
(System.currentTimeMillis() - startTime) + "ms");
}
}
--------------------------------------------------------------
Run the rwWorking source altered age from 'int' to 'String'
hmmm it is pretty slow .... so slow I lowered 'N' just to get
a number from 15,000 down to 1,500. I question whether the
search even begins to behave in a near linear fashion.
--------------------------------------------------------------
#----------------
# if N = 15000; // as per original code
#----------------
orientdb# java -ea -cp $MYCP Main2
All deleted, 0 items
Saving took 7453ms
^C
Killed the run as I got tired of waiting (about five minutes)
either the code hangs or it is massively slow and non-scalable.
7.5 sec. to save [2,012.612 items/sec.] for 15,500 items
???.? sec. to load [ ?.??? items/sec.] (i.e. query 15,000 items)
#----------------
# if N = 1500;
#----------------
orientdb# java -ea -cp $MYCP Main2
All deleted, 0 items
Saving took 5947ms
Loading took 155599ms
5.9 sec. to save [252.228 items/sec.] for 1,500 items
155.5 sec. to load [ 9.640 items/sec.] (i.e. query 1,500 items)
IMHO ... This is very very slow .... almost unusable slow