Thursday, March 19, 2015

IBM BPM Event Manager

The main function of the Event Manager is to guarantee scheduled execution of code. Thing to remember over here is that the Event Manager is not executing the code, but scheduling it with the corresponding Process Server. Any work scheduled by a specific Event Manager is run on the local Process Server. The Event Manager scheduler is used anytime an undercover agent (UCA) is invoked, but is also used for processing business process definitions (BPD) notifications, executing business process definition system lane activities, and executing business process definition timer events - it is not specific to TWEvents or to undercover agents.

All date times in the process database are written by the database and use the database servers’ time clock. All timer based executions (BPD timers, scheduled UCAs, task due dates are all triggered and alerted by the process server. The time clocks of the TeamWorks server and the database need to be in sync or events will not be processed properly.


Queues ::
First we need to understand Queues in order to understand Event Manager.
IBM BPM has two type of queue – Asynchronous (async) and Synchronous (sync). The Event Manager treats sync and async queues differently.

1.)    Sync Queues ::
Sync queues are executed serially. If you have multiple tasks set to run on one sync queue, they will execute one after the other in the order that they were put into the sync queue.
Each task in a sync queue must be executed in serial. To prevent problems in a cluster, an Event Manager claims ownership of one or more sync queues when it starts up. The ownership is stored in the LSW_UCA_SYNC_QUEUE where QUEUE_OWNER is linked to OWNER_ID in LSW_EM_INSTANCE.This is not a permanent assignment. The LSW_EM_INSTANCE table keeps track of status of all of the event managers. The status is checked every 15 seconds. If the owner of a sync queue is no longer available, another Event Manager takes ownership of that sync queue

2.)    Async Queues ::
Async queues are executed as soon as possible with no guaranteed order.
Async tasks are picked up by each Event Manager when there is room in their async queue for more tasks.





80EventManager.xml ::
Each process server has its own running Event Manager. The Event Manager is configured by each process server's copy of the 80EventManager.xml file:

Configuring Event Manager using 80EventManager.xml file
<enable>true</enable>
If this parameter set to true, the Event Manager is turned on for this process server instance. If you set this parameter to off, this process server has no event manager. Setting this parameter to false also disables the business process definition engine for this instance. This approach allows you to allocate process server instances for different duties. 

<start-paused>false</start-paused>
If this parameter is set to true, the scheduler for the Event Manager is started in a paused state. The Event Manager scheduler resumes if you specifically tell it to resume from the Event Manager Monitor console page, or if you click Resume All on that page.
Note: Pause/Resume always uses the Java Message Service (JMS) to send the request to the scheduler, even if you are pausing or resuming the web server to which you are connected. Pause/Resume is the only piece of the scheduler infrastructure that uses JMS - all other communication is done through the database.

<name>machine name</name>
This parameter is commented out, by default, and the host name is used instead. This parameter is used to populate the LSW_EM_INSTANCE table and names the Event Manager as viewed from the Event Manager monitor. If your host name is not descriptive for you, you can uncomment this parameter and use a name of your choosing. 

<heartbeat-period>15000</heartbeat-period>
<heartbeat-expiration>60000</heartbeat-expiration>
These parameters are used to determine which Event Manager instances are up and running. These parameters should not need to be changed.
The heartbeat is a separate thread that constantly updates the lsw_em_instance database table to tell other schedulers that it is alive. The heartbeat runs even if the scheduler itself is paused. The lsw_em_instance table drives the content in the top section of the Event Manager Monitor console. A scheduler whose expiration time is in the past is treated as disconnected. When this situation happens, the other schedulers assume that it is dead and pick ups any additional work as necessary. The heartbeat of a non-disabled scheduler will update the lsw_em_instance every <heartbeat-period> milliseconds (15 sec by default), and it sets its expiration to <heartbeat-expiration> milliseconds in the future (60 sec by default). This situation means that if a process server machine gets completely unplugged, it will take 60 seconds until the other schedulers recognize it as disconnected.

<loader-long-period>15000</loader-long-period>
For every loader long period, the Event Manager looks at each queue (sync and async) that it has access to and fills them to capacity. This scenario is sometimes referred to as a major tick.

<loader-short-period>2000</loader-short-period>
For every loader short period, the Event Manager looks through each of the queues that the Event Manager has and tries to fill them to capacity. Think of the loader long period as a sweep that fills the queue and the short period as the sweep that tries to fill any space that might be left over in the queue. This scenario is sometimes referred to as a minor tick.

<loader-advance-window>60000</loader-advance-window>
For scheduled tasks, this parameter specifies how far in advance the Event Manager looks for tasks.

<sync-queue-capacity>10</sync-queue-capacity>
This parameter specifies the number of tasks to fill for each sync queue that the Event Manager has acquired.

<async-queue-capacity>10</async-queue-capacity>
This parameter specifies the number of tasks to fill for each async queue that the Event Manager has acquired.

<bpd-queue-capacity>20</bpd-queue-capacity>
Business process definitions execute in their own async queue. The business process definition queue is used for timers firing, delivering messages to business process definition instances, and executing system lane tasks. This parameter is the queue depth for that queue.

<system-queue-capacity>10</system-queue-capacity>
The Event Manager has its own internal queue. This parameter is barely used and should not need to be changed.

<min-thread-pool-size>5</min-thread-pool-size>
This parameter specifies the minimum number of threads that the Event Manager should use.

<max-thread-pool-size>50</max-thread-pool-size>
This parameter specifies the maximum number of threads that the Event Manager can use.

The thread pool is not per queue; it is the total number of threads for that Event Manager instance in that particular Process Server Java virtual machine (JVM).
Note: Your total available database connections in the application server connection pool should be at least 2x this number. The number of connections on the actual database server needs to be at least the sum of the max connection pool for all nodes in the cluster.

<re-execute-limit>5</re-execute-limit>
This parameter specifies the maximum number of times to retry a failed task.

<kick-on-schedule>true</kick-on-schedule>
When this parameter is set to true, a newly-scheduled task forces the Event Manager into an immediate poll of lsw_em_task, to reduce the time between when a new task is scheduled and when it will be executed. This parameter helps with latency - a newly-scheduled "right now" task is executed almost immediately - but hurts overall throughput, because the TaskLoader ends up being more active than it would be otherwise. If the kick-on-schedule is false, newly-scheduled tasks are not picked up until the next time the Event Manager polls lsw_em_task (up to the loader-long-period), which will increase latency. However it also increases overall throughput by reducing the chatter and contention on the lsw_em_task table for a system with heavily loaded Event Manager, this parameter should be set to false.

<event-retry-interval>5000</event-retry-interval>
This parameter specifies the time between retries for failed tasks.

<task-execution-listener>com.lombardisoftware.server.scheduler.DbTaskExecutionListener</task-execution-listener>
This parameter is disabled by default. If the parameter is enabled, task history is maintained in the lsw_em_task_history table. You can then query this table to get the history of your tasks. Note: The product does not provide a way to display or clean up this data.

<sync-queue-controller-interval>5000</sync-queue-controller-interval>
This parameter specifies the time interval (milliseconds) the Sync Queue Controller wakes up and checks for Sync Queue jobs that need to be executed

Removing a stuck task -
Because sync queues only advance when a task completes, a poorly designed task can cause a sync queue to stop. If you do need to stop one, you can delete the task from the lsw_em_task table. You can then stop and start the Event Manager from the console to get things moving again.

Points to remember -
·         The Event Manager is quick and efficient. Usually it is the tasks it is executing that slows it down; not the Event Manager itself.
·         If you want to throttle the Event Manager, do not decrease the thread pool. Instead, decrease the queue capacity.
·         A sync queue can get stuck because it will not advance until the task completes. To help make this less of a problem, create multiple sync queues. You can manage sync queues in the Teamworks console.
·         All the time stamps used by the Event Manager scheduler - the heartbeat expirations and the task scheduled times - are interpreted relative to the system clock for the database machine. Thus, the scheduler does not require keeping the process server system clocks in sync. Keeping system clocks in sync is a good idea, however, for date-based tracking data, log analysis, and so on.

·         All time settings mentioned in 80EventManager.xml are in milliseconds.

Tuesday, December 16, 2014

IBM BPM Instrumentation Page - A very good way to Monitor IBM BPM


Instrumentation Explained for IBM BPM.

What is Instrumentation?
How to use Instrumentation?
What all we can monitory using Instrumentation?

If you have above or similar kind of question, you should visit the post written by  Sergei Malynovskyi in BP3 Portal. It is really well written post.

Best thing to take from the post is how to see extended data in instumentation monitor page. 

If you dont know it already, it will open whole new world of monitoring you can do for IBM BPM. You can also visit below Tech Note for more details.





Sunday, November 2, 2014

Second Page of custom saved search result reset back to previous saved search's column and filter - IBM BPM Portal

Problem
Whenever we try to execute a custom search or quick search first page of result comes as expected but as soon as we click on second or any other page from pagination menu custom search gets back to default or last clicked saved search.

Solution 
We raised this issue with IBM and they came back with an IFix to solve this issue.
apparently this issue is related to cookie in local browser. whenever we click on second or any other page, it get redirected to the saved search that is related in cookie and search filter, sorting and column get details from saved search in cookie. 
To solve this problem, JR49440 Needs to be installed.

Go to, IBM Fix Central and find JR49440 related to your current IBM BPM version.
More details can find in below tech-note


Monday, June 9, 2014

EXECUTION_STATUS column in LSW_BPD_INSTNCE table

You need to query the database to get the status of your business process definition (BPD) instances. What is the meaning of the EXECUTION_STATUS field in the LSW_BPD_INSTANCE table?

Flag Meaning
1 The BPD instance is active.
2 The BPD instance has completed.
3 The BPD instance has failed. Look at the ERROR and ERROR_STACK_TRACE for further details.
4 The BPD instance has terminated.
5 The BPD instance did not start because its message event condition returned false.
6 The BPD instance is suspended,

Thursday, May 8, 2014

Pythagoras Cup - Greedy Cup


Was just surfing the youtube yesterday and found below. Really interesting.
Hope you like it.




Friday, April 4, 2014

UCA disappearing from Event Monitor or Corrupted UCA problem in IBM BPM - Solved

Problem Description - 
==============
Facing issues with Event Monitor related to UCA scheduling , its behaving weird the entries are randomly disappearing from the scheduler .

Even after re-enabling(checking unchecking from the application side) , the UCA appear in event Monitor for short time and disappear after one run or after some time.

Reason for Problem -
=============
When a time-based UCA is scheduled, an event manager task in the
LSW_EM_TASK table and two keywords in the LSW_EM_TASK_KEYWORDS 
table are created. These keywords are 'UCA4.<uca-id>' and 
'scheduledExec'. On rare occasions, you might see event manager 
tasks for time-based UCAs that have only the 'scheduledExec' 
keyword. When a UCA is rescheduled, the keywords are used to 
delete the previous event manager task.  However, having only 
the 'scheduledExec' keyword for a particular UCA could cause all 
other time-based UCAs to be deleted during the rescheduling 
process.
In our case we believed reason for this problem was due to our DB file system was running at 100% at couple of times.

Solution -
======
The proposed solution is to manually delete the corrupted task from the database. This must be done carefully in order to not corrupt the whole database. The following queries should be executed at times     
where they do not interfere with the scheduling time of the UCA, i.e. not at full hours, or 5,15,25,35,45 or 55 minutes after full hours or you UCA is about to get executed.

There are can be two type of problem as one of the keyword for perticular UCA is not present. I will explain both scenarios.

Scenario 1 -
------------
1.) Retrieve TASK_IDs for scheduled UCAs that have only the 'scheduledExec' keyword, but not the uca id keyword:

select task_id from lsw_em_task_keywords where keyword = 'scheduledExec' and task_id not in ( select task_id  from lsw_em_task_keywords where keyword like 'uca4%')


2.) Display description and ID of ucas returned by query2:  

select description,task_arguments_str from lsw_em_task where task_id in(select task_id from lsw_em_task_keywords where keyword = 'scheduledExec' and task_id not in ( select task_id  from lsw_em_task_keywords where keyword like 'uca4%'))

3.) If the result of query 2 shows only tasks with description "Execute UCA <UCA_Name> <Schedule>, on set schedule", then you can delete the corrupt UCA and keyword with the following queries:  

3.1) Delete corrupted lsw_em_task: 

delete from lsw_em_task where task_id in (select task_id from lsw_em_task_keywords where keyword = 'scheduledExec' and task_id not in (select task_id  from lsw_em_task_keywords where keyword like 'uca4%'))

3.2) Delete corrupted lsw_em_task_keyword:

delete from lsw_em_task_keywords where task_id in (select task_id from lsw_em_task_keywords where keyword = 'scheduledExec' and task_id not in (select task_id  from lsw_em_task_keywords where keyword like 'uca4%'))

Scenario 2 -
------------
1.) Retrieve TASK_IDs for scheduled UCAs that have only the  uca id keyword, but not the 'scheduledExec' keyword:

select task_id from lsw_em_task_keywords where keyword = 'uca4%' and task_id not in ( select task_id  from lsw_em_task_keywords where keyword like 'scheduledExec')


2.) Display description and ID of ucas returned by query2:

select description,task_arguments_str from lsw_em_task where task_id in (select task_id from lsw_em_task_keywords where keyword = 'uca4%' and task_id not in ( select task_id  from lsw_em_task_keywords where keyword like 'scheduledExec'))

3.) If the result of query 2 shows only tasks with description " Execute UCA <UCA Name>, on set schedule",then you can delete the corrupt UCA and keyword with the following queries:  

3.1)  Delete corrupted lsw_em_task:

delete from lsw_em_task where task_id in (select task_id from lsw_em_task_keywords where keyword = 'uca4%' and task_id not in (select task_id  from lsw_em_task_keywords where keyword like 'scheduledExec'))                                                       
                                                                        
3.2) Delete corrupted lsw_em_task_keyword:

delete from lsw_em_task_keywords where task_id in (select task_id from lsw_em_task_keywords where keyword = 'uca4%' and task_id not in (select task_id  from lsw_em_task_keywords where keyword like 'scheduledExec'))       

You could also only delete the corrupt task keyword with Query4. APAR JR47574 will then take care, that the associated UCA task is not executed and not rescheduled

Saturday, March 15, 2014

Changing Configuration in IBM BPM Configuration file usitn 100Custom.xml

In IBM BPM most of the configuration details are stored in 99Custom.xml file. There are lots of instances when you need to change this default settings/configuration to the customized one.
When ever you modify a server configuration,always make the changes to the 100Custom.xml file,not to the original configuration file.In this way , all customization's are captured in a single file and are readily available if you upgrade to a new version of IBM BPM. This is the recomanded process as it is very easy to rollback from here without forgetting what was the “out-of-box/Defualt“ value for the given parameter/tag.
For example, the 100Custom.xml and 99Local .xml files are stored in the profile root for the server, where the value is either process-center or process-server, depending on which server you are configuring.  

The configuration files in the ../config/ directories are loaded in numerical order. For example, the standard files are loaded in this order: 00Static.xml, 50AppServer.xml, 60Database.xml, 80EventManager.xml, 98Database.xml, 99Local.xml, 100Custom.xml. By default, the first time the element that is loaded, it will stick in the configuration. For example,  then the one in 99Local.xmlfile loads first, unless the merge attribute is set to replace.
According to explanation on above paragraph, you can create any file of your choice having customized tag which replaces the default configuration.

Using the 100Custom.xml file to add new configuration values or replace existing values
The 100Custom.xml file is designed to hold the customization and changes that you want to make to any of the configuration files. The idea is that if you do a fresh installation of a new version, you can simply drop in your existing 100Custom.xml file and all the changes that you have made are picked up and used instead of the default values that you want to put in the 100Custom.xml file.

For example, consider adding any additional columns or views for your task manager to the 
100Custom.xml file. Any tuning options, such as for the event manager in the 80EventManager.xml file, are appropriate to put in the 100Custom.xml file. Any changes to default values, such as your system lane user, should be made in the 100Custom.xml file.

Alternatively, if you are changing your database URLs (database name, database machine name, and so on) then consider making those changes directly to the 
98Database.xml file. This approach is because these values are written down correctly when you install a new version of the product. 

One note on the 
100Custom.xml file changes: When you move to a new version of the product, you always want to review the changes in the 100Custom.xml file to make sure that they are still appropriate in the new version. For example, some of the default settings or database queries that you use in customizing the Process Portal might change between releases. Other settings might no longer apply.

The merge attribute
When you load or replace values using the 100Custom.xml file, you need to be careful which merge setting that you use for each element. The "merge" attribute supports the following:
       "append" - This setting appends the new tag.
       "mergeChildren" - This setting merges the new tag with the first of the existing tags, which is the default behavior. In other words the "mergeChildren" setting merges a child element with the parent element. However, the "mergeChildren" setting does not merge a child tag if it does not have any attributes and that child tag only has text.
       "replace" - This setting replaces all old tags with this new tag.

You can see usage examples for the "append" and "replace" settings in the 
50AppServer.xml and 60DataBase.xml files, which overrides things in 00static.xml file depending on the database or application server.

For example, from the sample 
100Custom.xml file, you might want to change the <environment-name> value. In the 99Local.xml file you have something like the following code:
<properties>
...
 <common merge="mergeChildren">
   ...
 <environment-name>Environment_from_99Local</environment-name>
   ...
 </common>
   ...
 </properties>


To change the environment name in the 
100Custom.xml file, you might use the following code:

<properties>
<common merge="mergeChildren">
<environment-name merge="replace">Environment_from_100Custom
</environment-name>
</common>
</properties>
Making changes to configuration files for a network deployment cluster
For network deployment environments, XML configuration files on the cluster level are templates for XML configuration files that are created when new cluster members are added. If you make changes to the file at the cluster member level (PROFILE_ROOT\config\cells\cell_name\nodes\custom_node_name\servers\cluster_member_name\server_type\config\100Custom.xml), make the changes at the cluster level as well (PROFILE_ROOT\config\cells\cell_name\clusters\cluster_name\server_type\config\100Custom.xml). Making the changes to the templates at the cluster level ensures that the changes are also created on any new cluster member, if one is added in the future.
At run time, only the settings from cluster member files are read. If you make changes after deployment, you need to make them in the cluster member version of the file for each server to have the changes take effect at run time.
Always make changes to any of these XML configuration files on the deployment manager server using the following steps:
1.    Make changes to cluster members, when means that you need to change the XML file for each node. See the path name that is listed earlier in this section, but work in the deployment manager file system.
2.    Make changes to the cluster level to ensure that each new cluster is created with your customized settings.
3.    Select Full Resynchronize to replicate the settings from the deployment manager server to the individual nodes. If you edit these configuration files on an individual node, the changes might be lost in the next update.

Backing up configuration files
It is always a good idea to make a backup copy of the files that you are changing. However, these configuration files are one area where you need to use some caution when backing them up. Specifically, always change the extension from .xml when backing up these files. The following information explains why you want to change the file extension:

All of the files in the 
.../config directory ending in .xml are loaded by the product on startup. These files are loaded in an alphanumeric order; letters are loaded first and then numbers are loaded in numerical order. For example, if you have the following files in the ../config directory they are loaded in the order shown below:
.../config/system/Copy of 99Local.xml
.../config/system/00Static.xml
.../config/system/50AppServer.xml
.../config/system/60Database.xml
.../config/system/80EventManager.xml
.../config/system/98Database.xml
.../config/system/99Local.xml
.../config/100Custom.xml.

If you want to get more details and explanation about this topic and also about other configuration file, specially TeamWorksConfiguration.running.xml (which is merged file from all xml configuration file created when we start the server), you can go to below links which provides more details.