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;

public void run(){
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) {


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("", "xxx");
Database db2 = session2.getDatabase("", "xxx");
DocumentCollection col1 = db1.getAllDocuments();
DocumentCollection col2 = db2.getAllDocuments();
Looper looper1 = new Looper(col1);
Looper looper2 = new Looper(col2);
time1 += looper1.time + looper2.time;

db1 = session1.getDatabase("", "xxxx");
db2 = session1.getDatabase("", "xxxx");
col1 = db1.getAllDocuments();
col2 = db2.getAllDocuments();
looper1 = new Looper(col1);
looper2 = new Looper(col2);
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. 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 ...... 
  2. 02/05/2019Toro Yard Equipment - Not really a premium brand as far as I am concernedDear Toro Customer Service, I arm writing about the following machine: Toro Power Max 1120 OXEModel:38654S/N:31000#### Specifically, bearing part #:63-3450 This is the part ($15 online / $25 at the local dealer) that caused me to raise my objections on-line. This piece of garbage is supposed to be a bearing. It carries the shaft which drives both stages of the auger. The shaft passes through the bearing (which is what bearings do) after the auger drive pulley as the shaft goes through the back (engine ...... 
  3. 10/08/2018Will you be at the NYC Launch Event for HCL Domino v10 -- Find me!Come find me in NYC on Wednesday at the Launch Event if you're there. I really do want to talk to ...... 
  4. 09/04/2018With two big projects on hold, I suddenly find myself very available for new short and long term projects.  
  5. 07/13/2018Who is HCL and why is it a good thing that they are now the ones behind Notes and Domino? 
  6. 03/21/2018Domino Apps on IOS is a Game Changer. Quit holding back. 
  7. 02/15/2018Andrew’s Proposed Gun Laws 
  8. 05/05/2016Is the growing social-sourced economy the modern back door into socialism? 
  9. 04/20/2016Want to be whitelisted? Here are some sensible rules for web site advertising 
  10. 12/30/2015Fantastic new series on Syfy called “The Expanse” – for people who love traditional science fiction 
Click here for more articles.....

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

Please wait while your document is saved.