IBM®
Skip to main content
    Country/region select      Terms of use
 
 
   
     Home      Products      Services & solutions      Support & downloads      My account     

developerWorks  >  Lotus  >  Forums & community  >  Best Practice Makes Perfect

Best Practice Makes Perfect

A collaboration with Domino developers about how to do it and how to get it right in Domino

The saga continues; Johannes writes:

I'm not an expert on performance. It requires a lot spare time for testing and I think it's more fun to code, but I attended a presentation on the subject ... and one of the conclusions I remember was that if you compare the performance of a @Formula agent with a similar agent in LotusScript, the @Formula agent will perform much better. I think it would run twice as fast on large amounts of data, and this was with R4 or R5 and we all know that the @Formula interpreter was totally recoded (and made even more efficient) for R6.

I love this kind of stuff, so I decided to do a test. I took a local database containing 2400 documents that use a particular form ("Pirate"), and a few documents that use a different form. In about 20% of the documents, the field "Job" contains the value "Scurvy Dog". I wrote five agents and ran them each a few times for average timing. Each of these agents does the same task: it locates all the documents that use the "Pirate" form where the Job field contains "Scurvy Dog", and assigns a numeric value to the Ranking field. Each agent assigns the same Ranking value to all the documents it processes, but each one assigns a different value, so that as I run each one in turn, they are actually making a change to the documents. Here are the different approaches I tried:
Agent description / Execution time: Code:
A. The Johannes Method (run on All documents) Document selection: none
9.47s SELECT Form = "Pirate" & Job = "Scurvy Dog";
FIELD Ranking := 5;
B. Formula agent with search (run on All documents) Document selection: ([Form] = "Pirate") and ([Job] = "Scurvy Dog")
5.23s
Note that this was mostly the time to update the full-text index, since the agent that just ran before this one, modified hundreds of documents. Since the FT index is kept pretty up to date, this task would take less time in a more typical situation: fewer documents would need indexing. Also note that if the database is on a server, the server does the indexing task without having to send document data to the client, whereas if the A agent runs on the workstation, it must read all the document data from the server.
SELECT @All;
FIELD Ranking := 4;
C. LotusScript agent with search, StampAll (run on All documents) Document selection: ([Form] = "Pirate") and ([Job] = "Scurvy Dog")
3.91s
Of course, normally StampAll is not going to be useful, because it's seldom that assigning a constant value to one field is all you need to do. But when it works, it's speedy!
Sub Initialize
        Dim session As New notessession
        Dim db As NotesDatabase
        Dim coll As NotesDocumentCollection
        Set db = session.CurrentDatabase
        Set coll = db.UnprocessedDocuments
        Call coll.StampAll("Ranking", 3)
End Sub
D. LotusScript agent with search (run on All documents) Document selection: ([Form] = "Pirate") and ([Job] = "Scurvy Dog")
4.06s
The exact same task as B but in a different language, proving that formula language is really not faster than LotusScript for this task. I would agree it's faster for form actions and the like, though, but in that case the performance difference is generally going to be too small to notice.
Sub Initialize
        Dim session As New notessession
        Dim db As NotesDatabase
        Dim coll As NotesDocumentCollection
        Set db = session.CurrentDatabase
        Set coll = db.UnprocessedDocuments
        Dim doc As NotesDocument
        Set doc = coll.GetFirstDocument()
        Do Until doc Is Nothing
                Call doc.ReplaceItemValue("Ranking", 8)
                Call doc.Save(True, False, True)
                Set doc = coll.GetNextDocument(doc)
        Loop
End Sub
E. LotusScript agent from view (run on None) Document selection: N/A
1.63s
I was surprised this was so quick. I'd been running the agents from that same view, so I tried switching to a different view, and that didn't make a difference in the timing. The view indexing task is a lot faster than full-text indexing.
Sub Initialize
        Dim session As New notessession
        Dim db As NotesDatabase
        Dim coll As NotesDocumentCollection
        Set db = session.CurrentDatabase
        Dim vu As NotesView
        Set vu = db.GetView("PiratesByJob")
        Set coll = vu.GetAllDocumentsByKey("Scurvy Dog")
        Dim doc As NotesDocument
        Set doc = coll.GetFirstDocument()
        Do Until doc Is Nothing
                Call doc.ReplaceItemValue("Ranking", 12)
                Call doc.Save(True, False, True)
                Set doc = coll.GetNextDocument(doc)
        Loop
End Sub

I emphasize, I think it's best to go with the simplest approach if performance is not an issue, but in cases where it does matter, knowing about these different approaches and their relative merits can be the difference between meeting your design goal and not.

Andre Guirard | 12 April 2007 04:48:29 PM ET | Plymouth, MN, USA | Comments (15)

Search this blog 

Disclaimer 

    About IBM Privacy Contact