You can make the most of multiCPU even in Perl

Perl explains how to support multiple CPUs. There are many misunderstandings on the Web that Perl may not support multiple CPUs.

The exact information is that one method can support multiple CPUs, and another method cannot.

Let's understand what kind of method can support multi-CPU and what kind of method can not support multi-CPU.

Multi-CPU support using pre-fork in web applications

In Perl, if it is a Web application, you can use a function called prefork to support multiple CPUs.

You can make full use of the resources of multiple CPUs by using a function called prefork.

The misunderstanding is that in Perl, you can make full use of the resources of multiple CPUs by using a web server that supports preforking in your web application.

Web servers that support prefolk include Starman and Mojolicious.

Starman

Starman is a web server that supports Perl prefolks.

Starman is a versatile Prefork web server based on the Net::Server module. The author is Mr. Miyagawa who develops PSGI / Plack and formulates specifications.

The 24th PSGI / Plack Practice Introduction-Starman, Starlet, Twiggy, Plack::Middleware, Server: : Starter (2)>

Mojolicious

A Perl web framework called Mojolicious has a prefolk-enabled web server.

Mojo::Server::Prefork is a full-featured UNIX-optimized UNIX-optimized asynchronous IO HTTP and WebSocket built-in server.

Mojo::Server::Prefork --Prefork non-blocking IO HTTP WebSocket server

Why is it believed that Perl cannot make good use of multiCPUs?

In general, multi-CPU support starts with the topic of threads as the very first topic.

Or, it's not a thread, but it starts with the topic of whether the language has a mechanism that can use multiple CPUs.

In the case of Perl, threads are a deprecated feature and are expected to operate as a single thread.

Perl is not multi-CPU compatible as a language feature.

From this, it is misunderstood that Perl is not multi-CPU compatible as a language function, and it is misunderstood that Perl cannot support multi-CPU.

Perl uses the Unix / Linux fork function, and if you use a web server that implements preforking, you can support multiple CPUs in your web application.

It's not a feature of Perl's language itself, but if you use a method that doesn't use the feature of the language itself, you can support multiple CPUs.

If you use the language extension called XS, parallelization by GPU and CPU is also possible

When it comes to parallel processing, if you really want the performance of parallelization, you need to know that threads can only give you poor performance.

The cost of thread switching is high, and triple the number of threads does not triple the performance.

In order to make the best use of computational resources, it is necessary to optimize at the hardware level such as GPU and CPU.

In Perl, you can use XS, a C / C ++ language extension to write C / C ++ and GPUs. You can perform parallel processing by hardware using a C-like language.

At the Perl level, it is single thread, but if you write it at the C / C ++ level, you can make the best use of the parallel function of hardware such as CPU and GPU.

Associated Information