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

    Server Performance

    Are your servers underperforming? Just buying new boxes isn't the answer. If you want to get better performance from your existing servers, 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. 02/14/2010Great weekend sleddingI'm from "away" -- a term which in Maine speak means that I wasn't born here, and while I've been here for nearly 20 years I am very easily spotted as a non-native to pretty much anyone with long time family roots in the area. Being from away, there are things I just hadn't had a chance to do that most Mainer's take for granted. This weekend, I got the chance to scratch a few of those off the list. These included going 'upta camp', being significantly north of Bangor, and spending a fair bit of time on a ...... 
    2. 02/10/2010Is anyone really considering a move to a hosted Exchange system?I got this press release today from someone I really should learn to just ignore -- but I couldn't help myself. I actually read it. What struck me as the most odd set of statements in it focused on the idea that small and medium businesses are migrating away from Notes and into hosted exchange environments. In other words, that the move for small business into the cloud was somehow based on ISV's hosting off-site Microsoft Exchange mail servers for people. I suppose there must be some out there. This one ...... 
    3. 02/06/2010When does an application stop belonging to its owner?When an application becomes truly successful and people start relying on it for things they consider important, is there a point at which the application starts to belong to the owners? Facebook's latest change brings the topic to mind, but it can happen to you with internal applications as well. There comes a time when users begin to have a personal stake in the design of a good application. Facebook makes a great example for when your users really own your application. Its user base is both extremely ...... 
    4. 01/29/2010Lotusphere 2010 - Session Survey Results 
    5. 01/27/2010Is UPS just plain broken? * Updated 
    6. 01/25/2010My presentations posted here from Lotusphere 2010 
    7. 01/24/2010Me - in bobblehead form 
    8. 01/23/2010Announcing the C.U.L.T. Shirt 2010 Winner 
    9. 01/19/2010Great round table with Kristen Lauria about the Lotus Knows campaign 
    10. 01/19/2010The Review: Lotusphere 2010 – Opening General Session 
    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.