Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

xsawyerx (8978)

xsawyerx
  (email not shown publicly)

Journal of xsawyerx (8978)

Wednesday March 17, 2010
05:54 AM

Two Perl Mongers meetings, three talks, two reviews

Monday March 15, 2010
02:40 AM

Modules vs. Applications

Wednesday March 10, 2010
06:44 AM

Speeding Up Code

Monday March 08, 2010
04:52 AM

Dancer 1.160 is out!

Thursday March 04, 2010
11:26 AM

Search::GIN 0.04 finally out!

Monday March 01, 2010
08:20 AM

Gaming FAIL

original post can be found on my blog.

Many years ago, when I was... roughly 15 (I think), I met Theodor Ts'o (one of the first hardcore Linux Kernel hackers, since version 0.90, I believe) at a Linux event IBM organized in Israel. I should note that he is a very nice person.

After the event, we got to talk a bit. We talked about our favorite games. Mine was "avoiding segfaults". This was back when I was programming in C.

Today I wrote the following regex: qr/^([\w|\.]+)\s+(?(\d+)\s+)?(\w+)\s+(?:(\d+)\s+)?([\w|\d|\.]+)$/;

Then got a Segmentation fault

Can you spot the error?

Here's a hint: it is missing a colon (:).

This is perl, v5.10.0 built for i486-linux-gnu-thread-multi

Wednesday February 24, 2010
07:40 AM

Writing your own Search::GIN extractor

original post can be found on my blog. note: It has code embedded so it's easier to view it there.

I stumbled into a tricky situation with Search::GIN that required me to have a reverse indexing with set introspection. This situation isn't so rare, so I thought it would be helpful to share how I did it.

Suppose I have an object. The object has an attribute. The attribute is a set of objects. I need to be able to fetch the objects according to the value of an attribute of the objects in the set in the attribute of the original object. Err.. ya know what? Here's an example!

I have a few music preferences (blues, jazz, etc.), a few simpsons characters (Lisa, Homer, Barney). Each of them likes certain types of music. Lisa likes blues and jazz, while Barney only likes blues and Homer just likes stupid commercial jingles.

First define the objects:
See here

The create them:
See here

I want to be able to fetch all the people who like a certain type of music. This is a bit difficult since a person likes a set of music styles. Search::GIN::Extract::Attributes doesn't cover sets (though it would be cool if it could in the future) and I obviously don't want to go over all characters and do it.

Instead I wrote an extractor that does that:
See here

In order to use this extractor, in my DB interface (which extends KiokuX::Model) I do this:
See here

And viola!

Now using Search::GIN::Query::Manual, I can search for any Character that likes Blues music:
See here

I wanted to write all the code in this post but for some reason I can't put more than a few lines of code here and it always double spaces it. How do others put code here?

Monday February 22, 2010
01:11 PM

My first bug report!

original post can be found on my blog.

Even though I helped on various projects, I never really got a bug report on a project of my own. I've gotten offline requests (usually from people who know me personally), but never an actual RT ticket.

Today I got my first RT ticket (in the mail) and I've very proud of it!

Apparently there was a change in Template::Tiny's API. mst made it more compatible with Template::Toolkit and Adam Kennedy released Template::Tiny 0.11 and took the time to open a ticket with Dancer::Template::Tiny to require 0.11 and up, and update the code. I've updated the code, changed the requirement and done the same with Task::Dancer. Both of them on the way to CPAN as we speak.

Why am I sharing this small tidbit? (isn't tidbit a funny word? I think it is)

Because I was really excited about it. The way people take a global look on things in CPAN. Updating each other's code, tickets and patches, notifying each other of API changes that might relate, etc. In Hebrew we have two phrases that relate to this: a "big head" and a "small head". A "big head" (rosh gadol) is someone who looks at the bigger picture. A "small head" (rosh katan) is someone that tries to know the least s/he can. Even though trying to concentrate on something specific isn't bad, the terms try to relate to laziness and caring, which gives them connotations of good and bad. In English, though, it sounds like I'm vaguely cursing someone.

I really do hope I'll keep feeling good about incoming tickets. :)

01:09 PM

Dancer gets Route Caching

original post can be found on my blog.

Recently I've spent more time with Dancer development, since it's such a fast, fun and flowing project. I've written Task::Dancer (after bugging a few people on #toolchain - thanks daxim!), Dancer::Template::Tiny and even patched Dancer::Template::Tenjin (and thanks to Ido for released it so quickly!).

Once thing I recently implemented in Dancer is Route Caching. Route Caching is a new term - at least for me - since I don't remember seeing it elsewhere (though I wouldn't be surprised if it's implemented in other frameworks).

When Dancer gets all the routes you want, it compiles them into regular expressions in a registry and then matches each request against the compiled routes, returning the first match. Route Caching allows to cache the path matches.

Theoretically if you have about 40 routes, and your 10 most wanted requests are in the lower set of the registry, Dancer would still have to go over the registry top to bottom, trying to match your request to a given compiled route. This is standard procedure and makes sense in every framework. However, this could be sped up.

Route Caching caches which request went to which compiled route and returns the compiled route instead of letting it go through the registry. As if it is saying "oh, this request? I know it, it goes to this specific route, no need to check the entire registry.

This, however, could be a sensitive issue, since many variable-based paths (/get/artist/:id) can increase the cache, taking more and more. You could set a size limit or a path limit, limiting either the size of the cache (KB, MB, GB) or the amount of paths it caches.

Once I add a feature to use the disk to read and write the cache, it would enable CGI-based applications to reap the benefits as well, without having persistence.

At first I thought this was pretty cool but as the evening set I was quite discouraged thinking maybe I should have worked on actually caching the results of pages (which Dancer will have soon enough). Today Alexis showed me results of benchmarks he did.

The benchmark test is available here, and these are the results he had:
<sukria> without caching: Requests per second: 73.19 [#/sec] (mean)
<sukria> with caching: Requests per second: 225.66 [#/sec] (mean)
<sukria> SCORE!
<sukria> ;)
<sawyer> oooo

This is not bad considering the caching isn't even on results, only on the matching of routes. Not too shabby. :)

Thursday February 18, 2010
05:27 AM

Midway Culmination

original post can be found on my blog.

Recently I started a new project at $work in which I'm using a lot of cool projects (DBIx::Class, KiokuDB, Search::GIN, POE and Dancer to name a few) and it involved a lot of layers so I wanted to do this one just right.

I finally started using KiokuDB and it went relatively easy, though Search::GIN is still lacking (and 0.4 still hasn't been released to CPAN, so I'm relying on the code on Github). It's amazing how easily I can write tests with KiokuDB and plug my stuff in and out. Sometimes, I have a hard time realizing it's that simple.

I finally started using DBIx::Class correctly. Up until now, I just used it to hook up to SQLite/MySQL database tables I've previously created. Now I actually use deploy(). I've also created a full schema detail, which is something I hardly ever do. When I just started using DBIx::Class, I had a hard time going over the docs. I asked for help more than once. However, this time the documentation was a breeze, fun to read, easy to understand and I only spent a few minutes doing everything I needed. Either the docs are much better, or I'm smarter. Either way, WIN! :)

Dancer is improving rapidly. I'll be releasing Dancer::Template::Tiny soon enough, and the core is pushing more changes every day, thanks to hard-working co-developers and a steady hand at the wheel.

Last two days, however, I spent on a bug in POE::Component::Generic. Apparently, when wrapping Net::OpenSSH, some methods lead to an infinite hang. Net::OpenSSH does a lot of stream magic with stdin/stdout/stderr, and might be causing this, but I'm not sure. It could also be a reference leak. Using the async mode directly with POE::Kernel works, but gives a "connection closed" message. I've opened ticket #54744.

Yesterday I've had Nicholas Perez and Rocco Caputo help me with debugging this. I'd like extend my gratitude, this isn't the first (or even second) occasion they've helped me with POE-related problems and they put time and effort into explaining things or helping with stuff, which I really appreciate. Thanks guys, you rock.