Andrew Pollack's Blog

Technology, Family, Entertainment, Politics, and Random Noise

It is REALLY better for each Thread to have its own Notes Session object

By Andrew Pollack on 02/19/2004 at 05:10 PM EST

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()) ;
}

}
}


  • text bubble icon

    Security Review

    How secure is your Domino environment? A security review doesn't have to be expensive to be helpful. If you're interested in finding out more, Contact Me.
  • There are  - loading -  comments....

    wowBy jonvon on06/23/2004 at 11:21 AM EDT
    Comment Loading
    re: It is REALLY better for each Thread to have its own Notes Session objectBy Thomas on06/01/2007 at 03:42 AM EDT
    Comment Loading


    Other Recent Stories...

    1. 06/23/2009OpenNTF Licensing ChoiceOpenNTF should settle on the Apache Licensing. It allows IBM to consume OpenNTF released software for inclusion into the core product base -- which means really good stuff could get added in as default templates or parts of the mail file, etc. It also means developers can use Google code and other Apache Licensed software without worrying about being excluded from OpenNTF. As far as I'm concerned, if you don't agree, you're wrong -- and you should fork off (your own source tree) -- maybe call it ...... 
    2. 06/23/2009Web Developers and Artists -- What does a color really look like?The two images in the sample to the right - which LOOK like different colors, are not. they are the same web page and being displayed on the same computer with nearly the same settings. In both cases, the color is defined as "#15433D". [] The only difference, is that the one on top is shown in Firefox using the relatively little known feature introduced in version 3.x which uses the color profile configuration you have set up for your monitor when it renders images. These settings are ...... 
    3. 06/04/2009Product Review: Verizon's MiFiā„¢2200 Intelligent Mobile HotspotYou're not as connected as I am. If that's not true, you're a pretty unusually connected person. When I'm not in the office, I've used cellular tower based connections for several years. Originally it was just a cellular modem, then Verizon upgraded the network to "1xRTT" which gave speeds comparable to a dial-up line at home. EVDO came out and we boosted to the speed of a cheap DSL connection, and now with EVDO Rev A we can be connected almost anywhere with speeds nearly as good as any hotel or coffee ...... 
    4. 05/27/2009Second Signal - Starting to see the kind of growth I've been looking forward to 
    5. 05/26/2009Memorial Day 2009 - Slideshow of the parade, the marching band, the kids' bike parade, etc... 
    6. 05/21/2009Speaking at events that are not specific to our industry - Interesting Reaction 
    7. 05/19/2009Corporate Protectionism is as bad as the nationalistic kind 
    8. 05/17/2009Skippy, the Omega Dog! Freedom - thanks to the new "Dogwatch" fence 
    9. 05/17/2009This blog interrupted by the Lotus Design Partner Program 
    10. 04/24/2009Even more cool integration with the XLight FTP & SFTP Server to Domino - Upload/Download notificiations to the the Domino server 
    Click here for more articles.....


    pen icon Comment Entry
    Subject
    Your Name
    Homepage
    *Your Email
    * Your email address is required, but not displayed.
     
    Your thoughts....
     
    Remember Me  

    Please wait while your document is saved.