[ntp:hackers] [Gpsd-dev] Single-writer/many-reader consistency: Test program updated.
Terje Mathisen
terje at tmsw.no
Wed Mar 30 11:16:23 UTC 2011
Terje Mathisen wrote:
> Dave Hart wrote:
>> On Tue, Mar 29, 2011 at 5:54 AM, Gary E. Miller<gem at rellim.com> wrote:
>>> The files say .cpp, but it looks like plain C. Â What am I missing?
>>
>> That most C compiles as C++ just fine? Terje tossed it together using
>> a Visual Studio new project wizard which defaults to .cpp filename and
>> he didn't bother to rename it, is my guess. I didn't even think about
>
> That's absolutely correct:
>
> Most of my q&d C code is C(++), basically plain C with a few of the more
> useful syntax cleanups from C++, i.e. like the ability to declare
> variables upon first use, and single-line comments etc.
>
> For a production program I would definitely clean it up. :-)
I've updated the test program to be pure C, and so that it now accepts
cmd line parameters for number of threads, nr of timestamp slots and
seconds to run.
I have also aligned the timestamps on a 64-byte boundary, so that when
the writer is updating one record, all the readers can still read the
previous one, without forcing the cache line to bounce back&forth
between them.
With 8 such buffers the writer can update 15 million times per second,
while the readers show a 0.01% retry rate. Dropping down to 4 buffers
increases the retry rate to nearly 9%:
C:>shm-test.exe -t 10 -n 4 -b 8
Testing with 8 buffer slots, 4 threads for 10 seconds
Writer affinity = 1, old = f
Reader 1 affinity = e, old = f
Reader 2 affinity = e, old = f
Reader 3 affinity = e, old = f
Done waiting 10 seconds
All threads done! (i = 0)
Writer:
158887012 iterations, 1.5889e+007 iterations/second
Thread 1:
145237131 iterations, 74140284 updating 2604 retries 0 errors
Thread 2:
261964371 iterations, 65223303 updating 17985 retries 0 errors
Thread 3:
268689494 iterations, 67451007 updating 16879 retries 0 errors
Reader totals:
675890996 iterations, 206814594 updating 37468 retries 0 errors
Reader totals:
6.7589e+007 iterations/second, 30.60% updating 0.01% retries 0.000% errors
C:>shm-test.exe -t 10 -n 4 -b 4
Testing with 4 buffer slots, 4 threads for 10 seconds
Writer affinity = 1, old = f
Reader 1 affinity = e, old = f
Reader 2 affinity = e, old = f
Reader 3 affinity = e, old = f
Done waiting 10 seconds
All threads done! (i = 9)
Writer:
154333505 iterations, 1.5433e+007 iterations/second
Thread 1:
252654335 iterations, 63512529 updating 21460308 retries 0 errors
Thread 2:
116489834 iterations, 68217408 updating 12011315 retries 0 errors
Thread 3:
245540974 iterations, 62312089 updating 20920159 retries 0 errors
Reader totals:
614685143 iterations, 194042026 updating 54391782 retries 0 errors
Reader totals:
6.1469e+007 iterations/second, 31.57% updating 8.85% retries 0.000% errors
The files are still at http://norloff.org/ntp/shm-test/
>
>> it. I should have given the distinction in finer points of volatile
>> between C and C++.
>>
>> Looking forward to a POSIX port...
Still waiting for the time to do this one. :-)
Terje
>
> So do I, as I said I'll write it if I have to.
>
> Terje
--
- <Terje at tmsw.no>
"almost all programming can be viewed as an exercise in caching"
More information about the hackers
mailing list