Dancing Your Way into EffortLess Web Development with Dancer and Perl

Posted by feydr | Posted in Uncategorized | Posted on 26-05-2010

View Comments

Sentiments found on hackernews and dzone recently regarding Perl:

“fuck a bunch of perl monk motherfuckers!”

“perl sucks!”

“perl can suck a dick!”

ok, well that was slightly exagerrated =)

but .. so seems the sentiment sometimes browsing certain portions of the net
(dzone, hackernews, etc.)

Really, imo perl was one of the first dynamic interpreted languages that a LOT of people
got on board with and really opened the door to web development… say what
you want but perl was the “first web language”™

Dancer

A couple of weeks I ran into dancer. I was really quite interested because it’s cousin,
sinatra from rubyland is my favorite framework from that language.

I have to admit that I have not used perl for a while but I had dancer up and tapping it’s toes
within minutes and it is pretty damn fast.

can I sum it up?
yes …. dancer turns perl web development from this…


perl


into this…


marlboros camel

installing

feydr@mhu:~$ sudo cpan Dancer

cpan will block when it’s dling new modules so make sure to pay attn to any visual beeps if you are in screen or something, or you could always use expect or whatever

Sample Hello World written in Dancer

#!/usr/bin/perl
 
use Dancer;
 
get '/hi' => sub {
  "Hello World!"
};
 
dance;
feydr@mhu:~$ perl ./hi.pl

hit it up at: http://127.0.0.1:3000/hi

Some Slightly Drunken Made Benchmarks:
That last red bar should be at 672 request/second.



need some more example code? check out the dancer website source built using dancer

Deploying Dancer into Production

I’d avoid abusing this ass-rocking software with something as terrible as apache as you just won’t get the same performance and you’ll have to do stupid CGI/FastCGI tricks. However, if you must use apache (because you are already using it for 10 other websites on the same box) then you can still use PSGI.

Dancer runs best under PSGI/PLACK

Wait! What the fuck is that shit? PSGI is a spec akin to Python’s WSGI while PLACK is to ruby’s Rack.

confused? just use Starman!!Perl Reference

StarMan Features

  • preforking web server that reaps dead kids and does auto restarts
  • can utilize unix sockets
  • very little memory footprint (like 7-12 meg little)
  • No Win32 Support, yes this is a feature

It’s also written by Japanese hackers. I don’t think I need to mention why Japanese hackers rock..

Yukihiro Matsumoto

back to dancer…

supported session engines by default:

  • memory (no persistence — useful for debugging)
  • yaml file-based (puke!)
  • memcached (distributed production env ftw!)
  • cookie (make sure you protect your shit from timing attacks)

other features:

  • wilcard routing path matching
  • before filters

In comparison to Catalyst? Well, the most obvious is that Dancer is light-weight — like cheerleader on prom night light-weight.

In Closing

For my next ‘small’ project this will probably be written with Dancer rather than Sinatra.
Yes, the terse syntax of perl might not meet the eloquence of ruby but for memory usage
Dancer will win hands down everytime.

Getting Oriented with OrientDB

Posted by feydr | Posted in Uncategorized | Posted on 22-05-2010

View Comments

Was on the nosql mailing list the other day and I ran across a message from Cliff Moon trolling it up

“I find the name of your database to be extremely racist.”

To tell you the truth I usually am ctrl-D’ng (mutt mass deleting) all threads from this mailing list since I just do not have time to read them all. This of course caught my eye though and I’ve been waiting for a day to set aside some time to write up an article on it. So that day is today and this is that article.

These guys make a TON of claims and the description page is chockful of buzzwords describing what exactly OrientDB is. Let’s take a quick look.
Features

  • Written in Java
  • 40k inserts/second on commodity hardware
  • Document/Graph Based DataBase
  • Supports Schema-less, schema-full, schema-mixed modes
  • Security Profiling for users/roles Based Access
  • Supports SQL as a query language
  • ACID compliant with support for transactions
  • Less than 400k Footprint for Full Server (embeddable)

It is truthly very easy to get started unlike other solutions out there. It unfortuantely has a XML config file but the default one that comes with the release I downloaded (0.9.13) clocks in at only 22 lines and is fairly readable. It listens for binary connections on port 2424 by default and a built-in web interface on 2480 by default. The package I downloaded came with jars ready to go so there was no bullshit to configure or anything but if you grab sources ant should work things out for you.

Example:

svn checkout https://orient.googlecode.com/svn/trunk/ orient
export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.20/
chmod a+x build.sh
./build.sh

Like any good startup script it proudly displays it’s ascii logo.
It really is quite a nice little web interface I have to admit. For those of you who have/want to care about licenses it is under the Apache 2.0 License. There are currently 12 members on it’s google groups mailing list.

Web Interface
The web interface has a RESTful interface that supports GET, PUT, POST, and DELETE operations. This is really cool because then you can do all your requests with javascript and pull down result sets with json. Being able to put this crap behind a load balancer allows you to scale like a motherfucker when it comes to reads, which is one reason why other databases that have RESTful interfaces caught on so quickly. It has a built in profiler that really rocks out and I firmly believe all software should have built in shit like this — it is just common sense for applications like this. There are tabs right next to it that show you configurations, connections and and database pools — cool stuff indeed.

OrientDB Profiler

OrientDB Profiler

The schema view is pretty cool as well as you can see all of your classes (tables) , their record count and their cluster count. Physical clusters make for fast IO, whereas logicals save space but are slower. Of course in the day and age of pocket terrabyte storage drives — who the hell needs more space? We need ram and cpu damnit!

Security
I must say that out of all the NoSQL solutions out there OrientDB really fucking shines with it’s security built-in from the get-go — almost every other system out there has added it on as an *optional* feature — as if security should ever be treated that way — it’s like modern day programmers for some reason still do not know that 14 year old kids have scripts that scan the net for open things like this — some mid-20s kids have those exact same scripts. ;)

Apparently the underlying data structure is a “RB+Tree” which as the authors point out is a mix of Red-Black and B+ Tree algos — this they assert give you the best mix of balancing, speed, and 50% less memory usage.

All in all this is a pretty nice offering and I might need to play with again here in the future. I have a couple million xml documents I’m thinking about transforming to json. What are your thoughts on this fellow readers?