My Informal CV and a note to recruiters.


This didn’t turn out as planned. Started as what was suppose to be a note to recruiters and a small summary of things I like to help them decide if I would like a job or not but by the end of it I’d ranted about far too many things but I’m leaving it as is…already took the time to write it so why not.

Note to recruiters:

To give this a little context. I (like most I know in our field) get hounded by recruiters. It’s not a problem for me. I really don’t mind. I think it’s great, give us a lot of opportunities so don’t stop.
But don’t be rude if you get a no. (A note to you, if you were standing near me I’d have floored you then and there, you have no manners!). Read more of this post

Hypnotic photo


I was looking a Lorenzo‘s slides (slide 50)  and found a very interesting and hypnotic photo. I stole it from his slides and made it into my desktop wall paper, I really like the effects this image has on the eyes… Making a flat 2D image seem so 3D without all the fancy this and that.
So without further ado:

Hypnotic image

Install thrift and build PHP (and other language) bindings for Cassandra


Install thrift and build PHP bindings for Cassandra

This guide should work for 0.7+ versions of Cassandra. Other versions may need tweaking here and there but the general path should be similar. Lets begin…

Install thrift dependencies

yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel

Download thrift

wget http://mirrors.enquira.co.uk/apache/incubator/thrift/0.5.0-incubating/thrift-0.5.0.tar.gz
extract

tar –xvf  thrift-0.5.0.tar.gz

cd  thrift-0.5.0

./configure

make && make install

Once its all completed you should now be able to run thrift, test it by typing:

thrift

and you should get an output telling you a bunch of options are available. If not something went wrong when you were installing and you need to try and find where the error occurred and fix it.

Now lets download Cassandra’s source so that we can get the thrift file from it:

wget  http://mirror.fubra.com/ftp.apache.org/cassandra/0.7.0/apache-cassandra-0.7.0-src.tar.gz

tar -xvf apache-cassandra-0.7.0-src.tar.gz
cd apache-cassandra-0.7.0-src/interface

You should see some files listed, the one we’re interested in is cassandra.thrift …

Now we can generate the thrift bindings for any of the supported languages:

#thrift –gen XYZ cassandra.thrift

Where xyz is the language you need, so for PHP it would be:

thrift –gen php cassandra.thrift

You will now have a gen-php folder in the directory, it contains the subdirectory for Cassandra and finally the php files. The files cassandra_constants.php, Cassandra.php  and cassandra_types.php should have been generated.

Lets copy the generate files to our website include path for use later.

cd gen-php
tar –cvf cassandra.php.tar
#now copy or move (mv) the archive to your website’s include path
#cp cassandra.php.tar /home/username/websiteRoot/includes/thrift

You can now include these files in your PHP program. There are additional files that you need to find and include. One such file is Thrift.php, depending on the system you’re running the location may be different.

On my Centos distro, it is located in /usr/lib/php/ – along with the folders “protocol” and “transport” and a second file, “autoload.php”

If you open the Cassandra.php file from earlier, you’ll notice it is including files from “thrift_root” or similar. These files are the ones you need to copy to wherever you want you thrift root location to be. Since I only have the thrift files in /usr/lib/php I’m going to tar this folder and copy it to a location where I want to include files from. If that directory contains files not belonging to thrift then only copy Thrift.php, protocol and transport.

#create an archive of the required files
cd /usr/lib/php/
tar  -cvf  thrift.php.tar *
#now copy or move (mv) the archive to your website’s include path
#cp thrift.php.tar /home/username/websiteRoot/includes/thrift

We now have the Cassandra PHP bindings as well as the required PHP thrift files.
extract the files from the tar archives and put them all in the folder thrift (or whichever you want).

Cassandra.php,Cassandra_constants.php and Cassandra_types.php includes the thrift php files in the following manner:

 include_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
 

You need to therefore set THRIFT_ROOT in your PHP file like this:

 $GLOBALS['THRIFT_ROOT'] = '/home/username/websiteRoot/includes/thrift';

//where /home/username/websiteRoot/includes/thrift is the location of Thrift.php
 

You’re now ready to test it all out. The example at  http://wiki.apache.org/cassandra/ThriftExamples#PHP

Should work nicely. In a future tutorial, I’ll write some PHP examples using thrift.

You may also download the files I generated for 0.7 while doing this tutorial:
PHP bindings
http://www.crlog.info/wp-content/uploads/2011/02/phpBindings.tar

Thirft files

http://www.crlog.info/wp-content/uploads/2011/02/thrift.php_.tar

NoSQL/Cassandra Presentation by Ran/Outbrain


I found this useful while preparing my own presentation for an up coming event in March. Just thought I’d share :)

https://docs.google.com/present/embed?id=ahbp3bktzpkc_145c5gmf2gz&size=m
A link to the google docs presentation if the above doesn’t work : https://docs.google.com/present/view?id=ahbp3bktzpkc_145c5gmf2gz

Building a simple Java none-blocking server


O’reily NIO tutorial(1)

I found myself in need of a way to connect to Cassandra 0.7
Existing clients are either unreliable or none existent. Being a fan of the
Java hector client (which is undoubtedly the best I’ve found) I decided to write a language independent
“wrapper” around the hector API.

I’ll cover the client a different blog post, but I wanted to write a socket server that’ll handle multiple users at the same time.
I t turns out using the raw Java NIO package would end taking the attention away from writing the Cassandra “client” so in the end
I used the server library, Netty… Below is the code I had up to the point I moved to Netty.
It allows multiple connections on the same socket but the requests are still processed sequentially which means, if a single request
hangs then all subsequent requests will hang until the connections start to timeout or the server is overloaded and turns over.

package info.crlog.server;

import info.crlog.interfaces.Constants;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.util.Iterator;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *based on http://tim.oreilly.com/pub/a/onjava/2002/09/04/nio.html?page=2
 * @author Courtney
 */
public class Server implements Constants {

    private int port = 9969;
    private String host = "127.0.0.1";

    public static void main(String[] args) {
        Server serv = new Server();
        serv.init();
    }

    private void init() {
        try {
            // Create the server socket channel
            ServerSocketChannel server = ServerSocketChannel.open();
            // nonblocking I/O
            server.configureBlocking(false);
            // host-port
            server.socket().bind(new InetSocketAddress(host, port));
            System.out.println("Server connected on " + host + ":" + port);
            // Create the selector
            Selector selector = Selector.open();
            // Recording server to selector (type OP_ACCEPT)
            server.register(selector, SelectionKey.OP_ACCEPT);
            // Infinite server loop
            for (;;) {
                // Waiting for events
                selector.select();
                // Get keys
                Set keys = selector.selectedKeys();
                Iterator i = keys.iterator();
                // For each keys...
                while (i.hasNext()) {
                    SelectionKey key = (SelectionKey) i.next();
                    // Remove the current key
                    i.remove();
                    //see if client is requesting connection
                    if (acceptConn(key, server, selector)) {
                        continue;
                    }

                    // then the server is ready to read
                    if (performIO(key)) {
                        continue;
                    }
                }
            }
        } catch (IOException ex) {
            Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private boolean performIO(SelectionKey key) throws IOException {
        if (key.isReadable()) {
            SocketChannel client = (SocketChannel) key.channel();
            // Read byte coming from the client
            int BUFFER_SIZE = 32;
            ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
            try {
                client.read(buffer);
            } catch (Exception e) {
                // client is no longer active
                e.printStackTrace();
                return true;
            }
            buffer.flip();
            Charset charset = Charset.forName("ISO-8859-1");
            CharsetDecoder decoder = charset.newDecoder();
            CharBuffer charBuffer = decoder.decode(buffer);
            Handler dataHandler = new Handler();
            client.write(ByteBuffer.wrap(dataHandler.processInput(charBuffer.toString()).getBytes()));
            client.socket().close();
            return true;
        }
        return false;
    }

    private boolean acceptConn(SelectionKey key, ServerSocketChannel server, Selector selector) throws IOException {
        // if isAccetable = true
        // then a client required a connection
        if (key.isAcceptable()) {
            // get client socket channel
            SocketChannel client = server.accept();
            // Non Blocking I/O
            client.configureBlocking(false);
            // recording to the selector (reading)
            client.register(selector, SelectionKey.OP_READ);
            return true;
        }
        return false;
    }
}

There are comments included to help you follow, the page cited below has an excellent tutorial and indept description of how
to get this all done so if you’re having problems making it work, ask in the comments or have a read through the tutorial linked
below.
Further reading:
[1]Introducing Nonblocking Sockets by Giuseppe Naccarato

My new blog :-)


I finally decided to collate all my posts and articles one blog. I’m considering moving all my old posts. Sounds like a job that will take a while, I may just leave them all on the various sites… who knows.

Follow

Get every new post delivered to your Inbox.

Join 346 other followers

%d bloggers like this: