lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Background story:

Our customer is running a financial "real-time audit" service. This includes
a micro-service that audits money transfers. Naturally the service also
writes to ​a log file​.

We were asked to monitor the performance of the "money transfer auditing"
micro-service. To do this we need to be able to calculate ​the average time
it takes to audit a money transfer​.

Your task:

In this exercise you are given 3 log files that were produced by the service
during it’s runs.

You need to write a ​script in Lua that calculates the average ​​time it
takes to audit a money transfer ​in each log file.

Understanding the Log Files:

[1] every log line has several parts -

[a]​Time since system started​, e.g. 01:10:05.112 is 1 hour, 10 minutes, 5
seconds and 112 milliseconds. This part length is fixed, as numbers are 0
padded.

[b]​Worker thread name​, e.g. worker-12. Threads work in parallel allowing
the system to audit several transactions at the same time.

[c]​Message type​, e.g. INFO

[d]​Code location​, e.g. LoggingThread:33

[e]​Message​- an explanation of what exactly was done by the thread at that
moment.

[2] Every transaction performed by the service starts with the message "XXX
loaded from queue". for example:

00:47:55.154 worker-39 INFO LoggingThread:33 - money transfer loaded from
queue

Is the beginning of a money transfer transaction by worker thread 39.


01:24:13.701 worker-3 INFO LoggingThread:34 - Periodic cache calibration
loaded from queue
Is​ the beginning of a periodic cache calibration action by worker-3.


We are only interested in money transfer transactions.


[3] Money transfer transactions end with an "accepted" or "declined"
message. Here are two examples:

00:47:57.388 worker-6 INFO MoneyTransfer:53 - Transfer to 13129063 approved

00:47:57.388 worker-5 INFO MoneyTransfer:53 - Transfer to 15617305 declined

[4] To know how much time processing took for a specific transaction, yo
need to subtract the time on the start line from the time at the end line.
Make sure that you follow the SAME THREAD (e.g. "worker-5", "worker-43",
etc.) until the action end.

For example, here is a transaction performed by worker-6 which took 22
milliseconds:

00:47:57.366 worker-6 INFO LoggingThread:33 - money transfer loaded from
queue
00:47:57.367 worker-6 INFO MoneyTransfer:39 - loading information for
ac13129063
00:47:57.367 worker-39 INFO MoneyTransfer:42 - parsing transaction
entries...
00:47:57.367 worker-40 INFO MoneyTransfer:48 - applying bussiness logic for
12226425
00:47:57.368 worker-27 INFO MoneyTransfer:48 - applying bussiness logic for
16683318
00:47:57.369 worker-6 INFO MoneyTransfer:42 - parsing transaction entries...
00:47:57.374 worker-40 INFO MoneyTransfer:53 - Transfer to 12226425 approved 
00:47:57.374 worker-10 INFO MoneyTransfer:27 - loading information for
customer cs-1676943...
00:47:57.374 worker-40 INFO LoggingThread:33 - money transfer loaded from
queue
00:47:57.375 worker-40 INFO MoneyTransfer:39 - loading information for
ac13433123
00:47:57.375 worker-6 INFO MoneyTransfer:27 - loading information for
customer cs-1231382...
00:47:57.380 worker-14 INFO MoneyTransfer:48 - applying bussiness logic for
14921732
00:47:57.380 worker-5 INFO MoneyTransfer:30 - cross indexing
00:47:57.380 worker-6 INFO MoneyTransfer:30 - cross indexing
00:47:57.380 worker-22 INFO MoneyTransfer:48 - applying bussiness logic for
14404617
00:47:57.383 worker-6 INFO MoneyTransfer:48 - applying bussiness logic for
13129063
00:47:57.384 worker-10 INFO MoneyTransfer:53 - Transfer to 17990343 approved
00:47:57.388 worker-6 INFO MoneyTransfer:53 - Transfer to 13129063 approved

Some things to note:

(a)Other workers were doing other work (or maybe just sleeping) at the same
time
(b)Any thread can perform many transactions, one after the other


The file “example.log” is an example of a log for the system when run with
only 1 thread, for 3 transactions (2 of them money transfers). The correct
answer for this file is “19 milliseconds”

example.log <http://lua.2524044.n2.nabble.com/file/t400821/example.log>  
simple.log <http://lua.2524044.n2.nabble.com/file/t400821/simple.log>  
medium.log <http://lua.2524044.n2.nabble.com/file/t400821/medium.log>  
hard.log <http://lua.2524044.n2.nabble.com/file/t400821/hard.log>  



--
Sent from: http://lua.2524044.n2.nabble.com/Lua-l-f2524044.html