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

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

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

    Good Day BrowserUk,

    Your 'C' example brought up a very good point, and one that I've been pulling my hair out ever since your response. I re-wrote the script to use 'fork' to see how multiple processes would run. To my amazement the higher the fork number the greater the throughput. Since the test machine has 6 core and with 6 forks, all cores are running at 100%, adding more processes should not improve the wps. But it did! I just got better and better throughput.

    But, because I'm using a file, I could look at the contents and the more processes, the more corrupt the file became. A little while ago, I found my problem.

    The 'flock' function wasn't working with the 'sys...' functions ( sysread, syswrite, etc ). I still want to check this out, but I wanted you to know that my new good numbers are way less than what I originally published.

    Regards...Ed

    "Well done is better than well said." - Benjamin Franklin