beanscake has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I have chunks of data that i am going to upload to Database which can take days to finish upload , i think if i can partition the arrays of data to be uploaded into some part while i spawn process to save each allocated @array data, i think it may save me some time please i need help with this Threads or Fork please advice
use strict; use warnings; my @orig = 1..2500; my $numberofarray = scalar @orig; my $arrs = 100; # Partition #print $arrs; sub Partition_Array_data { my @arrs; push @{$arrs[$_ % $arrs]}, $orig[$_] for 0..$#orig; if (my $pid = fork) { waitpid($pid, 0); } else { if (fork) { exit } else { thread_dbSave(\@arrs); } } } sub thread_dbSave { # this function will handle the saving my @arrayofsplit = @{$_[0]}; print join ' ', @$_, "\n" for @arrayofsplit; } &Partition_Array_data();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fork or Thread?
by stevieb (Canon) on Jul 29, 2015 at 21:43 UTC | |
by beanscake (Acolyte) on Jul 29, 2015 at 22:05 UTC | |
|
Re: Fork or Thread?
by Laurent_R (Canon) on Jul 30, 2015 at 08:28 UTC | |
|