Posts Tagged ‘Perl’

Memcached – Clustered

Posted in Technical on December 16th, 2011 by iyoung – Be the first to comment

I didn’t find a great deal of information about how to run memcached across multiple servers and have them treated as one pool. Most of the examples just seem to show the installation and running of a single server instance or multiple instances on the same server running on different ports.

Far more useful in my opinion is running memcached on a number of servers in a web cluster. Now the install is as simple as “yum install memcached”. The following will start the server as a daemon on each of the machines in the cluster: -

memcached -d -p 11211 -u nobody -c 1024 -m 1024

This starts the service on port 11211 and is set to use 1gb of RAM.

Now in your code, when you instantiate your memcached object, you can pass an array of servers, this is the pool. The following is an example in Perl.

use Cache::Memcached;

  $memd = new Cache::Memcached {
    'servers' => [ "10.0.0.15:11211", "10.0.0.15:11212", "/var/sock/memcached",
                   "10.0.0.17:11211", [ "10.0.0.17:11211", 3 ] ],
    'debug' => 0,
    'compress_threshold' => 10_000,
  };
  $memd->set_servers($array_ref);
  $memd->set_compress_threshold(10_000);
  $memd->enable_compress(0);

CPAN install BDB::informix Perl

Posted in Technical on October 11th, 2011 by iyoung – Be the first to comment

Got tasked with getting the Informix DBI module working for a webserver today and found it rather unpleasant, so I thought I would share the method I used to get it working.

####### added the following to /usr/informix/etc/sqlhosts
devsportdb5     onsoctcp        hostnameofserver    ids_tcp

####### ontlitcp (On Solaris)

####### Set the following environment variables

DBD_INFORMIX_USERNAME=informixuser
DBD_INFORMIX_PASSWORD=password
DBD_INFORMIX_DATABASE=databasename
INFORMIXDIR=/usr/informix/
INFORMIXSERVER=devsportdb5
LD_LIBRARY_PATH=/usr/informix/lib/:/usr/informix/lib/esql/
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/informix/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:$INFORMIXDIR/bin:

export DBD_INFORMIX_USERNAME
export DBD_INFORMIX_PASSWORD
export DBD_INFORMIX_DATABASE
export INFORMIXDIR
export INFORMIXSERVER

### added the following to /etc/services
ids_tcp         1526/tcp                        # informix service

### Force install
perl -MCPAN -e "CPAN::Shell->force(qw(install Bundle::DBD::Informix));

I found these far more helpful than the CPAN page

http://www-01.ibm.com/support/docview.wss?uid=swg21252384
http://www.webmasterkb.com/Uwe/Forum.aspx/perl-dbi/1568/DBD-Informix-Make-test-Problem
http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.sqlr.doc/sqlrmst228.htm


Regex words not starting with..

Posted in Technical on June 22nd, 2011 by iyoung – Be the first to comment

Pretty simple thing, but I wanted to check if a string had any words not starting with a “-” using a regular expression in Perl, I just though I would share what I had.

[code]/(?

So I used a combination of the negative lookbehind zero width assertion “?<!” and the word boundaries .”b”


Sphinx and dates

Posted in Technical on October 20th, 2010 by iyoung – Be the first to comment

I have just been making a new Sphinx index, we needed to index the dates of items in the database as well as the fulltext information and some integer fields for filtering. That all seems very straightforward, there’s even a timestamp type in sphinx, so following the examples you would just use MySQL’s UNIX_TIMESTAMP function to get you seconds since the epoch. The problem is dates before 1970 of course, as MySQL just returns 0 for those as expected, and even if you did some trickery, sphinx won’t support negative timestamp values.

At the moment, I am using TO_DAYS for my date fields, and then doing TIME_TO_SECS for the time field and storing them in unsigned 32 bit integer attributes for filtering. This is fine for us because we actually filter on the days only, but we do use the time in the sorting, so I can just use the Sphinx extended sorting syntax.

Finally on the code side, you would need to use something like Date_to_Days from Date::Calc(for Perl) to convert inputted dates into days.


CPAN force install memcached

Posted in Technical on September 8th, 2010 by iyoung – 3 Comments

Strangely the Perl module Cache::Memcached won’t install cleanly without the machine it’s being installed on having a running instance of memcached. I wanted to install the module on a webserver and intended to have memcached running on a database load balancer so didn’t want it installed and running on the webserver.

So you have to force an install with [code]perl -MCPAN -e "CPAN::Shell->force(qw(install Cache::Memcached));"[/code]

Just thought I would put it up incase anyone else wanted to force install with CPAN.