Skip to content

Instantly share code, notes, and snippets.

@nkh
Created August 24, 2017 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkh/865e74aea4fc2d1bd02e82049e1c62f8 to your computer and use it in GitHub Desktop.
Save nkh/865e74aea4fc2d1bd02e82049e1c62f8 to your computer and use it in GitHub Desktop.
Hi Jonathan,
I took an example from Data::Dump::Tree (DDT)and started playing with Promises, the
goal was simply educative, I am following your "Parallelism, Concurrency,
and Asynchrony in Perl 6" document to try the different mechanisms. The final goal
being the parallelization of DDT as it is too sluggish and also in preparation of
Asciio 2.0. Tell me if you want the development branch and the example on github to
check the problems below.
Problem 1
=========
for ^50
{
$dump_start = now ;
my $d1 = start $d.ddt: :get, { :$config, :$regex, :$match }, :title<config parsing>, :elements_filters[&sorter] ;
my $d2 = start $d.ddt: :get, { :$config, :$regex, :$match }, :title<config parsing>, :elements_filters[&sorter] ;
my $d3 = start $d.ddt: :get, { :$config, :$regex, :$match }, :title<config parsing>, :elements_filters[&sorter] ;
my $d4 = start $d.ddt: :get, { :$config, :$regex, :$match }, :title<config parsing>, :elements_filters[&sorter] ;
my $d5 = start $d.ddt: :get, { :$config, :$regex, :$match }, :title<config parsing>, :elements_filters[&sorter] ;
my $d6 = start $d.ddt: :get, { :$config, :$regex, :$match }, :title<config parsing>, :elements_filters[&sorter] ;
my $d7 = start $d.ddt: :get, { :$config, :$regex, :$match }, :title<config parsing>, :elements_filters[&sorter] ;
my $d8 = start $d.ddt: :get, { :$config, :$regex, :$match }, :title<config parsing>, :elements_filters[&sorter] ;
await $d1, $d2, $d3, $d4, $d5, $d6, $d7, $d8 ;
say "dump time: {now - $dump_start} s" ;
}
The problem is that it first iterates quickly and then slows down considerably
dump time: 0.24248294 s # first iteration
dump time: 0.2493730 s
dump time: 0.2249258 s
dump time: 0.25128736 s
dump time: 0.24334974 s
dump time: 0.2577809 s
...
dump time: 0.4216805 s
dump time: 0.404167881 s
dump time: 0.40570028 s
dump time: 0.41778251 s
dump time: 0.4126616 s # last iteration
I ran it with 500 iteration, around iteration 150 the time seems to stabilize just below 0.5s.
At iteration 500 it is half the time under 0.5s and half the time very slightly higher
with peaks around 0.7 s
Problem 2
=========
I changed the code to this loop and that call to ddt to show the promises, wrongly calling promises
threads in my example.
for ^15
{
@threads.push: start $d.ddt: :get, { :$config, :$regex, :$match }, :title<config parsing>, :elements_filters[&sorter] ;
}
ddt @threads ;
that worked fine and fast. I changed the code to
for ^16 # change from ^15 to ^16
{
@threads.push: start $d.ddt: :get, { :$config, :$regex, :$match }, :title<config parsing>, :elements_filters[&sorter] ;
}
ddt @threads ;
that doesn't work at all. The "ddt @threads" does not get executed, nothing get's schedules, no CPU is used. It's dead Jim.
Problem 3
=========
I changed the code to
for ^15 # change back to ^15
{
@threads.push: start $d.ddt: :get, { :$config, :$regex, :$match }, :title<config parsing>, :elements_filters[&sorter] ;
}
ddt @threads, :flat{1, 5} ; #changed the option to ddt
The option to ddt makes the rendering much slower, slow enough to that some promises get scheduled before the
ddt call returns.
I ran it mucltiple times on the command line, sometimes it works, like the example below:
132 ~/4/P6-Data-Dump-Tree p6 time_threads.pl
time: 0.24393817 s
[15] @0
0 = .Promise <Planned> 5 = .Promise <Kept> 10 = .Promise <Planned>
1 = .Promise <Planned> 6 = .Promise <Planned> 11 = .Promise <Planned>
2 = .Promise <Planned> 7 = .Promise <Planned> 12 = .Promise <Planned>
3 = .Promise <Planned> 8 = .Promise <Planned> 13 = .Promise <Planned>
4 = .Promise <Planned> 9 = .Promise <Planned> 14 = .Promise <Planned>
time: 0.5515428 s
total time 0.8070619 s
sometimes it fails with this error:
-----------------------------------
122 ~/4/P6-Data-Dump-Tree p6 time_threads.pl
time: 0.2489823 s
[15] @0
0 = .Promise <Planned> 5 = .Promise <Planned> 10 = .Promise <Kept>
1 = .Promise <Planned> 6 = .Promise <Planned> 11 = .Promise <Planned>
2 = .Promise <Planned> 7 = .Promise <Kept> 12 = .Promise <Kept>
3 = .Promise <Planned> 8 = .Promise <Planned> 13 = .Promise <Broken>
4 = .Promise <Planned> 9 = .Promise <Planned> 14 = .Promise <Kept>
Tried to get the result of a broken Promise
in block <unit> at time_threads.pl line 53
Original exception:
Cannot find method 'specialize' on object of type NQPClassHOW
in method reset at /home/nadim/nadim/devel/repositories/perl_modules/P6-Data-Dump-Tree/lib/Data/Dump/Tree.pm (Data::Dump::Tree) line 218
my code at line 218 looks like this :
$.width //= %+((qx[stty size] || '0 80') ~~ /\d+ \s+ (\d+)/)[0] ;
Other times it fails like this without outputing the result of ddt:
-------------------------------------------------------------------
122 ~/4/P6-Data-Dump-Tree p6 time_threads.pl
time: 0.24770038 s
Unhandled exception in code scheduled on thread 19
Unhandled exception in code scheduled on thread 18
Unhandled exception in code scheduled on thread 13
Unhandled exception in code scheduled on thread 6
Type check failed in binding to parameter 'value'; expected Any but got NQPMu (?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment