Scripting Performance Best Practices
Scripting Performance Best Practices
Maximo scripting can significantly impact system performance because script code, like custom Maximo code, is compiled to Java bytecode and executed in the same thread as other Maximo logic. Poorly written scripts can cause issues such as excessive processing or memory use. Mitigation practices include choosing appropriate launch points, avoiding unnecessary object initialization events, managing script execution orders at launch points, and checking logging levels before executing log statements .
Costly initialization in Maximo scripting should be restricted to necessary UI contexts to prevent unnecessary resource usage. For example, costly operations should only be executed when initializing from the main tab of the UI, not from a list tab, which can be achieved by checking the current UI context using psdi.common.context.UIContext methods, and conditionally executing initialization based on these checks .
Logging in Maximo scripting is essential for debugging and monitoring but can negatively impact performance, particularly if logs are written without checking whether logging is enabled. When logging is disabled but log statements still execute attached computations, such as MboSet.count(), it wastes resources. Therefore, scripts should check the logging level before performing log operations, thereby preserving performance .
Recent updates, such as starting with Maximo version 7.6.1.2, introduced a function in the ‘service’ variable that facilitates checking if logging is enabled more easily within scripts. This enhancement aids in reducing performance impacts by preventing unnecessary log computations when logging is disabled, which reflects a shift towards more efficient scripting practices .
Selecting the correct launch point is critical because it determines the conditions under which a script is executed, thereby directly affecting performance. Using the Object Launch point (OLP) Init event for attribute initialization, for example, can lead to performance issues when applied unnecessarily to all members of an MboSet. Instead, using an Attribute Launch Point which initializes values only when needed, reduces unnecessary executions .
The Maximo Mbo framework automatically releases MboSets created as related sets to the launch point or related Mbo after a transaction is complete. However, if an MboSet is created using MXServer.getMXServer().getMboSet(), script authors are responsible for manually cleaning up these MboSets using a try-finally block to prevent memory leaks and eventual Out-Of-Memory (OOM) errors .
Platform developers should aim to reduce dependency conflicts by consolidating multiple scripts into a single script where feasible. If scripts must remain separate, developers should ensure no interdependencies in execution order to prevent issues due to the unordered nature of event firing in Maximo's event map. This approach prevents execution conflicts and ensures consistent script behavior .
Attaching multiple scripts to the same launch point can lead to complications due to the unordered firing of events. This can cause issues if the scripts have dependencies on each other or require execution in a specific order, as the lack of order can disrupt expected behaviors. It is advised to combine scripts where possible or ensure independence between them to avoid such conflicts .
Calling MboSet.count() multiple times in a script is inefficient because each call executes an SQL statement, which can degrade performance. This can be avoided by assigning the count to a variable once and reusing it in later code, thereby reducing redundant SQL executions and improving script efficiency .
Proper management of transactions in Maximo scripting is crucial because scripts should ideally be part of the encompassing Maximo transaction. Issues arise when scripts call save within a transaction, causing disruptions in event firing and transactional integrity. Additionally, creating MboSets using MXServer.getMboSet() outside of the normal transaction flows can lead to disjointed transactions unless explicitly added to the transaction. This can result in incomplete updates or inconsistencies .