Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How amount of data and code affects fork() performance in Perl?

Tags:

fork

perl

What is overhead of fork() in Perl in regard to Perl's own data structures? Does 1) size of code (syntax tree) and 2) amount of data in variables/references affect amount of time spent on forking?

like image 574
Oleg V. Volkov Avatar asked Dec 13 '22 00:12

Oleg V. Volkov


2 Answers

Not a Perl question, since fork is a system call. It does not matter whether that process is Perl or not, it always does the same things. It does not care about the partical internals of a process, only the total memory size has an effect.

Modern operating systems such as Linux implement COW, so fork usually returns very quickly, nearly the same for each process.

like image 61
daxim Avatar answered Dec 27 '22 06:12

daxim


The short answer is, as others have said, that the amount of code/data has no bearing on fork() performance beyond what is generically implied by your system's implementation.

However, perl itself will flush open filehandles before calling fork, per the documentation. So, yes, the number of open perl filehandles has some bearing on fork() performance.

(Threaded perl builds will also throw an internal mutex protecting memory allocation, at least under 5.16 on my system. Small, internal synchronization like that will likely vary from system to system and from perl version to perl version.)

like image 25
pilcrow Avatar answered Dec 27 '22 07:12

pilcrow