Jump to: navigation, search

Stardust/Knowledge Base/Performance Tuning/Write Behind

Introduction

 The Write Behind feature has been introduced for mainly STP-driven solutions characterized by high volume and throughput with the need for low latency. The basic idea around Write Behind is to write process run information as a batch asynchronously into the database, instead of doing it right away. Writing process run information synchronously creates a lot of contention on sequence retrieval and redo logs, which can’t be much reduced / optimized. Write Behind, however, dissolves such contention, since the number of database operations are optimized and reduced to a minimum. That way much more process instances can be completed within a given timeframe. Depending on complexity of the processes, multiple hundreds of process instances can be processed within a second. 

Prerequisites

There are two main preconditions that are important to keep in mind if process run information should be written asynchronously into the Audit Trail. Write Behind works if:

  1. A sequence-based database is used for the Audit Trail
  2. Processes can be completed from start to end within one transaction

The latter precondition is essential. If a process is not completed in one transaction, its current state will be written to the Audit Trail synchronously. A process cannot be completed in one transaction if:

  1. It includes a manual activity
  2. Sub-processes are invoked asynchronously
  3. Fork-On-Traversal flags have been defined explicitly
  4. JMS Request-/Response activities are used
  5. Activities are hibernated first after creation
  6. Processes define AND-Splits and/or AND-Joins
  7. Processes are triggered asynchronously.

Setting up Write-Behind

Download Files

  • Configure a JMS Queue called CarnotAuditTrailQueue.

    Add below bean to your Spring configuration and make sure you JMS provider does have this queue defined.

   <bean class="com.infinity.bpm.rt.integration.spring.jms.JmsResourceBinding">
       		 <property name="name" value="jms/CarnotAuditTrailQueue" />
   		 <property name="resource" ref="CarnotJmsAuditTrailQueue" />
   </bean>

    Remove customCarnotProperties bean from carnot-spring-context.xml and replace property carnotProperties of abstractCarnotService bean with below.

    <property name="carnotProperties">
                <map>
                       <entry>
                           <key>
                               <value>jms/CarnotXAConnectionFactory</value>
                           </key>
                         <ref bean="CarnotJmsConnectionFactory" />
                       </entry>
                       <entry>
                           <key>
                               <value>jms/CarnotAuditTrailQueue</value>
                           </key>
                         <ref bean="CarnotJmsAuditTrailQueue" />
                       </entry>
                       <entry>
                           <key>
                               <value>jms/CarnotApplicationQueue</value>
                           </key>
                         <ref bean="CarnotJmsApplicationQueue" />
                       </entry>
                </map>
     </property>
  • Add below properties to carnot.properties
  1. Write behind configuration &  Override sequence generator Setting
  1. JMS.ProcessTrigger.ThreadMode = synchronous
  2. Carnot.Engine.Tuning.SupportAsyncAuditTrailWrite = true
  3. Carnot.Engine.Tuning.SupportAsyncAuditTrailWriteViaJms = true
  4. Carnot.Engine.Tuning.SequenceBatchSize = 100
  5. AuditTrail.SequenceGenerator = ag.carnot.db.jdbc.sequence.FastCachingSequenceGenerator
  • Audit Trail Writer and DB changes
The Audit Trail Writer is the component that reads the JMS messages from the additional Queue and writes process  run information as batch into the Audit Trail. This component has to be adjusted to the project needs.  Attached(ipp-audittrail-writer.jar) is the sample implementation of the audit trail writer component.
Make  sure this jar ends up in the WEB-INF\lib folder and your "contextConfigLocation" parameter in web.xml has entry  classpath:META-INF/spring/*-context.xml. A scheduler Spring bean should automatically be started a couple of  seconds after server start and start reading message from AuditTrailQueue and write process run information into  Audit Trail Database. Gist of this component is the timer based scheduler that runs on a periodic basis to update  the DB with blob data that is picked from the CarnotAuditTrailQueue.
Execute the attached script "tweak-sequences" against your Audit Trail DB. Key here is the increment number in the SQL script should be same as the  Carnot.Engine.Tuning.SequenceBatchSize property specified in the carnot.properties.
 

        <bean name="processBlobFilingService" class="com.infinity.bpm.wb.spring.ProcessBlobFilingServiceBean">
		<property name="forkingService" ref="forkingService" />
	</bean>

	<bean id="processBlobFilingScheduler" class="org.springframework.scheduling.timer.TimerFactoryBean">
		<property name="scheduledTimerTasks">
			<list>
				<bean class="org.springframework.scheduling.timer.ScheduledTimerTask">
					<property name="delay" value="30000" />
					<property name="period" value="2000" />
					<property name="timerTask" ref="processBlobFilingTask" />

				</bean>
			</list>
		</property>
	</bean>

	<bean name="processBlobFilingTask" class="com.infinity.bpm.wb.spring.ProcessBlobFilingTask">
		<property name="filingService" ref="processBlobFilingService" />
	</bean>

Note: The script is for Oracle databases and Write Behind is working for sequence-based databases only. It has been tested for Oracle only at the moment. Delay in the timer schedule can be specified in the above spring config xml.

  • DB Schema changes
ALTER SEQUENCE activity_instance_seq INCREMENT BY 5000;
ALTER SEQUENCE activity_instance_log_seq INCREMENT BY 5000;
ALTER SEQUENCE act_inst_property_seq INCREMENT BY 5000;
ALTER SEQUENCE trans_inst_seq  INCREMENT BY 5000;
ALTER SEQUENCE trans_token_seq INCREMENT BY 5000;
ALTER SEQUENCE daemon_log_seq INCREMENT BY 5000;
ALTER SEQUENCE data_value_seq INCREMENT BY 5000;
ALTER SEQUENCE event_binding_seq INCREMENT BY 5000;
ALTER SEQUENCE log_entry_seq INCREMENT BY 5000;
ALTER SEQUENCE message_store_seq INCREMENT BY 5000;
ALTER SEQUENCE property_seq INCREMENT BY 5000;
ALTER SEQUENCE timer_log_seq INCREMENT BY 5000;
ALTER SEQUENCE usergroup_seq INCREMENT BY 5000;
ALTER SEQUENCE usergroup_property_seq INCREMENT BY 5000;
ALTER SEQUENCE user_seq INCREMENT BY 5000;
ALTER SEQUENCE user_property_seq INCREMENT BY 5000;
ALTER SEQUENCE wfuser_session_seq INCREMENT BY 5000;
ALTER SEQUENCE user_participant_seq INCREMENT BY 5000;
ALTER SEQUENCE user_usergroup_seq INCREMENT BY 5000;
ALTER SEQUENCE process_instance_seq INCREMENT BY 5000;
ALTER SEQUENCE proc_inst_property_seq INCREMENT BY 5000;
ALTER SEQUENCE structured_data_value_seq INCREMENT BY 5000;
ALTER SEQUENCE domain_seq INCREMENT BY 5000;
ALTER SEQUENCE domain_hierarchy_seq INCREMENT BY 5000;
ALTER SEQUENCE wfuser_domain_seq INCREMENT BY 5000;
ALTER SEQUENCE wfuser_realm_seq INCREMENT BY 5000;
ALTER SEQUENCE clob_data_seq INCREMENT BY 5000;
ALTER SEQUENCE model_seq INCREMENT BY 5000;
ALTER SEQUENCE STRING_DATA_SEQ INCREMENT BY 5000;
ALTER SEQUENCE partition_seq INCREMENT BY 5000;
COMMIT;

  • On server startup the timer based scheduler will run, once the process execution happens the process information in form of a BLOB structure will be written to the Database.
  • Sample output: Active-->Completed.
20:54:12 INFO [gScheduler] ProcessBlobFilingTask - 0 blob files to audit trail.
20:54:14 INFO [gScheduler] ProcessBlobFilingTask - 0 blob files to audit trail.
20:54:16 INFO [gScheduler] ProcessBlobFilingTask - 1 blob files to audit trail.
20:54:18 INFO [gScheduler] ProcessBlobFilingTask - 1 blob files to audit trail.
  • You can use any JMS based browser to view the messages that are posted in the custom queues.