Excel::Writer::XLSX isn't thread-safe, so I'd tackle the problem this way:

#! perl -slw use strict; use threads; use Thread::Queue; use Excel::Writer::XLSX;; sub worker { my( $Q, $region, $sql ) = @_; my $wb = Excel::Writer::XLSX->new("$region.xlsx"); $wb->set_properties( title => 'Node List', author => 'L_WC de +mo', comments => 'Node List' ); $wb->set_optimization(); my $fmt = $wb->add_format( bg_color => 44 ); $fmt->set_align('cent +er'); my $ws = $wb->add_worksheet( $region ); my $row = 0; while( $Q->dequeue ) { $ws->write( $row++, 0, $_ ); } $wb->close; } my @nodeList = ( ['AMS', 'a'], ['APJ', 'ap'], ['EMEA', 'e'] ); my @Qs = map Thread::Queue->new, 1 .. 3; my @threads = map threads->new( \&worker, $Qs[ $_ ], @{ $nodeList[ $_ +] } ), 0 .. 2; for( 1 .. 1e6 ) { my $sheet = int( rand 3 ); $Qs[ $sheet ]->enqueue( $nodeList[ $sheet ][1] . $_ ); } $Qs[ $_ ]->enqueue( undef ) for 0 .. 2; $_->join for @threads;

That writes 1 million items split between 3 workbooks in around 1 minute. Once the 3 files are produced, it should be simple to merge the single sheets from the 3 zipfiles into one workbook by using Excel itself. (I don't have Excel, so I couldn't test that hypothesis.)


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.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

In reply to Re^3: How to use threads to write worksheets of excel by BrowserUk
in thread How to use threads to write worksheets of excel by L_WC

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.