Skip navigation

In last article we mentioned that IT engineers from the Web Company used esProc to code program which could handle large data volume and complex requirements. Not only could it meet the demands for online time computation, but also is relatively easy to be extended to with new conditions.

 

However, these engineers found that the single-threaded program does not take full advantage of the of the server’s computing power. Practice has proved that the use of esProc’s multi-threading capability can take advantage of the server's quad dual core, or even more CPUs. The change from single-threaded to multi-threaded requires very little workload.

 

Let’s first review the recording of Weber's user behavior information. Data recorded in the log file. A daily log file, for example, following 2014-01-07.log file, record the operations log January 7, 2014 the day. If you want to calculate 2014-01-05 to 2014-01-11 This week long online, you need to read the log file from 7:

 

First, let’s review the way the user behavior information is recorded in the Web Company. Data was recorded in the log file. Everyday a separate log file is generated. For example, the following log file, “2014-01-07.log”, contains the users online actions on January 7, 2014. To compute the online time for user in the week of 2014-01-05 to 2014-01-11, we need to retrieve data from 7 log files:

logtime                  userid              action

2014-01-07 09:27:56        258872799       login

2014-01-07 09:27:57        264484116       login

2014-01-07 09:27:58        264484279       login

2014-01-07 09:27:58        264548231       login

2014-01-07 09:27:58        248900695       login

2014-01-07 09:28:00        263867071       login

2014-01-07 09:28:01        264548400       login

2014-01-07 09:28:02        264549535       login

2014-01-07 09:28:02        264483234       login

2014-01-07 09:28:03        264484643       login

2014-01-07 09:28:05        308343890       login

2014-01-07 09:28:08        1210636885     post

2014-01-07 09:28:09        263786154       login

2014-01-07 09:28:12        263340514       get

2014-01-07 09:28:13        312717032       login

2014-01-07 09:28:16        263210957       login

2014-01-07 09:28:19        116285288       login

2014-01-07 09:28:22        311560888       login

2014-01-07 09:28:25        652277973       login

2014-01-07 09:28:34        310100518       login

2014-01-07 09:28:38        1513040773     login

2014-01-07 09:28:41        1326724709     logout

2014-01-07 09:28:45        191382377       login

2014-01-07 09:28:46        241719423       login

2014-01-07 09:28:46        245054760       login

2014-01-07 09:28:46        1231483493     get

2014-01-07 09:28:48        266079580       get

2014-01-07 09:28:51        1081189909     post

2014-01-07 09:28:51        312718109       login

2014-01-07 09:29:00        1060091317     login

2014-01-07 09:29:02        1917203557     login

2014-01-07 09:29:16        271415361       login

2014-01-07 09:29:18        277849970       login

 

Log files record, in chronological order, users’ operation (action), user ID (userid) and the time when the actions took place (logtime) in the application. Users operations include three different types, which are login, logout and get/post actions.

 

The Operation Department provided the following requirements for computation of users online time:

  1. 1. Login should be considered as the starting point of online time, and overnight should be take into consideration.
  2. 2. If the time interval between any two operations is less than 3 seconds, then this interval should not be added to online time.
  3. 3. If after login, the time interval between any two operations is longer than 600 seconds, then the user should be considered as logged out.
  4. 4. If there is only login, without logout, then the last operation time should be treated as time for logout.
  5. 5. For users who completed a post operation, his/her current time online time will be tripled in computation.

 

To shift from single-threaded computing to parallel computing, following steps needs to be done:

The first step: Adjust the log file preprocessor with the @g option of export function, to retrieve the log file for one week into a segmented binary file. In subsequent parallel processing, log file could be retrieved by block for different users. The use of @g option is to ensure the segmented data retrieval is aligned to group borders, removing the possibility for assigning data of the same user to two blocks. The actual procedures are as following:

main-qimg-267eb006adab7ca7f1ab73f88bb64aa9?convert_to_webp=true

The second step: Rewrite the online time computing program into a parallel subroutine. The part in the following red box is where we need to modify for parallel processing. Because different parallel tasks are used compute for different users, you can see that very little changes are required for parallel computing. The only change required, is to replace the use of files with different blocks from the binary file.

 

First we need to add parameters to subroutine, to pass the log file name, block number and total number of blocks for the week when called by the main program.

main-qimg-9100c5050ea86d54c06a6864c3bf1f3f?convert_to_webp=true

And then modify the program as following:

main-qimg-f9a18981148744d967e354afc9ad4738?convert_to_webp=true

The above screenshot illustrates that:

  1. 1. As we previously used export@g to retrieve the file according to different user ID, the use of @z option by cursor to handle specific block (value is block number) among total (value is total blocks) from file, as shown in the red box, will retrieve the complete group for the same user ID. Data for one user will not be split into two blocks.
  2. 2. A16 returns the resulting file as cursor to the main program.

 

The third step: writing main program for parallel computing, to call the parallel computing subroutine. Because the total cores of the server CPU is 8, the IT engineers decided to use six threads for parallel computing. This take full advantage of multi-core CPUs to improve performance.

main-qimg-ec9effee1b88347a541eb62053f6165a?convert_to_webp=true

Note: for specific measurements regarding esProc’s performance gain with parallel computing, please refer to related test reports for esProc.

 

Upon the meeting of this requirement, IT engineers from the Web Company are facing a new problem: the user numbers for the online application grew explosively. Colleagues from the Operation Department complained that the online time computation program is still running too slow. The single-machine, multi-threaded approach can no longer enhance the computing speed significantly. Can these IT engineers effectively solve the performance issue using esProc’s parallel multi-machine computing capability? Is it too costly to transform to a multi-machine parallel mode? See “Computing the Online Time for Users with esProc (IV)”