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

}
}


There are  - loading -  comments....

wowBy jonvon on 06/23/2004 at 11:21 AM EDT
this is really interesting andrew, thanks for posting this stuff.
re: It is REALLY better for each Thread to have its own Notes Session objectBy Thomas on 06/01/2007 at 03:42 AM EDT
Hi thanks to your site we were able to confirm this odd behavior of
multithreaded agents.

Our research in this issue gave that multithreaded agents in Notes do in fact
run slower than sequential agents if no or only minor calculations besides the
notes API calls are done. If the calculations on the data are very
timeconsuming then the multithreaded model plays out its advantages.

If you had used Netbeans-Profiler you would have seen that the runtime of the
Notes-API calls are growing proportional to the number of threads.

This can only mean that the Notes-API is not reentrant at all and is heavily
synchronized to achieve multihreading safety.

I think that IBM does in fact have some homework to do on the C-API of Notes.


Other Recent Stories...

  1. 04/04/2020How many Ventilators for the price of those tanks the Pentagon didn't even want?This goes WAY beyond Trump or Obama. This is decades of poor planning and poor use of funds. Certainly it should have been addressed in the Trump, Obama, Bush, Clinton, Bush, and Reagan administrations -- all of which were well aware of the implications of a pandemic. I want a military prepared to help us, not just hurt other people. As an American I expect that with the ridiculous funding of our military might, we are prepared for damn near everything. Not just killing people and breaking things, but ...... 
  2. 01/28/2020Copyright Troll WarningThere's a copyright troll firm that has automated reverse-image searches and goes around looking for any posted images that they can make a quick copyright claim on. This is not quite a scam because it's technically legal, but it's run very much like a scam. This company works with a few "clients" that have vast repositories of copyrighted images. The trolls do a reverse web search on those images looking for hits. When they find one on a site that looks like someone they can scare, they work it like ...... 
  3. 03/26/2019Undestanding how OAUTH scopes will bring the concept of APPS to your Domino serverWhile a full description of OATH is way beyond what I can do in this quick blog entry, I wanted to talk a bit about how "SCOPES" interact with the already rich authorization model used by Domino. Thanks to the fantastic work by John Curtis and his team, the node.js integration with Domino is going to be getting a rich security model. What we know is that a user's authorizations will be respected through the node.js application to the Domino server -- including reader names, ACLs, Roles, and so on. The way ...... 
  4. 02/05/2019Toro Yard Equipment - Not really a premium brand as far as I am concerned 
  5. 10/08/2018Will you be at the NYC Launch Event for HCL Domino v10 -- Find me! 
  6. 09/04/2018With two big projects on hold, I suddenly find myself very available for new short and long term projects.  
  7. 07/13/2018Who is HCL and why is it a good thing that they are now the ones behind Notes and Domino? 
  8. 03/21/2018Domino Apps on IOS is a Game Changer. Quit holding back. 
  9. 02/15/2018Andrew’s Proposed Gun Laws 
  10. 05/05/2016Is the growing social-sourced economy the modern back door into socialism? 
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.