25 Aug 2010

Reality

What is reality? Are you real, are the people around you real?

If you have some spare time I recommend those articles about theoretical and philosophical theories about our reality or what we call so ;-)

8 Aug 2010

fast as lightning - again

I have a lot of stuff on my Mac Book Pro. Especially for my
work i need a lot of applications and services running at the same
time, e.g. VMWare, MSSQL Server, PostgreSQL, MySQL, Apache, Eclipse,
Firefox, Safari, Xcode, and so on, not forgetting the applications
that make you feel comfortable at work like iTunes :-) . And because
it's a Mac, you'll never turn it off. I'm actually wondering why this
device has an on-off switch - probably it's just an on switch (just
kidding).

However, for a long time I was very excited how well everything
performs, but at some point you notice the latency gaps between a
click and the application response. Sooner or later, depending to your 
personal threshold of discomfort, you will decide to do something
against these latency issues.

I got 8GB RAM and guess what ... it's fast as lightning - again :)

19 Jun 2010

RecordColumnNameDecorator - A Doctrine Compatibility Decorator

I mentioned that we’re migrate our application from pure SQL to an ORM-Layer. Many of the existing functions work with column names of the database tables. Sometimes these column names are used hard coded or directly linked to the view layer. The actual problem is that we used the opportunity of the migration to unify the denotation of our tables and column names via the doctrine alias functionality. At the end we had functions using the old syntax and models with a new stylish unified nomenclature.

Fortunately it’s all OOP :)

The functions need a way to get the data from a given “Array”, but with the real column names instead of the new field names. The Doctrine_Record implements the ArrayAccess-Interface, which solves the problem that Doctrine_Record object should behave like an Array. The compatibility issue is solved through a small decorator which is currently not more as a proof of concept. The decorator change the functionality of the implemented ArrayAccess-Interface so that will accept real column names.

/**
 * A Doctrine_Record uses field names instead of columns names
 *
 * The RecordColumnNameDecorator change the functionality how
 * you call data from a Doctrine_Record. You can use the original
 * column names instead of the field alias.
 *
 * @author     Enrico Stahn <stahn@rib.de>
 * @version    SVN: $Id$
 */
class RecordColumnNameDecorator extends Doctrine_Record
{
  protected $record;

  public function __construct(Doctrine_Record $record)
  {
    $this->record = $record;
  }

  public function offsetGet($key)
  {
    return $this->record[$this->record->getTable()->getFieldName($key)];
  }

  // ... Implement the rest of the interface
}

Example:

// old: ugly_tablename.ugly_column_name
// new: foo.bar
$a = new Foo();
$b = new RecordColumnNameDecorator($a);
echo $a->bar;
echo $b->ugly_column_name

easy-peasy :)

11 Jun 2010

PostgreSQL - Add primary key to an existing Table

The next months are full of hard work because we have to master a huge migration task. We migrate all SQL-Statements to an ORM Layer. The application is already a bit long in the tooth and has approximately 8000 queries. The database itself has some strange design issues and some of them are incompatible with the ORM layer. One of this issues is the lack of a primary key at some tables. In PostgreSQL we can solve this with the following steps:

  • Add a column with type integer to your table
  • Create a sequence
  • Update the column table with sequence values
  • Set the necessary column properties (e.g. default, not null, etc.

Example for table “foo” and column “id”:

ALTER TABLE "public"."foo"   ADD COLUMN "id" INTEGER;
CREATE SEQUENCE "public"."foo_id_seq";
UPDATE foo SET id = nextval('"public"."foo_id_seq"');
ALTER TABLE "public"."foo"
  ALTER COLUMN "id" SET DEFAULT nextval('"public"."foo_id_seq"');
ALTER TABLE "public"."foo"
  ALTER COLUMN "id" SET NOT NULL;
ALTER TABLE "public"."foo" ADD UNIQUE ("id");
ALTER TABLE "public"."foo" DROP CONSTRAINT "foo_id_key" RESTRICT;
ALTER TABLE "public"."foo" ADD PRIMARY KEY ("id");
24 May 2010

Klettern - Pfingsten - Ith

1 Dec 2009

Comparison: Symfony vs Ruby on Rails

1 Sep 2009

Egypt: 2009

27 Jun 2009

PHP's pg_connect via pgpool-II vs pgBouncer vs native

In the last few weeks one of our customer had some performance issues with our web application. We discovered a lot of opportunities in our infrastructure that would improve the performance. I’m currently working on an article series about those experiences.

Whatever, if you’re running a high-traffic PHP application with a PostgreSQL database as backend you might be running into problems with slow repsonse times of your pages caused by pg_connect. This was one of the things happens to our application.

To solve this issue you can use a connection pooling software like pgpool-II or pgBouncer. I’m not going to explain what this makes or show how this works in theory. I just give you some statistics fresh from one of our servers to think about it. The webserver is running on Apache 2 + fcgid + PHP (CGI). This explains why the first benchmark results are low and increasing by and by.

Overview

1) PHP file without a database connection

/etc/init.d/apache2 restart ; \ 
  for c in {1..10}; \
  do ab -n 1000 -c 100 http://localhost/phpinfo.php 2>&1 | \
    grep "Requests per second"; \
  done
Restarting web server: apache2 ... waiting ..
Requests per second:     55.04 [#/sec] (mean)
Requests per second:    117.04 [#/sec] (mean)
Requests per second:    108.67 [#/sec] (mean)
Requests per second:     99.30 [#/sec] (mean)
Requests per second:    114.79 [#/sec] (mean)
Requests per second:    155.76 [#/sec] (mean)
Requests per second:    152.06 [#/sec] (mean)
Requests per second:    142.65 [#/sec] (mean)
Requests per second:    154.77 [#/sec] (mean)
Requests per second:    149.60 [#/sec] (mean)

2) PHP file with pg_connect to PostgreSQL

/etc/init.d/apache2 restart ; \
  for c in {1..10}; \
  do ab -n 1000 -c 100 http://localhost/phpinfo2.php 2>&1 | \
    grep "Requests per second"; \
  done
Restarting web server: apache2 ... waiting ..
Requests per second:     8.50 [#/sec] (mean)
Requests per second:    12.47 [#/sec] (mean)
Requests per second:    12.14 [#/sec] (mean)
Requests per second:    12.50 [#/sec] (mean)
Requests per second:    12.50 [#/sec] (mean)
Requests per second:    12.39 [#/sec] (mean)
Requests per second:    12.38 [#/sec] (mean)
Requests per second:    12.34 [#/sec] (mean)
Requests per second:    12.01 [#/sec] (mean)
Requests per second:    11.91 [#/sec] (mean)

3) PHP file with pg_connect via pgpool-II

/etc/init.d/apache2 restart ; \
  for c in {1..10}; \
  do ab -n 1000 -c 100 http://localhost/phpinfo3.php 2>&1 | \
    grep "Requests per second"; \
  done
Restarting web server: apache2 ... waiting ...
Requests per second:     41.43 [#/sec] (mean)
Requests per second:     94.64 [#/sec] (mean)
Requests per second:     80.83 [#/sec] (mean)
Requests per second:     85.47 [#/sec] (mean)
Requests per second:     73.03 [#/sec] (mean)
Requests per second:     87.65 [#/sec] (mean)
Requests per second:     84.18 [#/sec] (mean)
Requests per second:    103.66 [#/sec] (mean)
Requests per second:    105.99 [#/sec] (mean)
Requests per second:    104.72 [#/sec] (mean)

4) PHP file with pg_connect via pgBouncer

/etc/init.d/apache2 restart ; \
  for c in {1..10}; \
  do ab -n 1000 -c 100 http://localhost/phpinfo4.php 2>&1 | \
    grep "Requests per second"; \
  done
Restarting web server: apache2 ... waiting ...
Requests per second:     47.53 [#/sec] (mean)
Requests per second:    106.67 [#/sec] (mean)
Requests per second:     90.49 [#/sec] (mean)
Requests per second:     66.29 [#/sec] (mean)
Requests per second:    102.98 [#/sec] (mean)
Requests per second:    129.06 [#/sec] (mean)
Requests per second:    115.56 [#/sec] (mean)
Requests per second:    132.95 [#/sec] (mean)
Requests per second:    127.06 [#/sec] (mean)
Requests per second:    126.64 [#/sec] (mean)

What are your experiences and which one do you prefer? Why do you prefer pgpool-II over pgBouncer or pgBouncer over pgpool-II?

21 Jun 2009

Microsoft PowerToys ImageResizer for Vista

A real time-saver back in XP-times was the Image Resizer from Microsofts PowerToys. Unfortunately this tool doesn't work for Vista, but there are some alternatives out there.

I guess both working great, but I just tested the first one because this meets my requirements perfectly.

20 Apr 2009

Fettverbrennungspuls

Auf vielen Seiten zum Jogging ist etwas über Pulsbereiche zu lesen in denen man laufen müsste. Basierend auf diesen Informationen kauft sich evtl. der eine oder andere eine Pulsuhr und versucht per Formel oder anderen Techniken die maximale Herzfrequenz für die Berechnung der Bereiche herauszufinden. Für alle diejenigen hier einige Informationen: Einfache Erklärung:

Erklärung vom Sportmediziner:

Weitere sehr gute Publikationen findet Ihr unter: http://www.dr-moosburger.at/publikationen.php

Enrico Stahn's Posterous