MCE::Util(3)
๐ MCE::Util โ Utility functions ๐
okay bestie, this is the MCE::Util page from the User Contributed Perl Documentation, and it's literally just the lil' helper drawer for MCE. let's get into it ๐ซถ
โจ VERSION โจ
This document describes MCE::Util version 1.902. yes, that's the version. no, don't ask me to make it cuter, it's a number ๐
๐ธ SYNOPSIS ๐ธ
use MCE::Util;
that's it. that's the whole vibe. so simple. so clean. icon behavior honestly โจ
๐ฆ DESCRIPTION ๐ฆ
so this is a utility module for MCE โ like the little purse of tools that MCE carries around. and here's the tea: nothing is exported by default. nope. not a single thing. you gotta ask for it.
the one thing you can export is get_ncpu. that's the only exportable, periodt.
๐ get_ncpu() ๐
okay so this one returns the number of logical (online/active/enabled) CPU cores. and โ important โ it will never be smaller than one. so even if your machine is being weird about it, you get a 1 minimum. no zeros, no negative nonsense, we don't do that here ๐
my $ncpu = MCE::Util::get_ncpu();
now, the fun part: if you specify 'auto' for max_workers, it calls MCE::Util::get_ncpu automatically for you. but listen โ MCE 1.521 sets an upper-limit when specifying 'auto'. why? mainly to safeguard apps from spawning 100 workers on a box having 100 cores. that's a lot of workers, bestie. and it's especially important for apps that are IO-bound. iykyk.
here's the whole thing in code, exactly as it lives:
use MCE;
## 'Auto' is the total # of logical cores (lcores) (8 maximum, MCE 1.521).
## The computed value will not exceed the # of logical cores on the box.
my $mce = MCE->new(
max_workers => 'auto', ## 1 on HW with 1-lcores; 2 on 2-lcores
max_workers => 16, ## 16 on HW with 4-lcores; 16 on 32-lcores
max_workers => 'auto', ## 4 on HW with 4-lcores; 8 on 16-lcores
max_workers => 'auto*1.5', ## 4 on HW with 4-lcores; 12 on 16-lcores
max_workers => 'auto*2.0', ## 4 on HW with 4-lcores; 16 on 16-lcores
max_workers => 'auto/2.0', ## 2 on HW with 4-lcores; 4 on 16-lcores
max_workers => 'auto+3', ## 4 on HW with 4-lcores; 11 on 16-lcores
max_workers => 'auto-1', ## 3 on HW with 4-lcores; 7 on 16-lcores
max_workers => MCE::Util::get_ncpu, ## run on all lcores
);
the way that 'auto' can do math now?? *, /, +, - โ it's giving calculator energy ๐งฎโจ
โญ In summary โญ
- Auto has an upper-limit of 8 in MCE 1.521 (# of lcores, 8 maximum)
- Math may be applied with auto (
*/+-) to change the upper limit - The computed value for auto will not exceed the total # of lcores
- One can specify
max_workersexplicitly to a hard value MCE::Util::get_ncpureturns the actual # of lcores
like, five whole facts. we ate. ๐
๐ ACKNOWLEDGMENTS ๐
shoutout time!! the portable code for detecting the number of processors was adopted from Test::Smoke::SysInfo. giving credit where credit is due, as one does ๐
๐ INDEX ๐
- MCE
- MCE::Core
๐ AUTHOR ๐
Mario E. Roy, <marioeroy AT gmail DOT com>
and that's the whole page bestie!! this was written for perl v5.42.0 on 2025-09-10, and it's MCE::Util(3) from the User Contributed Perl Documentation. go forth and count your cores, you absolute icon ๐โจ๐ฆ
๐ฆ where this page comes from
- fedora 43: perl-MCE 1.902-1.fc43 ยท GPL-1.0-or-later OR Artistic-1.0-Perl
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms