SlideShare a Scribd company logo
1 of 62
Download to read offline
Raku Memory Manglement:
Checking yourself out.
Steven Lembark
Workhorse Computing
lembark@wrkhors.com
Yes, size() matters.
but it isn’t available in Raku.
Process-level stats.
Mainly “RSS”.
getrusage(2).
Acquiring & analyze data.
Raku tools.
RSS?
“Resident Set Size”
Virtual pages in physical memory.
Accessible without a page fault.
Non-resident VM may be swapped.
Requires a page fault to access.
Goals of memory managment:
Work within RSS.
Reduce page faults.
Avoid hard faults & swapping.
getrusage(2)
Returns process memory stats.
Aggregate values.
Results constrained by system limits.
getrusage(2)
struct rusage
{
struct timeval ru_utime; /* user CPU time used */
struct timeval ru_stime; /* system CPU time used */
long ru_maxrss; /* maximum resident set size */
long ru_ixrss; /* integral shared memory size */
long ru_idrss; /* integral unshared data size */
long ru_isrss; /* integral unshared stack size */
long ru_minflt; /* page reclaims (soft page faults) */
long ru_majflt; /* page faults (hard page faults) */
long ru_nswap; /* swaps */
long ru_inblock; /* block input operations */
long ru_oublock; /* block output operations */
long ru_msgsnd; /* IPC messages sent */
long ru_msgrcv; /* IPC messages received */
long ru_nsignals; /* signals received */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary context switches */
};
POSIX
getrusage(2)
struct rusage
{
struct timeval ru_utime; /* user CPU time used */
struct timeval ru_stime; /* system CPU time used */
long ru_maxrss; /* maximum resident set size */
long ru_ixrss; /* integral shared memory size */
long ru_idrss; /* integral unshared data size */
long ru_isrss; /* integral unshared stack size */
long ru_minflt; /* page reclaims (soft page faults) */
long ru_majflt; /* page faults (hard page faults) */
long ru_nswap; /* swaps */
long ru_inblock; /* block input operations */
long ru_oublock; /* block output operations */
long ru_msgsnd; /* IPC messages sent */
long ru_msgrcv; /* IPC messages received */
long ru_nsignals; /* signals received */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary context switches */
};
Linux
getrusage(2)
struct rusage
{
struct timeval ru_utime; /* user CPU time used */
struct timeval ru_stime; /* system CPU time used */
long ru_maxrss; /* maximum resident set size */
long ru_minflt; /* page reclaims (soft page faults) */
long ru_majflt; /* page faults (hard page faults) */
long ru_inblock; /* block input operations */
long ru_oublock; /* block output operations */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary context switches */
};
Only max
RSS.
getrusage(2)
struct rusage
{
struct timeval ru_utime; /* user CPU time used */
struct timeval ru_stime; /* system CPU time used */
long ru_maxrss; /* maximum resident set size */
long ru_minflt; /* page reclaims (soft page faults) */
long ru_majflt; /* page faults (hard page faults) */
long ru_inblock; /* block input operations */
long ru_oublock; /* block output operations */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary context switches */
};
Fault
counts.
Viewing RSS
Telemetry module.
Takes periodic snapshots.
Allows inserting a label to track events.
Core with nqp.
Not synchronous with tasks.
Raku
Viewing RSS
ProcStats
Soon to be on CPAN.
Exports “dump-rusage”.
Differences from first sample.
Only output changes.
Track wallclock time.
Optional label.
:final Output all stats compared to first sample
ProcStats
sub dump-rusage
(
Bool() :$final = False,
Bool() :$first = $final,
Bool() :$force = $final,
Stringy() :$label = $final ?? 'Final' !! ''
)
is export( :DEFAULT )
:first Values compared to first sample (vs. last).
ProcStats
sub dump-rusage
(
Bool() :$final = False,
Bool() :$first = $final,
Bool() :$force = $final,
Stringy() :$label = $final ?? 'Final' !! ''
)
is export( :DEFAULT )
:force Write all stats (vs. only changed).
ProcStats
sub dump-rusage
(
Bool() :$final = False,
Bool() :$first = $final,
Bool() :$force = $final,
Stringy() :$label = $final ?? 'Final' !! ''
)
is export( :DEFAULT )
:label Add “label” key (default from :final).
ProcStats
sub dump-rusage
(
Bool() :$final = False,
Bool() :$first = $final,
Bool() :$force = $final,
Stringy() :$label = $final ?? 'Final' !! ''
)
is export( :DEFAULT )
Wallclock time
Elapsed vs. CPU
sub dump-rusage
(
Bool() :$final = False,
Bool() :$first = $final,
Bool() :$force = $final,
Stringy() :$label = $final ?? 'Final' !! ''
)
is export( :DEFAULT )
{
my $wtime = now.Num;
Wallclock time
Sample at top to avoid time-shift.
sub dump-rusage
(
Bool() :$final = False,
Bool() :$first = $final,
Bool() :$force = $final,
Stringy() :$label = $final ?? 'Final' !! ''
)
is export( :DEFAULT )
{
my $wtime = now.Num;
Values from RSS
constant FIELDS =
<
maxrss ixrss idrss isrss minflt majflt
nswap inblock oublock msgsnd msgrcv nsignals
nvcsw nivcsw
>;
constant IGNORE = <ixrss idrss isrss ...>;
constant REPORT =
< maxrss majflt minflt inblock oublock >;
constant MICRO = 10 ** -6;
COMPARE avoids reporting on CPU swithes.
Track progress
Unchanged samples are not reported.
$passes tracks total calls.
state $passes = 0;
state %last = ();
Acquire data
Times are sec + µsec, deal with them separately.
“Z=>” zips fields & values into a hash.
use nqp;
nqp::getrusage( my int @raw );
my ( $user_s, $user_us, $syst_s, $syst_us )
= splice @raw, 0, 4;
my %sample = FIELDS Z=> @raw;
%sample{ IGNORE } :delete;
Making time
my $utime
= ( $user_s + $user_us / 1_000_000 ).round( MICRO );
my $stime
= ( $syst_s + $syst_us / 1_000_000 ).round( MICRO );
user & system time begin as two ints.
Round gives reasonable precision in output.
Store baseline values.
state %last =
state %first =
(
|%sample,
:$wtime,
:$utime,
:$stime,
);
First is never updated.
Get a working “last” value on the first pass.
Store baseline values.
Flatten %sample into pairs.
state %last =
state %first =
(
|%sample,
:$wtime,
:$utime,
:$stime,
);
Store baseline values.
Times as pairs.
state %last =
state %first =
(
|%sample,
:$wtime,
:$utime,
:$stime,
);
First is last at first.
After first last is last.
my %prior
= $first
?? %first
!! %last
;
What to compare?
Force reports full sample.
COMPARE limits keys compare to %prior & output.
my %curr
= ( $force || ! $passes )
?? %sample
!! do
{
my @diffs
= REPORT.grep( { %sample{$_} != %prior{$_} } );
@diffs Z=> %sample{ @diffs }
};
Write out one stat heading & value.
Compute column width once during execution.
sub write-stat ( Pair $p )
{
note
sprintf
'%-*s : %s',
once {FIELDS».chars.max},
$p.key,
$p.value
;
}
Write progressive value
Numerics compared to starting baseline.
Simplifies tracking code results.
sub write-diff ( Pair $p )
{
my $k = $p.key;
my $v = $p.value - %first{ $k };
write-stat $k => $v;
}
First pass writes all stats.
First pass has to report baseline values.
state $write = &write-stat;
First pass writes all stats.
First pass has to report baseline values.
After that report differences.
state &write = &write-stat;
...
write $stat;
...
once { &write = &write-diff };
for %curr.sort -> $stat
{
FIRST
{
note '---';
write-stat ( output => $++ );
write-stat ( :$passes );
write-stat ( :$label ) if $label;
write-diff ( :$wtime );
write-diff ( :$utime );
write-diff ( :$stime );
}
write $stat
}
for %curr.sort -> $stat
{
FIRST
{
note '---';
write-stat ( output => $++ );
write-stat ( :$passes );
write-stat ( :$label ) if $label;
write-diff ( :$wtime );
write-diff ( :$utime );
write-diff ( :$stime );
}
write $stat
}
for %curr.sort -> $stat
{
FIRST
{
note '---';
write-stat ( output => $++ );
write-stat ( :$passes );
write-stat ( :$label ) if $label;
write-diff ( :$wtime );
write-diff ( :$utime );
write-diff ( :$stime );
}
write $stat
}
for %curr.sort -> $stat
{
FIRST
{
note '---';
write-stat ( output => $++ );
write-stat ( :$passes );
write-stat ( :$label ) if $label;
write-diff ( :$wtime );
write-diff ( :$utime );
write-diff ( :$stime );
}
write $stat
}
for %curr.sort -> $stat
{
FIRST
{
note '---';
write-stat ( output => $++ );
write-stat ( :$passes );
write-stat ( :$label ) if $label;
write-diff ( :$wtime );
write-diff ( :$utime );
write-diff ( :$stime );
}
write $stat
}
Last steps
Up total count.
Store current sample for re-use.
++$passes;
%last = %sample;
once { &write = &write-diff };
Baseline usage
Bare for-loop
Shows overhead of rusage output.
#!/usr/bin/env Raku
use v6.d;
use FindBin::libs;
use ProcStats;
dump-rusage for 1 .. 1_000;
dump-rusage( :final );
Sample 0
Pass 0 as all values.
Baseline for RSS &
friends.
---
output : 0
passes : 0
wtime : 1560968261.746507
utime : 0.344793
stime : 0.020896
inblock : 0
majflt : 0
maxrss : 99732
minflt : 25039
nivcsw : 10
nvcsw : 204
oublock : 64
Sample 0
wtime is ‘real world’.
Reasonable candidate
key for sample history.
---
output : 0
passes : 0
wtime : 1560968261.746507
utime : 0.344793
stime : 0.020896
inblock : 0
majflt : 0
maxrss : 99732
minflt : 25039
nivcsw : 10
nvcsw : 204
oublock : 64
Sample 0
RSS is ~100MiB at
startup.
---
output : 0
passes : 0
wtime : 1560968261.746507
utime : 0.344793
stime : 0.020896
inblock : 0
majflt : 0
maxrss : 99732
minflt : 25039
nivcsw : 10
nvcsw : 204
oublock : 64
Output
Output 1+ are relative to %first.
Sample N ---
output : 1
passes : 1
wtime : 0.0081639
utime : 0.007295
stime : 0.000228
maxrss : 1588
minflt : 255
---
...
Output
Output 1+ are relative to %first.
maxrss & minflt cause output.
Output ---
output : 1
passes : 1
wtime : 0.0081639
utime : 0.007295
stime : 0.000228
maxrss : 1588
minflt : 255
---
...
Output
Inermediate passes.
Output #130:
minflt 1758 -> 1759.
Output ---
output : 129
passes : 812
wtime : 0.4603018
utime : 0.60607
stime : 0.000175
minflt : 1758
---
output : 130
passes : 813
wtime : 0.4636268
utime : 0.609417
stime : 0.000175
minflt : 1759
---
Output
getrulsage( :final );
Shows all fields.
About 1/8 of passes had output.
“Final” sample ---
output : 131
passes : 1000
label : Final
wtime : 0.5086002
utime : 0.654374
stime : 0.000175
inblock : 0
majflt : 0
maxrss : 6996
minflt : 1759
nivcsw : 2
nvcsw : 35
oublock : 0
Default label.
---
output : 131
passes : 1000
label : Final
wtime : 0.5086002
utime : 0.654374
stime : 0.000175
inblock : 0
majflt : 0
maxrss : 6996
minflt : 1759
nivcsw : 2
nvcsw : 35
oublock : 0
“Final” sample
Fairly low overhead.
---
output : 131
passes : 1000
label : Final
wtime : 0.5086002
utime : 0.654374
stime : 0.000175
inblock : 0
majflt : 0
maxrss : 6996
minflt : 1759
nivcsw : 2
nvcsw : 35
oublock : 0
“Final” sample
Multiple threads:
wallclock < user.
---
output : 131
passes : 1000
label : Final
wtime : 0.5086002
utime : 0.654374
stime : 0.000175
inblock : 0
majflt : 0
maxrss : 6996
minflt : 1759
nivcsw : 2
nvcsw : 35
oublock : 0
“Final” sample
RSS grew by ~7MiB
---
output : 131
passes : 1000
label : Final
wtime : 0.5086002
utime : 0.654374
stime : 0.000175
inblock : 0
majflt : 0
maxrss : 6996
minflt : 1759
nivcsw : 2
nvcsw : 35
oublock : 0
“Final” sample
Really do something...
Simulate traking userid’s on a web server:
Add a hash key.
Increment a random value.
Drop a key.
Roll your own
Random hash key via random sample.
sub random-string
(
Int() :$size = ( 1 .. 10 ).pick
--> Str
)
{
constant alpha = [ 'a' ... 'z', 'A' ... 'Z' ];
alpha.roll( $size ).join;
}
Roll your own
pick() returns a single, random value.
sub random-string
(
Int() :$size = ( 1 .. 10 ).pick
--> Str
)
{
constant alpha = [ 'a' ... 'z', 'A' ... 'Z' ];
alpha.roll( $size ).join;
}
Roll your own
roll() returns a random sample.
sub random-string
(
Int() :$size = ( 1 .. 10 ).pick
--> Str
)
{
constant alpha = [ 'a' ... 'z', 'A' ... 'Z' ];
alpha.roll( $size ).join;
}
Fake userid
Track key counts, active keys.
sub user-add
{
++%user-data{ random-string };
++$adds;
$max-keys = max $max-keys, %user-data.elems;
}
Random key selection
sub user-drop
{
%user-data or return;
++$drops;
%user-data{ %user-data.pick.key } :delete;
}
sub user-op
{
%user-data or return;
++$ops;
++%user-data{ %user-data.pick.key };
}
Randomized, weighted trial.
for 1 .. 1000
{
constant weighted_operations =
(
&user-add => 0.10,
&user-drop => 0.10,
&user-op => 0.80,
).Mix;
weighted_operations.roll( 1_000 )».();
dump-rusage(label => 'Keys: '~%user‑data.elems );
}
Define op’s and weights.
for 1 .. 1000
{
constant weighted_operations =
(
&user-add => 0.10,
&user-drop => 0.10,
&user-op => 0.80,
).Mix;
weighted_operations.roll( 1_000 )».();
dump-rusage(label => 'Keys: '~%user‑data.elems );
}
1000 iterations of trial.
for 1 .. 1000
{
constant weighted_operations =
(
&user-add => 0.10,
&user-drop => 0.10,
&user-op => 0.80,
).Mix;
weighted_operations.roll( 1_000 )».();
dump-rusage(label => 'Keys: '~%user‑data.elems );
}
Report summary
“say” is stdout, dump-rusage is stderr.
:final uses %first as reference for values.
dump-rusage( :final );
say 'Total adds: ' ~ $adds;
say 'Total drops: ' ~ $drops;
say 'Total ops: ' ~ $ops;
say 'Max keys: ' ~ $max-keys;
say 'Final keys: ' ~ %user-data.elems;
Getting stats
Easier to read with separate files.
$ ./rand-user-table >stats.out 2>stats.yaml;
Stats results
Final results from
“say”.
Total adds: 99738
Total drops: 98755
Total ops: 787133
Max keys: 213
Final keys: 144
Stats results
Final sample:
1000 iterations/pass.
Extra time from
threading.
~18MiB RSS growth.
---
output : 518
passes : 1001
label : Final
wtime : 18.668069
utime : 18.846082
stime : 0.01101
inblock : 0
majflt : 0
maxrss : 18404
minflt : 5522
nivcsw : 61
nvcsw : 83
oublock : 128
What you see is all you get.
RSS, faults.
Per-process totals.
Not per structure.
Randomized trials simple in Raku.
Monitor results after specific operations.

More Related Content

What's hot

Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Workhorse Computing
 
Doing It Wrong with Puppet -
Doing It Wrong with Puppet - Doing It Wrong with Puppet -
Doing It Wrong with Puppet - Puppet
 
Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...Puppet
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in PerlLaurent Dami
 
Utility Modules That You Should Know About
Utility Modules That You Should Know AboutUtility Modules That You Should Know About
Utility Modules That You Should Know Aboutjoshua.mcadams
 
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...Puppet
 
Puppet: What _not_ to do
Puppet: What _not_ to doPuppet: What _not_ to do
Puppet: What _not_ to doPuppet
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworksdiego_k
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojobpmedley
 
Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2nottings
 
PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0Tim Bunce
 
Smolder @Silex
Smolder @SilexSmolder @Silex
Smolder @SilexJeen Lee
 

What's hot (20)

Short Introduction To "perl -d"
Short Introduction To "perl -d"Short Introduction To "perl -d"
Short Introduction To "perl -d"
 
Unit Testing Lots of Perl
Unit Testing Lots of PerlUnit Testing Lots of Perl
Unit Testing Lots of Perl
 
Smoking docker
Smoking dockerSmoking docker
Smoking docker
 
Get your teeth into Plack
Get your teeth into PlackGet your teeth into Plack
Get your teeth into Plack
 
Getting Testy With Perl6
Getting Testy With Perl6Getting Testy With Perl6
Getting Testy With Perl6
 
Getting testy with Perl
Getting testy with PerlGetting testy with Perl
Getting testy with Perl
 
Effective Benchmarks
Effective BenchmarksEffective Benchmarks
Effective Benchmarks
 
Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6
 
Doing It Wrong with Puppet -
Doing It Wrong with Puppet - Doing It Wrong with Puppet -
Doing It Wrong with Puppet -
 
Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...
 
Troubleshooting Puppet
Troubleshooting PuppetTroubleshooting Puppet
Troubleshooting Puppet
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in Perl
 
Utility Modules That You Should Know About
Utility Modules That You Should Know AboutUtility Modules That You Should Know About
Utility Modules That You Should Know About
 
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
 
Puppet: What _not_ to do
Puppet: What _not_ to doPuppet: What _not_ to do
Puppet: What _not_ to do
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojo
 
Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2
 
PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0
 
Smolder @Silex
Smolder @SilexSmolder @Silex
Smolder @Silex
 

Similar to Memory Manglement in Raku

Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QACreating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QAarchwisp
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netPhp my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netProgrammer Blog
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLMark Wong
 
Lecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administrationLecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administrationMohammed Farrag
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLMark Wong
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Introzhang tao
 
Assignment no39
Assignment no39Assignment no39
Assignment no39Jay Patel
 
11 Things About 11gr2
11 Things About 11gr211 Things About 11gr2
11 Things About 11gr2afa reg
 
Shell Script Disk Usage Report and E-Mail Current Threshold Status
Shell Script  Disk Usage Report and E-Mail Current Threshold StatusShell Script  Disk Usage Report and E-Mail Current Threshold Status
Shell Script Disk Usage Report and E-Mail Current Threshold StatusVCP Muthukrishna
 
Clean & Typechecked JS
Clean & Typechecked JSClean & Typechecked JS
Clean & Typechecked JSArthur Puthin
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functionsmussawir20
 
Introduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaIntroduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaFlorent Pillet
 
Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)brian d foy
 
Unit 4
Unit 4Unit 4
Unit 4siddr
 

Similar to Memory Manglement in Raku (20)

Bioinformatica p4-io
Bioinformatica p4-ioBioinformatica p4-io
Bioinformatica p4-io
 
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QACreating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netPhp my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.net
 
Tt subtemplates-caching
Tt subtemplates-cachingTt subtemplates-caching
Tt subtemplates-caching
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Lecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administrationLecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administration
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Intro
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
 
11 Things About 11gr2
11 Things About 11gr211 Things About 11gr2
11 Things About 11gr2
 
Shell Script Disk Usage Report and E-Mail Current Threshold Status
Shell Script  Disk Usage Report and E-Mail Current Threshold StatusShell Script  Disk Usage Report and E-Mail Current Threshold Status
Shell Script Disk Usage Report and E-Mail Current Threshold Status
 
Clean & Typechecked JS
Clean & Typechecked JSClean & Typechecked JS
Clean & Typechecked JS
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
Apache Hacks
Apache HacksApache Hacks
Apache Hacks
 
Introduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaIntroduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoa
 
Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)
 
Unit 4
Unit 4Unit 4
Unit 4
 
ES6, WTF?
ES6, WTF?ES6, WTF?
ES6, WTF?
 

More from Workhorse Computing

Wheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWorkhorse Computing
 
Paranormal statistics: Counting What Doesn't Add Up
Paranormal statistics: Counting What Doesn't Add UpParanormal statistics: Counting What Doesn't Add Up
Paranormal statistics: Counting What Doesn't Add UpWorkhorse Computing
 
Generating & Querying Calendar Tables in Posgresql
Generating & Querying Calendar Tables in PosgresqlGenerating & Querying Calendar Tables in Posgresql
Generating & Querying Calendar Tables in PosgresqlWorkhorse Computing
 
The W-curve and its application.
The W-curve and its application.The W-curve and its application.
The W-curve and its application.Workhorse Computing
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Workhorse Computing
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Workhorse Computing
 
Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Workhorse Computing
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Workhorse Computing
 
Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium Workhorse Computing
 

More from Workhorse Computing (18)

Wheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility Modules
 
mro-every.pdf
mro-every.pdfmro-every.pdf
mro-every.pdf
 
Paranormal statistics: Counting What Doesn't Add Up
Paranormal statistics: Counting What Doesn't Add UpParanormal statistics: Counting What Doesn't Add Up
Paranormal statistics: Counting What Doesn't Add Up
 
Generating & Querying Calendar Tables in Posgresql
Generating & Querying Calendar Tables in PosgresqlGenerating & Querying Calendar Tables in Posgresql
Generating & Querying Calendar Tables in Posgresql
 
The W-curve and its application.
The W-curve and its application.The W-curve and its application.
The W-curve and its application.
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
 
Neatly folding-a-tree
Neatly folding-a-treeNeatly folding-a-tree
Neatly folding-a-tree
 
Light my-fuse
Light my-fuseLight my-fuse
Light my-fuse
 
Paranormal stats
Paranormal statsParanormal stats
Paranormal stats
 
Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.
 
Putting some "logic" in LVM.
Putting some "logic" in LVM.Putting some "logic" in LVM.
Putting some "logic" in LVM.
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.
 
Selenium sandwich-2
Selenium sandwich-2Selenium sandwich-2
Selenium sandwich-2
 
Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium
 
Docker perl build
Docker perl buildDocker perl build
Docker perl build
 
Designing net-aws-glacier
Designing net-aws-glacierDesigning net-aws-glacier
Designing net-aws-glacier
 
Lies, Damn Lies, and Benchmarks
Lies, Damn Lies, and BenchmarksLies, Damn Lies, and Benchmarks
Lies, Damn Lies, and Benchmarks
 

Recently uploaded

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 

Recently uploaded (20)

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 

Memory Manglement in Raku

  • 1. Raku Memory Manglement: Checking yourself out. Steven Lembark Workhorse Computing lembark@wrkhors.com
  • 2. Yes, size() matters. but it isn’t available in Raku. Process-level stats. Mainly “RSS”. getrusage(2). Acquiring & analyze data. Raku tools.
  • 3. RSS? “Resident Set Size” Virtual pages in physical memory. Accessible without a page fault. Non-resident VM may be swapped. Requires a page fault to access.
  • 4. Goals of memory managment: Work within RSS. Reduce page faults. Avoid hard faults & swapping.
  • 5. getrusage(2) Returns process memory stats. Aggregate values. Results constrained by system limits.
  • 6. getrusage(2) struct rusage { struct timeval ru_utime; /* user CPU time used */ struct timeval ru_stime; /* system CPU time used */ long ru_maxrss; /* maximum resident set size */ long ru_ixrss; /* integral shared memory size */ long ru_idrss; /* integral unshared data size */ long ru_isrss; /* integral unshared stack size */ long ru_minflt; /* page reclaims (soft page faults) */ long ru_majflt; /* page faults (hard page faults) */ long ru_nswap; /* swaps */ long ru_inblock; /* block input operations */ long ru_oublock; /* block output operations */ long ru_msgsnd; /* IPC messages sent */ long ru_msgrcv; /* IPC messages received */ long ru_nsignals; /* signals received */ long ru_nvcsw; /* voluntary context switches */ long ru_nivcsw; /* involuntary context switches */ }; POSIX
  • 7. getrusage(2) struct rusage { struct timeval ru_utime; /* user CPU time used */ struct timeval ru_stime; /* system CPU time used */ long ru_maxrss; /* maximum resident set size */ long ru_ixrss; /* integral shared memory size */ long ru_idrss; /* integral unshared data size */ long ru_isrss; /* integral unshared stack size */ long ru_minflt; /* page reclaims (soft page faults) */ long ru_majflt; /* page faults (hard page faults) */ long ru_nswap; /* swaps */ long ru_inblock; /* block input operations */ long ru_oublock; /* block output operations */ long ru_msgsnd; /* IPC messages sent */ long ru_msgrcv; /* IPC messages received */ long ru_nsignals; /* signals received */ long ru_nvcsw; /* voluntary context switches */ long ru_nivcsw; /* involuntary context switches */ }; Linux
  • 8. getrusage(2) struct rusage { struct timeval ru_utime; /* user CPU time used */ struct timeval ru_stime; /* system CPU time used */ long ru_maxrss; /* maximum resident set size */ long ru_minflt; /* page reclaims (soft page faults) */ long ru_majflt; /* page faults (hard page faults) */ long ru_inblock; /* block input operations */ long ru_oublock; /* block output operations */ long ru_nvcsw; /* voluntary context switches */ long ru_nivcsw; /* involuntary context switches */ }; Only max RSS.
  • 9. getrusage(2) struct rusage { struct timeval ru_utime; /* user CPU time used */ struct timeval ru_stime; /* system CPU time used */ long ru_maxrss; /* maximum resident set size */ long ru_minflt; /* page reclaims (soft page faults) */ long ru_majflt; /* page faults (hard page faults) */ long ru_inblock; /* block input operations */ long ru_oublock; /* block output operations */ long ru_nvcsw; /* voluntary context switches */ long ru_nivcsw; /* involuntary context switches */ }; Fault counts.
  • 10. Viewing RSS Telemetry module. Takes periodic snapshots. Allows inserting a label to track events. Core with nqp. Not synchronous with tasks. Raku
  • 11. Viewing RSS ProcStats Soon to be on CPAN. Exports “dump-rusage”. Differences from first sample. Only output changes. Track wallclock time. Optional label.
  • 12. :final Output all stats compared to first sample ProcStats sub dump-rusage ( Bool() :$final = False, Bool() :$first = $final, Bool() :$force = $final, Stringy() :$label = $final ?? 'Final' !! '' ) is export( :DEFAULT )
  • 13. :first Values compared to first sample (vs. last). ProcStats sub dump-rusage ( Bool() :$final = False, Bool() :$first = $final, Bool() :$force = $final, Stringy() :$label = $final ?? 'Final' !! '' ) is export( :DEFAULT )
  • 14. :force Write all stats (vs. only changed). ProcStats sub dump-rusage ( Bool() :$final = False, Bool() :$first = $final, Bool() :$force = $final, Stringy() :$label = $final ?? 'Final' !! '' ) is export( :DEFAULT )
  • 15. :label Add “label” key (default from :final). ProcStats sub dump-rusage ( Bool() :$final = False, Bool() :$first = $final, Bool() :$force = $final, Stringy() :$label = $final ?? 'Final' !! '' ) is export( :DEFAULT )
  • 16. Wallclock time Elapsed vs. CPU sub dump-rusage ( Bool() :$final = False, Bool() :$first = $final, Bool() :$force = $final, Stringy() :$label = $final ?? 'Final' !! '' ) is export( :DEFAULT ) { my $wtime = now.Num;
  • 17. Wallclock time Sample at top to avoid time-shift. sub dump-rusage ( Bool() :$final = False, Bool() :$first = $final, Bool() :$force = $final, Stringy() :$label = $final ?? 'Final' !! '' ) is export( :DEFAULT ) { my $wtime = now.Num;
  • 18. Values from RSS constant FIELDS = < maxrss ixrss idrss isrss minflt majflt nswap inblock oublock msgsnd msgrcv nsignals nvcsw nivcsw >; constant IGNORE = <ixrss idrss isrss ...>; constant REPORT = < maxrss majflt minflt inblock oublock >; constant MICRO = 10 ** -6; COMPARE avoids reporting on CPU swithes.
  • 19. Track progress Unchanged samples are not reported. $passes tracks total calls. state $passes = 0; state %last = ();
  • 20. Acquire data Times are sec + µsec, deal with them separately. “Z=>” zips fields & values into a hash. use nqp; nqp::getrusage( my int @raw ); my ( $user_s, $user_us, $syst_s, $syst_us ) = splice @raw, 0, 4; my %sample = FIELDS Z=> @raw; %sample{ IGNORE } :delete;
  • 21. Making time my $utime = ( $user_s + $user_us / 1_000_000 ).round( MICRO ); my $stime = ( $syst_s + $syst_us / 1_000_000 ).round( MICRO ); user & system time begin as two ints. Round gives reasonable precision in output.
  • 22. Store baseline values. state %last = state %first = ( |%sample, :$wtime, :$utime, :$stime, ); First is never updated. Get a working “last” value on the first pass.
  • 23. Store baseline values. Flatten %sample into pairs. state %last = state %first = ( |%sample, :$wtime, :$utime, :$stime, );
  • 24. Store baseline values. Times as pairs. state %last = state %first = ( |%sample, :$wtime, :$utime, :$stime, );
  • 25. First is last at first. After first last is last. my %prior = $first ?? %first !! %last ;
  • 26. What to compare? Force reports full sample. COMPARE limits keys compare to %prior & output. my %curr = ( $force || ! $passes ) ?? %sample !! do { my @diffs = REPORT.grep( { %sample{$_} != %prior{$_} } ); @diffs Z=> %sample{ @diffs } };
  • 27. Write out one stat heading & value. Compute column width once during execution. sub write-stat ( Pair $p ) { note sprintf '%-*s : %s', once {FIELDS».chars.max}, $p.key, $p.value ; }
  • 28. Write progressive value Numerics compared to starting baseline. Simplifies tracking code results. sub write-diff ( Pair $p ) { my $k = $p.key; my $v = $p.value - %first{ $k }; write-stat $k => $v; }
  • 29. First pass writes all stats. First pass has to report baseline values. state $write = &write-stat;
  • 30. First pass writes all stats. First pass has to report baseline values. After that report differences. state &write = &write-stat; ... write $stat; ... once { &write = &write-diff };
  • 31. for %curr.sort -> $stat { FIRST { note '---'; write-stat ( output => $++ ); write-stat ( :$passes ); write-stat ( :$label ) if $label; write-diff ( :$wtime ); write-diff ( :$utime ); write-diff ( :$stime ); } write $stat }
  • 32. for %curr.sort -> $stat { FIRST { note '---'; write-stat ( output => $++ ); write-stat ( :$passes ); write-stat ( :$label ) if $label; write-diff ( :$wtime ); write-diff ( :$utime ); write-diff ( :$stime ); } write $stat }
  • 33. for %curr.sort -> $stat { FIRST { note '---'; write-stat ( output => $++ ); write-stat ( :$passes ); write-stat ( :$label ) if $label; write-diff ( :$wtime ); write-diff ( :$utime ); write-diff ( :$stime ); } write $stat }
  • 34. for %curr.sort -> $stat { FIRST { note '---'; write-stat ( output => $++ ); write-stat ( :$passes ); write-stat ( :$label ) if $label; write-diff ( :$wtime ); write-diff ( :$utime ); write-diff ( :$stime ); } write $stat }
  • 35. for %curr.sort -> $stat { FIRST { note '---'; write-stat ( output => $++ ); write-stat ( :$passes ); write-stat ( :$label ) if $label; write-diff ( :$wtime ); write-diff ( :$utime ); write-diff ( :$stime ); } write $stat }
  • 36. Last steps Up total count. Store current sample for re-use. ++$passes; %last = %sample; once { &write = &write-diff };
  • 37. Baseline usage Bare for-loop Shows overhead of rusage output. #!/usr/bin/env Raku use v6.d; use FindBin::libs; use ProcStats; dump-rusage for 1 .. 1_000; dump-rusage( :final );
  • 38. Sample 0 Pass 0 as all values. Baseline for RSS & friends. --- output : 0 passes : 0 wtime : 1560968261.746507 utime : 0.344793 stime : 0.020896 inblock : 0 majflt : 0 maxrss : 99732 minflt : 25039 nivcsw : 10 nvcsw : 204 oublock : 64
  • 39. Sample 0 wtime is ‘real world’. Reasonable candidate key for sample history. --- output : 0 passes : 0 wtime : 1560968261.746507 utime : 0.344793 stime : 0.020896 inblock : 0 majflt : 0 maxrss : 99732 minflt : 25039 nivcsw : 10 nvcsw : 204 oublock : 64
  • 40. Sample 0 RSS is ~100MiB at startup. --- output : 0 passes : 0 wtime : 1560968261.746507 utime : 0.344793 stime : 0.020896 inblock : 0 majflt : 0 maxrss : 99732 minflt : 25039 nivcsw : 10 nvcsw : 204 oublock : 64
  • 41. Output Output 1+ are relative to %first. Sample N --- output : 1 passes : 1 wtime : 0.0081639 utime : 0.007295 stime : 0.000228 maxrss : 1588 minflt : 255 --- ...
  • 42. Output Output 1+ are relative to %first. maxrss & minflt cause output. Output --- output : 1 passes : 1 wtime : 0.0081639 utime : 0.007295 stime : 0.000228 maxrss : 1588 minflt : 255 --- ...
  • 43. Output Inermediate passes. Output #130: minflt 1758 -> 1759. Output --- output : 129 passes : 812 wtime : 0.4603018 utime : 0.60607 stime : 0.000175 minflt : 1758 --- output : 130 passes : 813 wtime : 0.4636268 utime : 0.609417 stime : 0.000175 minflt : 1759 ---
  • 44. Output getrulsage( :final ); Shows all fields. About 1/8 of passes had output. “Final” sample --- output : 131 passes : 1000 label : Final wtime : 0.5086002 utime : 0.654374 stime : 0.000175 inblock : 0 majflt : 0 maxrss : 6996 minflt : 1759 nivcsw : 2 nvcsw : 35 oublock : 0
  • 45. Default label. --- output : 131 passes : 1000 label : Final wtime : 0.5086002 utime : 0.654374 stime : 0.000175 inblock : 0 majflt : 0 maxrss : 6996 minflt : 1759 nivcsw : 2 nvcsw : 35 oublock : 0 “Final” sample
  • 46. Fairly low overhead. --- output : 131 passes : 1000 label : Final wtime : 0.5086002 utime : 0.654374 stime : 0.000175 inblock : 0 majflt : 0 maxrss : 6996 minflt : 1759 nivcsw : 2 nvcsw : 35 oublock : 0 “Final” sample
  • 47. Multiple threads: wallclock < user. --- output : 131 passes : 1000 label : Final wtime : 0.5086002 utime : 0.654374 stime : 0.000175 inblock : 0 majflt : 0 maxrss : 6996 minflt : 1759 nivcsw : 2 nvcsw : 35 oublock : 0 “Final” sample
  • 48. RSS grew by ~7MiB --- output : 131 passes : 1000 label : Final wtime : 0.5086002 utime : 0.654374 stime : 0.000175 inblock : 0 majflt : 0 maxrss : 6996 minflt : 1759 nivcsw : 2 nvcsw : 35 oublock : 0 “Final” sample
  • 49. Really do something... Simulate traking userid’s on a web server: Add a hash key. Increment a random value. Drop a key.
  • 50. Roll your own Random hash key via random sample. sub random-string ( Int() :$size = ( 1 .. 10 ).pick --> Str ) { constant alpha = [ 'a' ... 'z', 'A' ... 'Z' ]; alpha.roll( $size ).join; }
  • 51. Roll your own pick() returns a single, random value. sub random-string ( Int() :$size = ( 1 .. 10 ).pick --> Str ) { constant alpha = [ 'a' ... 'z', 'A' ... 'Z' ]; alpha.roll( $size ).join; }
  • 52. Roll your own roll() returns a random sample. sub random-string ( Int() :$size = ( 1 .. 10 ).pick --> Str ) { constant alpha = [ 'a' ... 'z', 'A' ... 'Z' ]; alpha.roll( $size ).join; }
  • 53. Fake userid Track key counts, active keys. sub user-add { ++%user-data{ random-string }; ++$adds; $max-keys = max $max-keys, %user-data.elems; }
  • 54. Random key selection sub user-drop { %user-data or return; ++$drops; %user-data{ %user-data.pick.key } :delete; } sub user-op { %user-data or return; ++$ops; ++%user-data{ %user-data.pick.key }; }
  • 55. Randomized, weighted trial. for 1 .. 1000 { constant weighted_operations = ( &user-add => 0.10, &user-drop => 0.10, &user-op => 0.80, ).Mix; weighted_operations.roll( 1_000 )».(); dump-rusage(label => 'Keys: '~%user‑data.elems ); }
  • 56. Define op’s and weights. for 1 .. 1000 { constant weighted_operations = ( &user-add => 0.10, &user-drop => 0.10, &user-op => 0.80, ).Mix; weighted_operations.roll( 1_000 )».(); dump-rusage(label => 'Keys: '~%user‑data.elems ); }
  • 57. 1000 iterations of trial. for 1 .. 1000 { constant weighted_operations = ( &user-add => 0.10, &user-drop => 0.10, &user-op => 0.80, ).Mix; weighted_operations.roll( 1_000 )».(); dump-rusage(label => 'Keys: '~%user‑data.elems ); }
  • 58. Report summary “say” is stdout, dump-rusage is stderr. :final uses %first as reference for values. dump-rusage( :final ); say 'Total adds: ' ~ $adds; say 'Total drops: ' ~ $drops; say 'Total ops: ' ~ $ops; say 'Max keys: ' ~ $max-keys; say 'Final keys: ' ~ %user-data.elems;
  • 59. Getting stats Easier to read with separate files. $ ./rand-user-table >stats.out 2>stats.yaml;
  • 60. Stats results Final results from “say”. Total adds: 99738 Total drops: 98755 Total ops: 787133 Max keys: 213 Final keys: 144
  • 61. Stats results Final sample: 1000 iterations/pass. Extra time from threading. ~18MiB RSS growth. --- output : 518 passes : 1001 label : Final wtime : 18.668069 utime : 18.846082 stime : 0.01101 inblock : 0 majflt : 0 maxrss : 18404 minflt : 5522 nivcsw : 61 nvcsw : 83 oublock : 128
  • 62. What you see is all you get. RSS, faults. Per-process totals. Not per structure. Randomized trials simple in Raku. Monitor results after specific operations.