in reply to SysV shared memory (Look-Alike) -- pure perl
Currently, 349K wps is the worse case on a RAM disk, 291K wps on a 7,200 rpm hard disk, and 221K wps on a 5,400 rpm disk. (Note: I didn't have a SSD on the test system.)
Not to detract from your code -- if it achieves your goals, its perfect -- but by way of comparison with using real shared ram.
The following does 32 million fully interlocked writes (32 threads x 1e6) to real shared memory in 4.17 seconds (7.6M wps):
C:\test\lockfree>type lockfree.c #include <windows.h> #include <stdio.h> #include <time.h> #include <process.h> typedef struct { int i; int loops; } shared; void worker( void *arg ) { shared *s = (shared*)arg; int i = 0; for( i=0; i < s->loops; ++i ) { _InterlockedIncrement( &s->i ); } return; } void main( int argc, char **argv ) { int i = 0, nThreads = 4; clock_t start, finish; double elapsed; uintptr_t threads[32]; shared s = { 0, 1000000 };; if( argc > 1 ) nThreads = atol( argv[1] ); if( argc > 2 ) s.loops = atol( argv[2] ); printf( "threads:%d loops:%d\n", nThreads, s.loops ); start = clock(); for( i=0; i < nThreads; ++i ) threads[ i ] = _beginthread( &worker, 0, &s ); WaitForMultipleObjects( nThreads, (HANDLE*)&threads, 1, INFINITE ) +; finish = clock(); elapsed = (double)(finish - start) / CLOCKS_PER_SEC; printf( "count: %lu time:%.6f\n", s.i, elapsed ); }
A run:
C:\test\lockfree>lockfree 32 1000000 threads:32 loops:1000000 count: 32000000 time:4.171000
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: SysV shared memory (Look-Alike) -- pure perl
by flexvault (Monsignor) on Jul 21, 2014 at 20:33 UTC |