What's really interesting here are two distinct findings:
1. There is no question that two threads hitting different databases pretty hard at the same time, run more than twice as fast as both threads using the same session. In fact, there is a 125% difference -- wow.
2. Maybe even more interesting, is that while there was virtually no difference when doing this on one thread at a time -- in fact it was faster IN TOTAL to do it sequentially than on distinct threads.
Note: This was done on a single processor machine. It will be interesting to run this on a dual processor and see the difference. What accounts for the nearly 20% increase in time to do the same thing in two threads? Is it really just thread overhead from the time slicing? Could it be contention for the network resources? I'll report back when I've had a chance to try this on "Northstar" -- a dual processor machine.
Here's the test:
Two threads, each doing a loop to 50 of collection.getnextdocument(). In test 1 the threads run at the same, while in test 2 they run one after the other (which was done by moving the join() method on the first loop to happen before the second loop was started.
Each test runs 10 times, alternating between the two threading conditions and adding the total times to avoid minor server busy issues.
Time1 -- Each databases is accessed
through its own session.
Time 2 -- Both databases are accessed
through the same session.
Test 1 TOTALS: Time1: 50,780ms Time2: 124,678ms
Test 2 TOTALS: Time1: 41,124ms Time2: 41,468ms
* Yes, I ran the tests several times and these results are consistant and representative. Don't be believe me? Here's some code. Just plug in your own server, username, and password, and databases.
/**
* @author andrewp
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import lotus.domino.*;
import java.util.*;
class Looper extends Thread {
DocumentCollection col;
long time = 0;
Looper(DocumentCollection col){
this.col = col;
start();
}
public void run(){
try{
Document doc1 = col.getFirstDocument();
Calendar begin = Calendar.getInstance();
Document doc = col.getFirstDocument();
for(int x = 0 ; x < 50; x ++) {
doc = col.getNextDocument(doc);}
Calendar end = Calendar.getInstance();
time += (end.getTimeInMillis() - begin.getTimeInMillis());
System.out.println("Time: " + (end.getTimeInMillis() - begin.getTimeInMillis()));
}catch(Exception e){
System.out.println(e.getClass().getName() );
System.out.println(e.getClass().toString() );
System.out.println(e.toString()) ;
}
}
}
public class TestClass {
public static void main(String[] args) {
try{
Session session1 = NotesFactory.createSession(
"xxxxxx", "xxx", "xxxx");
Session session2 = NotesFactory.createSession(
"xxxxx", "xxxx", "xxxx");
System.out.println(session1.hashCode() + " -- " + session2.hashCode());
System.out.println(session1.isValid() + " -- " + session2.isValid());
long time1 = 0;
long time2 = 0;
for(int z = 0; z < 4 ; z++) {
Database db1 = session1.getDatabase("www.thenorth.com/thenorth", "xxx");
Database db2 = session2.getDatabase("www.thenorth.com/thenorth", "xxx");
DocumentCollection col1 = db1.getAllDocuments();
DocumentCollection col2 = db2.getAllDocuments();
Looper looper1 = new Looper(col1);
Looper looper2 = new Looper(col2);
looper1.join();
looper2.join();
time1 += looper1.time + looper2.time;
db1 = session1.getDatabase("www.thenorth.com/thenorth", "xxxx");
db2 = session1.getDatabase("www.thenorth.com/thenorth", "xxxx");
col1 = db1.getAllDocuments();
col2 = db2.getAllDocuments();
looper1 = new Looper(col1);
looper2 = new Looper(col2);
looper1.join();
looper2.join();
time2 += looper1.time + looper2.time;
}
System.out.println("(TOTALS) Time1: " + time1 + " Time2: " + time2);
} catch(Exception e){
System.out.println(e.getClass().getName() );
System.out.println(e.getClass().toString() );
System.out.println(e.toString()) ;
}
}
}
Comment Entry |
Please wait while your document is saved.