Frage

I have a catalyst web server. I can see every child server process load a lot of same .so files individually, which take a lot of memory.

Is there any possible Catalyst preload all .so file once for all child processes?

War es hilfreich?

Lösung

The specific behavior you are describing is a feature of mod_perl rather than Catalyst itself. But you can of course run your Catalyst application under a mod_perl environment.

Under mod_perl there can only load shared library files once and it is not possible to have different versions. Aside from the saving of loading for multiple children this would actually work over different applications on the same server. So two different web applications using the mod_perl interpreter would actually share a loaded instance of a lirbrary that they both used.

For this reason, most people generally prefer to not use mod_perl as a means of serving their application, because they actually want to maintain different library versions per application. For the reasons described above this would not be possible in this environment.

But if that is something that you believe suits your needs, then mod_perl may be the environment for you.

Support for mod_perl with Catalyst is in a slight state of flux. The generally preferred method is to use the Plack::Handler methods to bootstrap Catalyst as a PSGI application to the mod_perl environment. There are some additional notes on configuration here.

Andere Tipps

I don't know what options are available in built-in Catalyst server, but looking at the documentation for Starman shows this option:

--preload-app

This option lets Starman preload the specified PSGI application in the master parent process before preforking children. This allows memory savings with copy-on-write memory management. When not set (default), forked children loads the application in the initialization hook.

Enabling this option can cause bad things happen when resources like sockets or database connections are opened at load time by the master process and shared by multiple children.

Since Starman 0.2000, this option defaults to false, and you should explicitly set this option to preload the application in the master process.

Alternatively, you can use -M command line option (plackup's common option) to preload the modules rather than the itself.starman -MCatalyst -MDBIx::Class myapp.psgi

will load the modules in the master process for memory savings with CoW, but the actual loading of myapp.psgi is done per children, allowing resource managements such as database connection safer.

If you enable this option, sending HUP signal to the master process will not pick up any code changes you make. See "SIGNALS" for details.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top