Package your own Perl for CentOS (or RHEL) as RPM

March 28th, 2010

Of course perl is easy to build and you can build your own Perl is nice, but it needs to be managed on the target host where it is deployed. As internet access to CPAN is not available everywhere (we are talking about enterprise and carrier deployments here) updates need to be managable. At least on a basic level.

Excactly this can be done by just packaging up your contents of /opt/perl5 using a quite simple RPM spec file. It’s important to use the AutoReqProv: no flag to avoid rpmbuild thinking too much and trying to find out which modules are packaged here. On the other hand this requires, that you add certain libs that this perl depends on manually. There is a chance that you could just override %__findrequires macro here, but that does not work for me, as setting it on the package level yielded strange errors for me.

Here is an shortened example of how this specfile perl5-custom.spec should look. Your perl is expected to be found in /opt/perl5:

Summary: Perl 5 custom install to /opt/perl5
Name: perl5-custom
Version: 5.10.1
Release: 1
Vendor: quikit.at
License: Artistic 2.0
Provides: perl5-custom
Group: Languages
BuildRoot: /tmp/%name-root
Requires: MySQL-client-community >= 5.0.18
Requires: shared-mime-info >= 0.19
Requires: libxslt >= 1.1.17
AutoReqProv: no

%changelog
* Sun Mar 28 2010  5.10.1-1
- Initial packaging of Perl 5.10.1 in /opt/perl5
- Included Modules:
  Task::Moose, Task::KiokuDB, Task::Plack
  EV, AnyEvent, AnyEvent::*
  DateTime, Log4perl, DBI, DBIx::Class, DBD::mysql
  Starman, Starlet, Tatsumaki

%description
Custom Perl 5 with server-specific modules pre-installed

%prep
%build

%install
SRCDIR=/opt/perl5

rm -rf $RPM_BUILD_ROOT
echo "Copy complete perl5 base directry to buildroot"
mkdir -p $RPM_BUILD_ROOT/$SRCDIR
cp -Rp $SRCDIR/* $RPM_BUILD_ROOT/$SRCDIR/

%clean
rm -rf $RPM_BUILD_ROOT

%pre
%post
%preun
%postun

%files
%defattr(644,root,root)
%attr(755,root,root) /opt/perl5/bin/*
/opt/perl5/lib/*
/opt/perl5/man/*
%dir %attr(755, root, root) /opt/perl5/bin
%dir %attr(755, root, root) /opt/perl5/lib
%dir %attr(755, root, root) /opt/perl5/man

Then just run rpmbuild -ba perl5-custom.spec and you get an installable package, which can be updated over time by updating modules on your build host and repackaging it.

  •   Category: Bits & Bytes   A-Tags: ,
  • Comments Off on Package your own Perl for CentOS (or RHEL) as RPM

Build your own (faster) perl

March 27th, 2010

Using the perl that comes with your distribution is usually fine, but it has some limitations. When building a perl for a distribution it needs to be versatile and fit various needs. Therefor ithreads, the perl specific threading implemenation, is enabled there, to allow building modules that require threads to be available.

The downside is, that this threading code adds some quite low-level overhead, which usually means that a perl compiled with threads takes a performance hit of up to about 10%. So it sometimes makes sense to build your own perl, especially if you know it’s going to be used more on the server side, for long-running processes. Saving 10% in CPU cycles means potential for 10% in power saving or giving other processes a chance to run.

Building perl is really straightforward and usually just takes these steps:

  • Download the latest stable Perl from perl.org
  • Unpack it to a temporary directory
  • sh Configure -de -Dprefix=/opt/perl5
  • make && make test && make install
  • Perl is now installed in /opt/perl5

Now you can add any additional modules that you like, some recommended ones are:

  • App::cpanminus
  • Task::Kensho
  • Task::Plack
  • Task::KiokuDB
  • Mojolicious
  • Starman
  • Starlet
  • EV
  • AnyEvent
  • AnyEvent::MP
  • DBIx::Class
  • MongoDB
  • Data::FormValidator

Using the newly built perl just requires to update your path before starting your perl programs:

  • export PATH=/opt/perl5/bin:$PATH
  • /usr/local/bin/myperlprog

After setting the PATH just verify with perl -v that your perl include path points to /opt/perl5 (or any other path you chose).

Add benchmarking tests to MooseX::Log::Log4perl to verify overhead

May 20th, 2009

After a while I had the chance to get back to MooseX::Log::Log4perl, which is Role (based on Moose) that can be easily reused in classes requiring logging functionality.

While it is really simple to use, I still found myself often directly using the default logger approach by creating a class variable and using that. So instead of:

use Moose;
with MooseX::Log::Log4perl;
sub whatever {
    my $self = shift;
    $self->log->debug("Here I am") if $self->log->is_debug;
}

mostly the direct logger was used in the classes.

   
use Log::Log4perl;
use vars qw($log);
$log = Log::Log4perl->get_logger(__PACKAGE__);
sub whatever {
    my $self = shift;
    $log->debug("Here I am") if $log->is_debug;
}

One reason was that during that time I optimized for speed and found a hotspot to be the additional method call for the “log” method. As perl has some overhead in calling functions, this still holds true to some extend, so that’s why I added a benchmarking test to the testsuite of MooseX::Log::Log4perl.

So if you have the chance, I’d like to see if in your test environment still the performance limits (keep overhead lower than 5% compared to using Log::Log4perl directly). To run the test simply get the sources and run the test.

cpan> look MooseX::Log::Log4perl
shell# TEST_MAINT=1 prove -l -v t/99_bench.t
t/99bench.t .. 
1..6
ok 1 - Bench instance for MooseX::Log::Log4perl isa BenchMooseXLogLog4perl
ok 2 - Bench instance for Log::Log4perl isa BenchLogLog4perl
                     Rate MooseX-L4p log MooseX-L4p logger Log4perl method Log4perl direct
MooseX-L4p log    21235/s             --               -0%             -4%             -6%
MooseX-L4p logger 21273/s             0%                --             -4%             -6%
Log4perl method   22102/s             4%                4%              --             -2%
Log4perl direct   22535/s             6%                6%              2%              --
...

If all tests pass you stayed within the limits (around 95% compared to using Log4perl directly). I’d like to see your results. So please comment on it and add the comparison table to it.

Bringing logging to Moose with MooseX::Log::Log4perl

July 13th, 2008

Finally after some playing around and discovering the main concepts behind moose and failing to find a logging role using my favorite logging system log4perl I sat down an did a little coding (it is really just a few lines) and uploaded to CPAN as MooseX::Log::Log4perl.

As I already received some valuable feedback by Michael Schilli of Log4perl fame, the interface might change a little (staying backwards compatible) to be easier to use for small projects by using something like with MooseX::Log::Log4perl qw(:easy) to give you methods for log_error, log_warn, log_debug, … directly on your class instance.

If your interested see the open RT ticket 37655.

This module was actually written as part of my other project called QuikPlan, a course scheduling and management web application.

primary