Environment sensitive Job Spawning
For faster results, we often execute programs in parallel using background jobs. Even though this might be a good idea in terms of processing efficiency, on many occasions this results in high utilization of the system resources and non-availability of background work processes for other key custom operations.
The below technique provides a controlled and conservative approach towards multiple/parallel job generation. With this technique, we can set a maximum utilization percentage and hence always reserve some work processes for other operations. The attributes like utilization threshold and delay can be input as a Parameter/Select-option in the program or can be maintained in selection variable table TVARVC or a custom table, but to keep it simple I am going to use this as constants in the program.
The key function that we use in this method is TH_GET_WPINFO which returns the details of the active work processes in the system. The function takes as input 2 optional parameters SRVNAME (Application server) and WITH_CPU. If the job processing has to be limited to a specific server on the system, these parameters can be used to limit the query and later submit the job to the specific server group. But if no restrictions need to be imposed in terms of servers, these can be left blank. The function returns the list of work processes in the system and is similar to SM50 screen (except for the fact that SM50 shows the work processes only from the server on which user is logged on to). Based on this information, we can determine the total and available work processes and the background work process utilization level. Based on the percentage, we can either generate the next job or wait for predefined amount of time and try again.
Utilization threshold : 60%
No. of jobs to be executed : 10
Wait before retry if utilization is too high : 10 seconds
“Assuming the utilization limit to be 60%
c_limit TYPE p DECIMALS 2 VALUE 60.
“Assuming a total of 10 jobs need to be generated
v_jobs TYPE i VALUE 10,
“Assuming a wait time of 10 seconds to be inserted
” if utilization is above limit
v_delay TYPE i VALUE 10.
lt_wplist TYPE TABLE OF wpinfo,
v_total TYPE i,
v_utilz TYPE i,
v_uperc TYPE p DECIMALS 2.
CALL FUNCTION ‘TH_GET_WPINFO’
* srvname = “Application server optional
* with_cpu = “CPU optional
wplist = lt_wplist
send_error = 1
OTHERS = 2.
IF sy-subrc = 0.
“Retain details of background work processes only
DELETE lt_wplist WHERE wp_itype NE 4.
DESCRIBE TABLE lt_wplist LINES v_total.
“Delete the work processes in Waiting state
DELETE lt_wplist WHERE wp_istatus = 2.
DESCRIBE TABLE lt_wplist LINES v_utilz.
v_uperc = v_utilz * 100 / v_total.
“If utilization is within set threshold, proceed
IF v_uperc LE c_limit.
“<Generate background job>
v_jobs = v_jobs – 1.
IF v_jobs = 0.
” If utilization crosses threshold, wait
WAIT UP TO v_delay SECONDS.
Please suggest alternate approaches you have used to handle similar situations at program level.