Lets Get Dugg!



Not sure what that is, looks like some type of arthropod. This really reminds me of that face implant alien from the movies Aliens. Any care to guess what this is?

creature
creature
creature
creature
creature


Today as I sat down at my cubicle and did my daily routine to initiate eclipse. I encountered a horrible sight; eclipse would start and all of a sudden just crash.

I first tried the obvious solution, to clean out the workspace.

	./eclipse -clean

Nope, no go, still eclipse kept crashing. Ugh, I fell into despair, all those key-binds and spring templates, all gone. So, rationally I hopped on to #eclipse on irc.freenode.net to get some feed back on my situation. Rcjsuen was kind enough to provide the answer that would solve my problem.

The solution was fairly straight forward. I had to remove org.eclipse.core.resources from my workspace.

	cd ~/Documents/workspace/.metalog/.plugins
	rm -rf  org.eclipse.core.resources

By removing org.eclipse.core.resources, you clear out all the project metadata from your workspace. However, don't worry, once you start eclipse you can just go to "File -> Import -> import eclipse projects" and re-import all your workspace projects.


Perl, singletons, DAOs oh my!

Lately I have been toying with Wicket , Hibernate and Spring for potentially writing a large complex site. Contrary to what people say about Java web development it isn't so bad, at least with Wicket. Since toying with Hibernate and DAOs, I came to the conclusion this can work really well in Catalyst!

Instead of micromanaging what to page cache, just cache the specific area that is the performance penalty: the database.

By utilizing the singleton data access object (DAO) pattern I can avoid the headache of micromanaging what gets page cached on my site. Furthermore, this pattern gives me the flexibility to still keep the dynamism of Template Toolkit and whatever code gets executed in my controller action.

This also solves my problem of exporting incrementally with DBIx::Class::Schema::Loader without over writing whatever business logic I might of added to my classes. This pretty much keeps my controllers clean of business logic. This pattern forces me to have clean separated code.

Lets get down the the beef of how to get this all setup.

Lets begin by setting up our first(?) DAO class

Now here is our controller which utilizes are simple DAO.

So what do you think? makes sense? keeps the controllers nice and simple, without any business logic.

And time to test the performance of the implementation vs the page cache

PageCache run:

Requests per second: 97.30 [#/sec] (mean)
Time per request: 1027.70 [ms] (mean)
Time per request: 10.28 [ms] (mean, across all concurrent requests)

DAO run:

Requests per second: 66.05 [#/sec] (mean)
Time per request: 1514.10 [ms] (mean)
Time per request: 15.14 [ms] (mean, across all concurrent requests)

So it is a bit slower, well 31% slower to be exact. This is more than adequate performance for a relatively high traffic site.


Mupen64 release, I fixed long standing bugs.

Release notes
Fullscreen now works
Save folder path bug is resolved
10.2/10.3 support is depreciated

Grab the emulator on my emulation page


How to deploy a self contained Rails application on Tomcat, painlessly!

Here at work we have a Postfix email server which handles all our email for multiple domains. The authentication and users are handled via the PostgreSQL database backend. To make life easy, I used Rails to scaffold a few tables in that Postfix PostgreSQL database. End result, is an easy to use interface to manage emails and domains. However, deployment isn't as fun as it could be, even with mongrel. I still have to have Rails/Ruby installed AND manage startup scripts to start the mongrel instance for my Rails MailManager application. Well JRuby to the rescue!

Here is how I created a self-contained Rails Application that can be reused in any Tomcat deployment.

I used the pure Ruby PostgreSQL implementation instead of the Java-centric ActiveRecord-JDBC solution, so I can develop using native Ruby while deploying via WAR using JRuby without any database.yml changes!

First off we want to instal GoldSpike which adds rake tasks to create WAR files.

script/plugin install svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike

Now I needed to implement a self-contained postgres-pr module. I implemented it as a Rails Plugin!

Create the postgres plugin

./script/generate plugin postgres

Copy the postgres pure implementation gem files to your Rails plugin

cp -rf /opt/local/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/* ./vender/plugins/postgres/lib/

Setup database.yml
I setup host as pdatabase, so on any server you deploy the WAR just add an alias to /etc/hosts ; 127.0.0.1 pdatabase

production:
  adapter: postgresql 
  database: postfix 
  username: victori  
  password: .......
  host: pdatabase

Run the rake task to build your reusable self-contained web application

rake war:standalone:create

Pretty darn easy eh?


Quick blurb concerning Typeface

I have been off in Java Wicket Land for the past month or two. In this time, I have let Typeface slide without putting out much needed maintenance releases for the various quirks currently found in Typeface. Anyway, I hope to get a new release of Typeface in a few days or so that will fix some of the rough edges.


Dynamic type languages such as Perl, Ruby, PHP, and Python free you as the developer from managing memory in your application. However, it isn’t a fool proof solution that you won’t have memory leaks in your application. You as the developer should be aware of how the underlying garbage collector of your preferred language works to accommodate for the inadequacies of its garbage collection algorithm.

Currently there are two ways of doing garbage collection; mark and sweep and reference counting. The Perl interpreter uses the latter. Reference counting is a fairly simple garbage collection technique. Each time you declare an instance, the reference count increments by one. When your program reaches the end of scope, objects with a reference of one get collected. However, if your object has a reference count of two it is kept. The one main draw back of reference counting is the fact it can’t deal with circular references. This is when both objects point to each other and they never get garbage collected.

On the other hand, Ruby and Java use the mark and sweep garbage collector. I personally have mixed feelings about it, since I don’t know exactly when my objects will be collected. The way mark and sweep garbage collection works, is it does not collect anything for a period of time. At intervals when the heap gets full, it runs its garbage collection. The downside to this is you don’t know exactly know when this happens and if there are lots of objects to be collected this leads to “stutters” and unresponsiveness of the application. If you have ever used a Java swing application you might have noticed these stutters, this is when garbage collection is taking place. However, it’s not as gloomy as I set the pretense to be with the mark and sweep garbage collection. Mark and sweep garbage collection can handle cyclic references unlike with reference counting, which is a huge boon to its usefulness. There has been much work done on mark and sweep garbage collection, specifically with generational mark and sweep collectors that try to fix the unresponsiveness issue. Java currently uses a generation GC, and Ruby hopes to obtain a generational GC for the Ruby 2.0 interpreter. Ideally a generational garbage collector would be the preferred GC for a long-standing process.

With that little garbage collection background out of the way, lets look at the life cycle of a instance in reference counting garbage collector.

Here is an example of how reference counting works ideally:

Unlike mark and sweep garbage collection with reference counting, you know exactly when your instance gets collected.

Here is a very simple problematic case for reference counting:

This is a fairly simple case of where reference counting falls right on its face. Usually this isn’t a problem since most Perl scripting revolves around short-lived scripts. However, with frameworks such as Catalyst that are long running perl scripts this becomes an issue quickly. Thankfully, with Perl it is extremely easily to nail memory leaks, more so than with Ruby or Java. Enter Devel::Cycle and Devel::Peek, both of these modules can be installed from cpan. Both Devel::Cycle and Devel::Peek can assist you in tracking down the memory leak in a relatively short time.

# Sample output
# ibook:~/Desktop victori$ perl blah.pl     
# Cycle (1):  <-- find_cycle tells you literly where the cyclic reference leak is at.
#   $A->{'child'} => \%B                           
#   $B->{'parent'} => \%A                           
# 
# SV = RV(0x1817898) at 0x1800ec8
#   REFCNT = 1
#   FLAGS = (PADBUSY,PADMY,ROK)
#   RV = 0x18006dc
#   SV = PVHV(0x1830980) at 0x18006dc
#     REFCNT = 2 <-- Notice the reference count of 2 , we know we have a leak
#     FLAGS = (SHAREKEYS)
#     IV = 2
#     NV = 0
#     ARRAY = 0x404e60  (0:6, 1:2)
#     hash quality = 125.0%
#     KEYS = 2
#     FILL = 2
#     MAX = 7
#     RITER = -1
#     EITER = 0x0
#     Elt "name" HASH = 0xe6e17f14
#     SV = PV(0x1801460) at 0x1800ea4
#       REFCNT = 1
#       FLAGS = (POK,pPOK)
#       PV = 0x401730 "victor"\0
#       CUR = 6
#       LEN = 8
#     Elt "child" HASH = 0x33ec6b5
#     SV = RV(0x1817870) at 0x1832ca4
#       REFCNT = 1
#       FLAGS = (ROK)
#       RV = 0x1800484
#       SV = PVHV(0x18309b0) at 0x1800484
#         REFCNT = 2
#         FLAGS = (SHAREKEYS)
#         IV = 2
#         NV = 0
#         ARRAY = 0x404db0  (0:6, 1:2)
#         hash quality = 125.0%
#         KEYS = 2
#         FILL = 2
#         MAX = 7
#         RITER = -1
#         EITER = 0x0
#         Elt "parent" HASH = 0xa99c4651
#         SV = RV(0x18178a0) at 0x1832c44
#           REFCNT = 1
#           FLAGS = (ROK)
#           RV = 0x18006dc


So how do we fix this? Quite simple, all we do is weaken the reference count using weaken(). Here is a proper way of patching up the memory leak we introduced in our program.

We weaken the reference at the parent level to set it back to a reference count of 1, so when it reaches the end of scope it will be collected and the memory leak will be no more.

Hopefully this is a good primer for other Perl coders out there who are facing memory leaks in their running long running perl scripts.


I found this fairly entertaining, definitely worth my 4 minutes of life. For those who don't know Kabayashi is the Japanese gentleman who beats us lard ass Americans at our own game; glutting. This does deliver.


Unlike most people I came to Catalyst from the Rails camp. I miss a few things namely, file_column for mapping file uploads to the filesystem.
Thankfully writing DBIC components is fairly trivial. I wrote this in a few minutes so consider this a hack. This component makes your DBIC class dependent on Catalyst since it uses a reference from the Catalyst upload context.

I hope to improve upon this and add thumbnail support for images. For now this will do.


Instead of sitting on this any longer, I decided to release Typeface 0.7. Typeface has been updated to utilize the recent Catalyst::Controller::FormBuilder module. I have also included two new ported WordPress themes Chaotic Soul and Connections. Since refactoring the template view, porting WordPress themes is extremely trivial now.

You can find the release at http://typeface-project.org/

-Victor