Lotuscript for large systems
-
Upload
bill-buchan -
Category
Documents
-
view
678 -
download
0
description
Transcript of Lotuscript for large systems
![Page 1: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/1.jpg)
LotusScript Survival Tips for Large Systems
Bill Buchanhadsl.com
![Page 2: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/2.jpg)
• Introduction
• What do we need?
• Logging
• Performance
• Code Reuse
• Weirdness
Agenda
![Page 3: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/3.jpg)
• I am:
• Bill Buchan, CEO, hadsl
• LotusScript expert since 1997, Large systems experience
Introduction
![Page 4: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/4.jpg)
Direction?
• Lets consider the following slide...
![Page 5: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/5.jpg)
Whats New In LotusScript?
This page is left intentionally blank
![Page 6: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/6.jpg)
Whats new in LotusScript?
• The Class libraries have generally grown with each release
• Leveraging feature-specific stuff such as ID Vault in 8.5.0
![Page 7: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/7.jpg)
What does this mean?
• LotusScript is still an invaluable tool in your armoury for creating Business Logic
• Its easy, its multi-platform
• Its NOT the future in terms of Client or Web
• Check out all the xPages sessions here
• No excuses
![Page 8: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/8.jpg)
What do we need?
• Large environments need:
• Stability
• Scalability
• If you cant measure it, you cant manage it
• You want to do more, with less time and less people
![Page 9: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/9.jpg)
What do we need?
• Stable performance
• We cant keep adding new servers every time we add a new application/database instance
• We cant let a single application wreak havoc on our systems
![Page 10: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/10.jpg)
What do we need?
• Code Reuse. Of course.
• We have less resources doing more work
• We need to test more effectively
![Page 11: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/11.jpg)
Logging
• Why do logging?
• As a rule of thumb, if its scheduled, critical, or running in someplace you cant immediately check, you need logging
• You need to know:
• When and where did it start, stop
• Was it successful
![Page 12: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/12.jpg)
Logging
• If something happens, and you find out from the users
• You have failed
![Page 13: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/13.jpg)
Logging
• Lots of solutions available
• For instance, use ‘msgbox’ to log to the console.
• Admins hate this
• It’ll never be acted upon
![Page 14: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/14.jpg)
Logging Solutions
• Check out OpenLog at OpenNTF
• Add two lines of code, and you have a comprehensive log
• Free and Easy
• No excuses
![Page 15: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/15.jpg)
SuperLogging
• Consider Performance
• Opening a notes database - even from Script - opens the default view
• Log database views can get large
• It can be slow
![Page 16: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/16.jpg)
SuperLogging
• Why not
• Create a new document and populate as normal
• Stamp it with start and stop times - handy for measuring load
• Add Server, Database, Agent and User
• But then use notesdocument.send()
![Page 17: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/17.jpg)
SuperLogging
• Sending log documents by email means:
• The process is not waiting for you to save the log document (and update the views) - huge performance increase
• The log database need not be local
• The user processes do NOT need access to the log database
![Page 18: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/18.jpg)
SuperLogging
• Once you start emailing in Log Documents, you can do more:
• Spot when agents DONT trigger a log document - and do something about it
• Spot when NEW agents start creating logs
![Page 19: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/19.jpg)
SuperLogging
• Remember, ALL code has to log accurately
• LotusScript, Java, xPages
• Javascript?
![Page 20: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/20.jpg)
Performance
• We application developers can create fantastic applications
• And we can create horrible ones
• Ones that really kill servers.
• Lets talk about...
![Page 21: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/21.jpg)
Performance:Views
• Your application needs views. Of course it does. But does it need them all?
• ‘Click-sort’ columns are evil
• Use more ‘Categorised’ views
![Page 22: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/22.jpg)
Performance:Views
• How can I tell the size of a view?
• Admin client, select database, Tools, Manage Views
![Page 23: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/23.jpg)
Performance:Views
![Page 24: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/24.jpg)
Performance:Views
![Page 25: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/25.jpg)
Performance:Views
• Create as few views as possible
• Don’t use Click-sort on columns unless absolutely necessary. Each click-sort column creates another copy of the view
![Page 26: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/26.jpg)
Performance:Agents
• Scheduled Agents have to be well-behaved
• Agent Manager doesn't really do a great job in killing runaway agents
• It certainly doesn't throttle agents which consume lots of CPU
• And it only runs one or two agents at a time
![Page 27: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/27.jpg)
Performance:Agents
• So how to we minimise our Agent Footprint?
• Write them to fit the potential size of your application
• If there are lots of documents to process, let the agent run multiple times
![Page 28: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/28.jpg)
Performance:Agents
• Use Agent Profiling to find out how long your agents take against a representative quantity of documents
• ‘It worked in testing’ is not an excuse.
• Its an admission your testing wasn’t rigorous enough
![Page 29: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/29.jpg)
Performance:Agents
• To enable Agent Profiling, check the ‘Profile This agent’ in Agent Properties.
• Once its ran, you can view which calls its made, and how much time it took
![Page 30: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/30.jpg)
Performance:Agents
![Page 31: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/31.jpg)
Performance:Agents
• You can see
• When the agent ran
• Where it ran
• Where it spent time
• Invaluable for performance tuning
![Page 32: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/32.jpg)
Performance:Agents
• Now. Lets take it one step further
• How about collecting ALL agent profiles from ALL databases and storing them in a database?
• NOT recommended for production environments
![Page 33: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/33.jpg)
Performance:Agents
• Recipe:
• Take ‘TriggerHappy’ from OpenNTF
• Have it listen to ALL document saves on the server
• If the form is called "$BEProfileR7"
• Forward the document to another database
![Page 34: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/34.jpg)
Performance:Agents
• For more information on this, visit:
• http://www.billbuchan.com/imported-20091119232548/2010/2/2/universal-agent-profiling-in-domino.html
• URL is in IBM Standard Download Notation.
![Page 35: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/35.jpg)
Performance:Agents
• A common scenario
• We build an agent to examine a lot of documents, and update a few of them, every night.
• The database grows
• Your admin kills you.
![Page 36: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/36.jpg)
Performance:Agents
• Remember:
• Agent Manager is like a crumbly old relative - Everyone loves him
• But he’s quite shaky on his feet
• And smells
• Don’t abuse him
![Page 37: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/37.jpg)
Performance:Agents
• Changing the maximum agent run-time on the server document is CHEATING
![Page 38: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/38.jpg)
Performance:Agents
• Re-architect the agent
• It starts up, figures out how long it has to run, and works out its termination time.
• Maximum time minus 2 mins
• Keep working till expiry time
• Have the agent run a few times - say every 10 mins for 3 hours overnight
![Page 39: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/39.jpg)
Performance:Agents
• So:
• Own & Understand your agent performance
• Don’t abuse agent manager
• Don’t let it kill your system
![Page 40: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/40.jpg)
Code Re-use
• Don't reinvent the wheel every time
• That leaves far too little time for the pub
• Oh - and it means re-testing from scratch every time
• Be Lazy
![Page 41: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/41.jpg)
Code Re-use
• So
• If your an old-fashioned script guy, create a standard script library that encapsulates:
• Standard Logging
• Configuration lookup
![Page 42: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/42.jpg)
Code Re-Use
• If your a little bored with this (and who isn't?)
• Create a LotusScript class which encapsulates all boring logic
• Extend this class in your own code for the business logic
• Simplify the target code
![Page 43: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/43.jpg)
Code Re-use
• For example:
class baseClassPublic Sub logMsg(msg as String)
‘ do stuffend sub
public sub raiseError()‘ do stuff
end subend class
![Page 44: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/44.jpg)
Code Re-use class myLogicClass as baseclass
Private Function myStuff(waffle as String)on error goto errorhandler
call logMsg(“hello world”)
‘ Do stuffexitFunction:
exit function errorhandler:
call me.raiseError()resume exitFunction
end functionend class
![Page 45: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/45.jpg)
Code Re-use
• Remove the responsibility for
• Logging
• Error handling
• Other boring stuff
• From your business logic
![Page 46: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/46.jpg)
Weirdness
• Sometimes, we have to walk on the wild side
• Just sometimes, we like to stroke our misshapen little ego
• Or we actually have a business reason
• Whatever
![Page 47: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/47.jpg)
Weirdness: Lists• Use lists - they’re not hard.
Dim Pres list as StringPres(“George”) = “Bush”Pres(“Bill”) = “Clinton”
Print “Georges’s last name is: “ + Pres(“George”)if not isElement(Pres(“Chad”)) then _print “Chad wasn’t found”
forall thisPres in Pres Print listtag(thisPres) + “ “ + thisPresend forall
![Page 48: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/48.jpg)
Weirdness:C-API
• LotusScript never does everything. Sometimes you have to call out to C-API
• What is C-API?
• Over 700 functions that you can get to using C code
• Downside: Creating & Supporting code on every platform you support. Eugh.
![Page 49: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/49.jpg)
Weirdness: C-API
• So how can the lazy programmer call C-API functions from LotusScript?
Declare Function W32_NSFGetServerLatency Lib LIB_W32 Alias {NSFGetServerLatency} (_Byval ServerName As Lmbcs String, _Byval Timeout As Long, _retClientToServerMS As Long, _retServerToClientMS As Long, _ServerVersion As Integer) As Integer
![Page 50: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/50.jpg)
Weirdness: C-API• Now lets exploit this declaration
Public Function getServerLatency _ (strServer As String) As LongDim nnServer As New NotesName(strServer) Dim ToServer As Long, fromServer As Long Dim ver As Integer Dim timeout As Longtimeout = 1000' 1000ms == 1 second
Call W32_NSFGetServerLatency(nnServer.Canonical,_ timeout, _toServer, fromServer, ver)
' Return both directional latencies added togethergetServerLatency = fromServer + ToServerEnd Function
![Page 51: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/51.jpg)
Weirdness: C-API
• Now do this for every function, and every platform you wish to support.
• Euch
![Page 52: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/52.jpg)
Weirdness: Execute
• You all know how to do ‘Evaluate’ right?
Dim V as variantV = evaluate( “ @Name( [CN]; @UserName ) “ )print V(0)
‘ Result is ‘Bill Buchan’
![Page 53: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/53.jpg)
Weirdness: Execute
• Boring. Lets write some code to write some code
Dim S as StringS = “ msgbox | Hello World | “V = execute ( S )
![Page 54: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/54.jpg)
Weirdness: Execute
• What is this doing?
• We can populate a string with valid Lotusscript Code
• And then execute it.
• Why on earth would this be useful?
• We could, for instance, generate our platform specific C-API calls
![Page 55: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/55.jpg)
Weirdness: C-API
• Check out the ls2capi.com web site
• And check out my ls2capi database on
• http://hadsl.com/hadsl.nsf/Documents/LS2CAPI+-+Calling+Notes+C-API+from+LotusScript!OpenDocument
• Step through it in the debugger.. ;-)
![Page 56: Lotuscript for large systems](https://reader036.fdocuments.net/reader036/viewer/2022062615/547e1da15906b5b0718b467d/html5/thumbnails/56.jpg)
Conclusion
• Use these techniques to deal with large systems
• Minimise, Simplify and Productionalise your code
• Learn xPages