I am using shared memory for transferring data between two process, using boost::interprocess::managed_shared_memory to create and manage shared memory.
I was measuring the latency for the 2 operations (fetch and update) –
update operation – writes to the array in shared memory.
fetch operation – reads the shared memory variable.
The array size is 16 bytes. I’ve created utility functions to update to and fetch the value from a purticular array location of the shared memory variable.
To measure the latency – I get the current time in microseconds and store it a variable. I get the timestamp before the operation and after the operation. Simply subtracting the time variables will the give the latency for the current iteration. Then I calculate the avg of the required number of iterations.
Initially for 1 iteration the latency is around 100 – 300 microseconds and it gradually decreases as I increase the iteraiton to 10, 100, 1000, 10000, …. In the end for 1000000 iterations the latency drops to 30 – 60 microseconds.
Iterations Latency for Update(microseconds) Latency for Fetch(microseconds)
1 254 347
10 84.9 153.5
100 71.16 55.43
1000 37.733 41.47
10000 32.52 37.1141
100000 34.2387 34.2009
1000000 33.4629 34.537
To measure the latency – I get the current time in microseconds and store it a variable. I get the timestamp before the operation and after the operation. Simply subtracting the time variables will the give the latency for the current iteration. Then I calculate the avg of the required number of iterations.
Initially for 1 iteration the latency is around 100 – 300 microseconds and it gradually decreases as I increase the iteraiton to 10, 100, 1000, 10000, …. In the end for 1000000 iterations the latency drops to 30 – 60 microseconds.
This is the results I’m getting,
Iterations
1
10
100
1000
10000
100000
1000000
Latency for Update(microseconds)
254
84.9
71.16
37.733
32.52
34.2387
33.4629
Latency for Fetch(microseconds)
347
153.5
55.43
41.47
37.1141
34.2009
34.537
Why does the latency decreases with increase in number of iterations
Vasanthan B is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.