title: Loading Perl modules into memory for Nginx, to make faster?
body: <p>I'm trying to speed up my Perl scripts on an <strong>nginx</strong> server. In a test script, if I comment out the "use" requests for 3 <strong>.pm</strong> files (all of which do their own stuff) ... the script looses about 600ms of load time! Now my guess, is that its because its having to load sub-modules from within the requested ones. For example:</p>
  
  <pre><code>use WebService::Solr;
  use WebService::Solr::Query;
  use Want::View;
  use JSON;
  use POSIX;
  </code></pre>
  
  <p>On <em>Apache</em> with <em>mod_perl</em>, you can set the startup script so it "imports" the modules into memory (to make it faster). Is something similar possible with nginx and Perl? My live script it currently taking 1.1 seconds to process (of which 800-900ms of that is "waiting" for it to respond!!!!), so I really need to see about speeding it up.</p>
  
  <p><strong>UPDATE:</strong> I found this, but it doesn't seem to work:</p>
  
  <p><a href="http://search.cpan.org/~zzz/Nginx-Perl-1.2.9.7/src/http/modules/perl/Nginx.pm#DESCRIPTION" rel="nofollow">http://search.cpan.org/~zzz/Nginx-Perl-1.2.9.7/src/http/modules/perl/Nginx.pm#DESCRIPTION</a></p>
  
  <pre><code>location ~ \.cgi$ {
  
      perl_inc     /usr/local/share/perl/5.20.2/;
      # perl_require WebService/Solr;
  
      ... rest
  
  }
  </code></pre>
  
  <p>I get an error:</p>
  
  <blockquote>
    <p>nginx: [emerg] unknown directive "perl_inc" in
    /etc/nginx/sites-enabled/site.net:134</p>
  </blockquote>
  
  <p>I'm wondering if its because I need to install the "Nginx" Perl module. When I try and install it via MCPAN though, I get a die:</p>
  
  <blockquote>
    <p>-lpthread -lcrypt -lcrypto -lcrypto -lz \
    -Wl,-E -fstack-protector -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu/perl/5.20/CORE -lperl -ldl -lm -lpthread -lc -lcrypt /usr/bin/ld: cannot find -lperl collect2: error: ld returned 1 exit status objs/Makefile:213: recipe for target
    'objs/nginx-perl' failed make[1]: <strong>* [objs/nginx-perl] Error 1
    make[1]: Leaving directory
    '/root/.cpan/build/Nginx-Perl-1.2.9.7-dbUMQF' Makefile:9: recipe for
    target 'build' failed make: *</strong> [build] Error 2<br>
    ZZZ/Nginx-Perl-1.2.9.7.tar.gz   /usr/bin/make -- NOT OK</p>
  </blockquote>
  
  <p>Thanks!</p>