Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Ignoring directories in Catalyst

by LunarCowgirl (Sexton)
on Nov 13, 2014 at 18:16 UTC ( [id://1107136]=perlquestion: print w/replies, xml ) Need Help??

LunarCowgirl has asked for the wisdom of the Perl Monks concerning the following question:

Is there any way to make Catalyst ignore certain directories? I'm using gulp to process Sass files and javascript as well as handle other project management tasks. Gulp modules are installed into a project directory called "node_modules." This directory can be quite huge -- mine is over 80MB -- and when the Catalyst development server runs, it eats up an excessive amount of resources when node_modules is present. Normal perl CPU usage for the server is 1% or less. With node_modules present, it runs 12% and over even at rest.

Catalyst is obviously trying to do something with the files in this directory, and it would be nice if I could tell it to skip them entirely. All I've managed to find, though, are ways to make Catalyst ignore .pm files (with Module::Pluggable) and static files in root (with Static::Simple). Otherwise, the only solution I can see is to create another subdirectory on the same level as node_modules and move all things Catalyst into it, and that's not optimal.

Replies are listed 'Best First'.
Re: Ignoring directories in Catalyst
by Corion (Patriarch) on Nov 14, 2014 at 08:59 UTC

    My (very rough) guess is that the Catalyst development server tries to monitor all the files for changes so it can restart. This is a very rough guess because you don't really tell us what kind of resources the server eats.

    I did not find documentation in Catalyst::Devel or in Catalyst on how to disable that file monitoring behaviour, so you might have to ask somebody who actually uses Catalyst on how to change that behaviour so that only Perl directories are monitored.

      I was just going by what a simple top tells me about resources. "perl" uses more than 12% of the CPU but less than one percent of memory while the server is waiting in restart mode. An strace shows that the server reads the node_modules directory and every file inside it. It reads every directory in the project folder and every file inside those directories, including my .scss files, which it shouldn't be concerned about at all either, though it doesn't read hidden directories. Then it goes into restart mode and sleeps. It does the exact same thing at the end when testing in a project without node_modules, so nothing telling there.

      I did find a better workaround than moving my Catalyst files into another subdirectory, though, by moving the node_modules directory somewhere else and symlinking to it. The development server doesn't follow the symlink. While that's not optimal either, it's a less ugly solution.

      I'll probably end up filing an issue on Catalyst::Devel. Using things like gulp or grunt is common enough these days. The server doesn't need to be monitoring them. A way to exclude directories and files would be helpful.

        I found a solution to my problem, though from the opposite direction. I had enough free time this weekend to delve into Catalyst's innards and trace the path of the code. The BUILD sub of Catalyst::Restarter is where the list of directories to monitor is set. There's a parameter called "exclude," and it's set to exclude "t" and "root" from monitoring as well as any hidden directories. There appears to be no way to add to or override that list though.

        Catalyst::Script::Server is where the restarter is called, and you can pass a few parameters to it from there, including this one:

        --rdir --restart_directory the directory to search for modified files, can be set multiple times (defaults to '[SCRIPT_DIR]/..')

        So it appears that you can set what directories to monitor but not set what to exclude. I can call the server with --rdir as the "lib" directory instead of the project root, which seems really the only one that needs monitoring anyway, and not have to worry about node_modules or any directories such as those with my Sass files being added to the weight of the server. If I find that anything else needs to be monitored, I can add to it, as --rdir takes an array reference of directories. So calling the server like so works for this problem:

        script/myapp_server.pl --rdir /full/path/to/lib -r

        It still would be nice to have an option to exclude directories, though, for those occasions when you only need to do so to one rather than having to build up a list of multiple approved directories, but at least there's a way to handle the issue.

Re: Ignoring directories in Catalyst
by Anonymous Monk on Nov 14, 2014 at 17:44 UTC
    Catalyst is an abysmal mess and its API is even worse. While it is an extremely lightweight solution, I have had nothing but joy and pleasure in using Dancer.

    Now if only someone would create an enterprise level alternative to Catalyst this is ... actually usable if you aren't the author. :/

      Most projects I work on straddle the line between being too big for Dancer and too small for Catalyst. I like using Catalyst though. It's certainly not easy to learn, but once you finally figure it out, you can use it quite effectively.
      I've seen Dancer used in production code. It is horrendous and disgusting. Now apparently Dancer2 is so much better etc. pp. But the Catalyst apps I've seen have always been quite a lot easier to maintain, and Catalyst has been more extensible in my experience. I'd recommend it at any time, though it does tend to be slower
      funny .. catalyst sucks, if only there was something just as big that wasn't catalyst ... it would be catalyst

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1107136]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-25 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found