Hello Monks, I'm developing a perl script to import data from a file and put it a MySQL Database. I'm using a Threaded::Queue to put each line of the file, and in parallel N threads to read from that queue and put it in the DB. In Sun Solaris (UltraSPARC T2) we must use parallelism in order to take advantage from the CPU. However i'm not getting improvements when increasing the number of threads to process the Thread::Queue. We are getting processing times very similar for both approaches, using and not using threads. I'm already try to use two parallel Queues and the results are similar. Any tips? Snnipet of the script:
#!/opt/coolstack/bin/perl -w use strict; use POSIX; use threads ('yield', 'stack_size' => 64*4096, 'exit' => 'threads_only', 'stringify'); use Thread::Queue; my $nthreads = 16; my $indata = new Thread::Queue; print "START PARSER: " . localtime() . "\n"; my @tloaders; print "LAUNCH LOADER THREADS\n"; my ($thr) = threads->create(\&load, $fname); push @tloaders, $thr->tid(); print "LOADER THREADS LAUNCHED\n"; print "LAUNCH WORKER THREADS\n"; for (my $i=0; $i < ($nthreads); $i++) { my ($thr) = threads->create(\&analyse ); } print "WORKER THREADS LAUNCHED\n"; print "WAITING FOR LOADERS TO FINISH\n"; foreach my $i (@tloaders) { my $thr = threads->object($i); print "WAITING ON THREAD: " . $thr->tid() . "\n"; $thr->join(); } print "LOADERS HAVE FINISHED: " . localtime() . "\n"; for (my $i=0; $i < ($nthreads); $i++) { $indata->enqueue("STOP"); } foreach my $thr (threads->list()) { print "WAITING ON THREAD: " . $thr->tid() . "\n"; $thr->join(); } print "END PARSER: " . localtime() . "\n"; exit;
Perl Version
$ perl -v This is perl, v5.8.8 built for sun4-solaris-thread-multi Copyright 1987-2006, Larry Wall

In reply to 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.