I'm not writing to a single file, but to one different file per Thread.

There is no way to know that from the code snippet you posted. And if each thread is writing to a different file, why are you mutexing? lock($x); $fh->print("$record\n"); Even your choice of mutex name seems calculated to obscure your real purpose.

I'm not taking advantage of the CPU because I serialize the processing.

Even if you weren't serialising, you still won't gain anything by throwing threads at an IO-bound process unless you can overlap the IO. If, for example, you needed to communicate with several remote servers, then assuming sufficient bandwidth, you can reduce the overall program time by overlapping the IO to those servers. Using 1 thread per concurrent server is an effective means of doing that.

But, on the basis of your descriptions such as they are, and the code snippets you posted, removing the locking is unlikely to produce any substantial gain. The reason is that--unless your files are all on different drives--all your threads will be competing for throughput and latency of one disk drive.

Ie. Even if you remove your serialisation, your concurrent writes will be serialised by the disk drive itself. The read head can only be in one place at one time, and so you can only be writing to one file at one time.

There may be some small (tiny..you know, really, really small) gains as a result of filesystem write caching and DD-based write-extent re-ordering, but it's unlikely to be something you would be able to measure on a general purpose system with other concurrent activities. You'd have to use a laboratory conditions system to detect it. And those kind of gains are useless in real-world scenarios.


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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^4: Sun Solaris (SPARC processor) + Threads + performance/optimization by BrowserUk
in thread Sun Solaris (SPARC processor) + Threads + performance/optimization by gulden

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.