Sep 27 2008

Gemstone/S and FastCGI with lighttpd

I was reading the post from James Foster about configuring Apache/FastCGI for serving Seaside. I prefer Lighttpd because, as its name implies, it needs less resources to run. And with virtual hosting, as I have my servers, memory it is a big factor.

I followed the steps to install Gemstone/S in my machine. Instead of a hosted server, I used my laptop with my user as server.
After testing that Seaside was running OK in my machine, using:

miguel@laptop:~$ source /opt/gemstone/product/seaside/defSeaside
miguel@laptop:~$ startGemstone
miguel@laptop:~$ startSeaside_Hyper 8080

and navigating to:

http://localhost:8080/seaside

I stoped the Hyper Webserver with Ctrl+C.

Now to install lighttpd in my Debian GNU/Linux 4.0 etch machine. As root:

laptop:~# aptitude install lighttpd lighttpd-doc

and backup the default config file:

laptop:~# cp /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.bak

then use this configuration for lighttpd.conf:

# Modules activated
server.modules = ( “mod_access”, “mod_alias”, “mod_accesslog”, “mod_fastcgi” )
# Document root, maybe there you have other sites also
server.document-root = “/var/www/”
# logs
server.errorlog = “/var/log/lighttpd/error.log”
accesslog.filename = “/var/log/lighttpd/access.log”
# Welcome file
index-file.names = ( “index.html” )
# Do not server files beginning with
url.access-deny = ( “~”, “.inc” )
# Server config
server.port = 80
server.pid-file = “/var/run/lighttpd.pid”
dir-listing.encoding = “utf-8″
server.dir-listing = “disable”
server.username = “www-data”
server.groupname = “www-data”
# FastCGI
# Debug enabled, disable on production sites
fastcgi.debug = 1
# Do FastCGI for anything with prefix /seaside
# load-balancing with 3 hosts
# check-local disable searching the requested file in the lighttpd document root and
# forward the request to the fastcgi hosts
fastcgi.server = ( “/seaside” => (
    ( “host” => “127.0.0.1″, “port” => 9001, “check-local” => “disable”),
    ( “host” => “127.0.0.1″, “port” => 9002, “check-local” => “disable”),
    ( “host” => “127.0.0.1″, “port” => 9003, “check-local” => “disable”)
  )
)

Instead of starting Seaside over Gemstone/S with startSeaside_Hyper <port>, I used the provided script to start 3 gems for fastcgi as per James’ instructions:

miguel@laptop:~$ runSeasideGems start

This started 3 fastcgi gems, listening in ports 9001, 9002 and 9003.

Then I restarted lighttpd:

laptop:~# /etc/init.d/lighttpd restart
Stopping web server: lighttpd.
Starting web server: lighttpd.

And tested that the default index page for lighttpd (located in /var/www/index.html) was served statically (you can add anything here)  from the server document root (/var/www/), pointing the browser to:

http://localhost/

Finally, I tested that the /seaside part was correctly delegated to Gemstone/S using FastCGI, pointing the browser to:

http://localhost/seaside

This time I get the dispatcher from Seaside, from where you can navigate the links from Seaside without problems.

This way you can use, for example, blueprint for the CSS style of your app, or maybe TinyMCE, for having a full fledged text editor. All you have to do is to put them in a directory inside the document root of lighttpd (/var/www in this example) and in the Seaside application, you reference them with the absolut path to your website, for example:

http://mysite.com/styles/blueprint.css

or

http://mysite.com/tinymce/jscripts/tiny_mce/tiny_mce.js

So, the webserver to serve the static content of your site (faster) and Seaside to serve your webapp.

Enjoy.


Sep 24 2008

Okcoba Fest

Yo, Miguel Cobá, en mi carácter de representante absoluto y vitalicio de mí mismo, con fecha 24 de setiembre del año del señor 2008, siendo las 16:39
horas en el horario local, 21:39 hrs en el horario universal, en la centenaria, hermosa y ahora muy atribulada Ciudad de México

DECLARO

oficialmente iniciados los festejos conmemorativos del natalicio de nuestro humilde, sonriente, amigable, entrañable, guapo, inteligente, trabajador y muy modesto representado.
En este tenor

ORDENO

que, a partir de las 23:59 minutos en tiempo local y durante un periodo no menor a 3 días y no mayor a lo que sea saludable para el buen mantenimiento de la salud del hígado humano normal de una persona adulta de 29 años, deberá festejarse, en cualquier lugar donde se encuentre uno, a la hora en que así sea conveniente, solo o en compañía, de manera preferente con el interesado, con toda suerte de sustancias y actividades tradicionalmente usadas al efecto en ocasiones de similar trascendencia, y apegados a la tradición, tanto mexicana como ingenieríl, incluyendo sin limitar:

  • derivados etílicos de la uva, la cebada, el agave azul, el arroz y las frutas dulces, así como bebidas dulces, derivadas de frutas o carbonatadas que produzcan una combinación agradable al gusto humano
  • los derivados lácteos en sus diversas variedades generalmente conocidas como quesos, preferentemente en sus presentaciones edam, de cabra, manchego y con ceniza
  • abrazos, besos (preferentemente de personas del sexo femenino, aunque del pequeño caballero de la mesa redonda se aceptan sin chistar y con emoción), actividades intimas y lúdicas para adultos (con exclusividad total para la filósofa y aspirante a curadora de arte, mejor conocida como Frau Kunst)
  • actividades de mesa incluyendo sin excepción, cartas, dominó, jenga, así como concursos coloquialmente conocidos como fondos y muppets
  • narración de anécdotas típicas, emotivas, avergonzantes, divertidas, por n-ésima ocasión al calor de la velada, así como la tradicional reinterpretación del sentido de la vida, del hombre y sus motivaciones, el espíritu del vino y el secreto escondido en el cuerpo de las mujeres y en la risa de los niños.
  • música al gusto del momento, con especial atención a la preferida por nuestro conmemorado

Sin otro afán que el de agradar y hacer patente nuestro amor y la felicidad que nos da el pretexto para honrar a Baco en su más mundana faceta y a participar de Eros en su más práctica y apapachante expresión, decreto:

QUE INICIE EL “OKCOBA FEST” 2008

PD. La sede principal de los festejos será, como siempre, la residencia oficial de nuestro conmemorado donde se les espera el día sábado 27 a las 19 horas tiempo local y hasta que el cuerpo (o el hígado) aguanten.

PPD. No se aceptan regalos, solamente asistencias, risas, “saluds”, abrazos y llamadas telefónicas (así como sus equivalentes modernos Web 2.0). Abstemios, se les insta a hacer un esfuerzo y dejar atrás sus arcaicas y no sociales prácticas :).

PPPD. Si alguien quiere traer regalos, estos no serán despreciados sino que se aceptarán con el más humilde y sincero agradecimiento.

PPPPD. Pero no son obligatorios los regalos.

Al margen un sello con el escudo nacional que dice: “Patronato Oficial para el Festejo del 29-nario del Natalicio de Miguel Cobá”. Una firma ilegible. Secretario General del Patronato para el festejo de Miguel Cobá.

Extiendo la presente en 2 fojas útiles, en México, Distrito Federal, a los 24 días del mes de setiembre del año de nuestro señor dos mil ocho, a fin de que sea publicada en el diario oficial de la federación, y en los diarios de mayor circulación nacional a fin de que sea de conocimiento general de la ciudadanía.

Miguel Cobá, Presidente del Consejo de Administración del Fideicomiso 2008/09/25MCM/ aprobado por la H. Cámara de Diputados, en su sesión extraordinaria y urgente del 23 de setiembre del año de nuestro señor dos mil ocho, para la creación del Patronato para el Festejo del N-ario del Natalicio de Miguel Cobá. Presente.


Sep 22 2008

F***ing MySQL

One more time, I am having trouble with the MySQL database I administer.
Look, this MySQL database was inherited. It contains ~30 databases, most of them MyISAM type. One of them, the biggest, with more than 30GB of data (150 millions registers). The configuration for MySQL especified a first innodb tablespace file of 20GB and a second file of 10MB, with autoextend. From my.cnf:

innodb_data_home_dir = /data/mysql/data
innodb_data_file_path = ibdata1:20000M;ibdata2:10M:autoextend

I was in the migration from MyISAM to InnoDB, in order to have transaction support. But, as I noted after starting the migration of tables, the innodb files used for storing the mysql tables NEVER shrinks. Never, even if you delete tables, drop tables or drop databases. Always grows but never returns unused space to the operating system. Unbelievable.
According to the bug tracking system for mysql (bugs 1341, 1287) this is a design decision to improve performance: if the space were disposed each time a delete is peformed, it would need to be allocated again when more data were written to the database. So it is only marked as deleted but not returned to the operating system. That is reasonable. In fact it is a good point. But there are times when you just need to free the innodb unused space and IT IS NOT possible, in an automatic or, at least, in a manual way.
Why would you need this. Supose, for example, that I have a 100 GB disk. It is used only for mysql. There is only a database of 40GB in it. So I have ~60GB of space free. One day I need to restore an old backup for this database. I create a new database and restore the old backup inside this database. If I have MySQL configured as all Innodb, the new database would be created in the innodb tablespace, so MySQL will grow the tablespace to say 80GB so the restored backup can be loaded. At this moment, I have 80GB used by the tablespace and only 20GB of free space in the disk. After extracting the data from the backup, I delete the restored database. One would think that the 40GB would be returned to the OS, but NO! The table space size is 80GB although only 40GB are really used, in fact, SHOW TABLE STATUS would show that it is only 50% used. If my original database doesn’t grows to fill the 80GB used by the innodb tablespace or grows very slowly I have actually lost 40GB from my disk and I can not do anything easy to recover that space. In other words, I have lost that space.
Of course there are workarounds for this problem, but they involve dumping and restoring the databases and more important, YOU MUST shutdown the database. That is not always posible. Maybe in a weekend or in the night, but that can be too late if you are running out of disk space.
It is needed a command to force MySQL to free unused space, under the responsability of the DB administrator. At this time, there isn’t any.
So the only way to add more free space to my database was by means of the operating system. My filesystem was like this:

[root@usp02 root]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/cciss/c0d0p3      64G   36G   26G  59% /
/dev/cciss/c0d0p2      99M   11M   83M  12% /boot
/dev/cciss/c0d1p1      67G   62G  2.4G  97% /data
none                  2.9G     0  2.9G   0% /dev/shm

and there were still 3 tables in the migration process. I was feeling real panic. Besides, it is Monday morning. The only feasible moment for shutdown is the next weekend or, in case of extreme urgency, until tonight.
Finally, after several hours searching for a solution for the problem in MySQL, I decided to search ways to free space in the filesystem of the operating system. Happily I found a way to reduce the space reserved for root in a ext2 filesystem from the default 5% of the disk size to 1%. The instructions are here. And I don’t even have to remount the filesystem. The change was applied inmediately.
I just typed:

[root@usp02 root]# tune2fs -m 1 /dev/cciss/c0d1p1
tune2fs 1.32 (09-Nov-2002)
Setting reserved blocks percentage to 1 (177816 blocks)
[root@usp02 root]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/cciss/c0d0p3      64G   36G   26G  59% /
/dev/cciss/c0d0p2      99M   11M   83M  12% /boot
/dev/cciss/c0d1p1      67G   62G  5.1G  93% /data
none                  2.9G     0  2.9G   0% /dev/shm

So I could get 2.7GB that hopefully will last until I can shutdown MySQL, remove the autoextend from the second innodb file and add a third tablespace in another filesystem with enought free space.

One more thing I don’t like about MySQL.

Uff.


Sep 19 2008

Mon premier post en français

Je m’ appelle Miguel. Ma femme s’ appelle Aline. J’ ai un garçon. Il s’ appelle Tristán et il a 1 ans. J’ habite à Mexico, en Mexique. Je suis mexicain. J’ aime Aline et Tristán. Je suis ingenieur et je parle espagnol, anglais, allemand et un peu français.
Comment allez-vous?

Au revoir!