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

}
}


  • car icon

    On Site Training

    We can bring the same kind of top quality training you get at conferences right to your offices. If your team needs training in a single topic, or you want to do a whole series on site, we can put a mini-conference together just for your team. For more information, Contact Me.
  • There are  - loading -  comments....

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


    Other Recent Stories...

    1. 07/20/2010IBM has invented the time machine - and not in a good waySteve Mills is now in charge of both hardware and software. According to The New York Times.... The management changes, announced in an e-mail message to I.B.M. employees, were intended to improve the company’s products and services, Mr. Palmisano wrote. For example, computer hardware and software are for the first time being placed under the oversight of one executive......Increasingly, Mr. Palmisano wrote, computer systems must be “designed and brought to market as tightly integrated” packages of ...... 
    2. 07/18/2010A lot of work, but something I've always wanted to do -- Fixing up a car for one of my kidsOne of the things I've thought about for years and have always wanted to do, is to fix up a car for one of my kids. I'm not sure why, but its just something that I've thought about since they were really small. Of course, daydreams being what they are, the reality is never quite as grand in scale -- the 70's era muscle car turns out to be a 2002 Kia, and instead of an old pole barn to work in, the car is up on ramps in my driveway. Still, I'm really enjoying getting to do the work, being able to do the ...... 
    3. 07/13/2010Old Spice -- Their marketing team fully groks social media. You know the old spice guy (I'm on a boat)? I don't care for their products, but their ad people have gone social nuclear. Read this to see how they've totally "Got" social media promotion. ...... 
    4. 06/22/2010Product Review: Plantronics Savi Office wireless headset 
    5. 06/16/2010Ed Brill has a blog. Peter O'Kelly has blog... 
    6. 06/15/2010How about Traveler for Desktop? 
    7. 06/15/2010Why XPages is not LCD any more 
    8. 06/15/2010Fixing Domino Designer -  
    9. 06/14/2010Bandwagon: Why the decline in Notes seats, when the Domino server is still the best value on the marketplace? Here's why.... 
    10. 05/17/2010Unified Comunications Server? That ship sailed -- it's time to move on. 
    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.