PostgreSQL Planing Built In Replication

June 18th, 2008

Yes, that’s right, the PostgreSQL team is planning to add built in replication. This has come, in part, do to the demand of replication solutions, and the lack of easy-to-setup, easy-to-maintain replication for PostgreSQL. Many projects have moved to MySQL, simply because developers don’t want to deal with the headaches of Slony-I or PGCluster.

The features are planned to ship with PostgreSQL 8.4, however, do to technical issues, read-only queries to slaves may not be ready until 8.5.

This is going to be a huge leap for PostgreSQL.

The full announcement is on the PostgreSQL mailing list.

Comcast PowerBoost Is PR BS

June 16th, 2008

Comcast PowerBoost is useless. They ramble on about how Comcast Internet is so much faster than DSL, with PowerBoost giving you speeds up to 12mbit. Read the fine print, you’ll notice that PowerBoost only works for the first 10MB of a file (attached), and even that isn’t guaranteed. To put this into perspective, if I downloaded a 10MB file on my 7mbit DSL, and did the same on Comcast Internet with PowerBoost, Comcast would be a whopping 5 seconds faster, assuming both services work as advertised. Now if I were to download a 700MB iso with my 7mbit DSL, that would take ~14 minutes. If I did the same with 6mbit Comcast, compensating for PowerBoost, it would take ~16 minutes, DSL being about 2 minutes faster. Even if you had 8mbit Comcast Internet, the speed difference with DSL would still only be about 2 minutes.

Comcast relies on trickery to try and win over customers, by saying their internet service is way faster than DSL. In reality, PowerBoost does nothing to make downloads faster, there’s almost no difference between DSL and Cable download speeds (assuming that both services deliver exactly what they advertise), and Comcast’s methods of advertising are shady, to say the least.

A Simple Way To Deal With Web Form Spam

June 11th, 2008

I’ve been getting hit with a lot of web form spam lately, but I hate Captcha, so I thought of a simple solution for it. All I did was add an extra field to my form, and I changed the CSS so it’s set as “display: none;“. Then when the form is submitted, the validator checks to see if there’s anything in the extra field. If there is, the submitted fields are stored in a separate table, just for spam, along with information like IP address, User Agent, etc. It’s working pretty well, so far; hopefully the Spam Bots won’t adapt, but if they do, I’ll be ready.

I’m hoping to eventually collect enough information from these Spam Bots, to create a spam filtering system for web forms

Regular Expressions In SQL

June 11th, 2008

Regular expressions are pretty easy to use, however, different DBMS’s handle them differently.

In PostgreSQL, regular expression searches are done via the “~” character. For instance:

SELECT * FROM table1 WHERE column1 ~ '^(.?)unq([a-z]{4})([1-9]+)$';

In MySQL, this is done via REGEXP:

SELECT * FROM table1 WHERE column1 REGEXP '^S([c-z])n(.*)$';

In Oracle, this is done via the REGEXP_LIKE function:

SELECT * FROM table1 WHERE REGEXP_LIKE(column1, '[[:digit:]]{2}$');

Current Problems With Ubuntu Hardy

May 26th, 2008

Now that I’ve had a chance to play around with Hardy, I’d thought I’d update my list of problems with it.

  • TERRIBLE default fonts. Open /etc/fonts/conf.d/30-metric-aliases.conf and replace all occurrences of “Nimbus Sans L” and “Liberation Sans” with “DejaVu Sans” to fix them.
  • Very slow and sluggish performance. Any SQL statements that perform a sequential scan, bring out the worst in it.
  • Firefox Flash plugin crashes, and sometimes crashes Firefox. I’m not sure if this is because I’m on x86_64.
  • Firefox extremely slow at times.
  • Power Management extremely buggy.

Forcing VSYNC In ioquake3 (Mac OS X)

May 18th, 2008

I’ve been really frustrated with ioquake3 on OS X, mainly because there’s no vsync, and there’s no option to enable vsync that works (I tried setting r_swapInterval to 1, but to no avail), so I had to take things into my own hands. The proper SDL way of doing this, seems to be broken, or maybe the way ioquake3 handles it is broken. In any case, here a patch that should apply to the latest SVN.

ioquake3 vsync patch

Ubuntu Hardy Disappointing

May 16th, 2008

I’ve been very disappointed with Ubuntu Hardy. By far, the most noticeable thing after installing it is how much slower it is. If you have a beefier system, you probably don’t notice it, but it’s very noticeably slower on my current system. After using it for a while, it really slowed down, and I noticed that the scrollkeeper process was sucking 80% of my CPU. I just killed that process and removed it from /etc/cron.*, so it wouldn’t be spawned again.

I decided to pull up PostgreSQL to run a quick benchmark. I created a very simple table and added 10,000 rows to it, to see how fast SELECT COUNT(*) performed. The results were shocking:


CREATE TABLE test (id INTEGER PRIMARY KEY);
INSERT INTO test VALUES (generate_series(1,10000));

EXPLAIN ANALYZE SELECT COUNT(*) FROM test;
                                        QUERY PLAN
--------------------------------------------------------------------------------------------------
 Aggregate  (cost=170.00..170.01...) (actual time=63.064..63.067...)
   Seq Scan on test  (...145.00...) (actual time=0.034..27.452...)
 Total runtime: 83.567 ms
(3 rows)

WTF!!??!? 83ms!?! On Feisty, the exact same thing takes 8ms, 10x faster than on Hardy! Something is seriously screwed up!

The first thing about Firefox 3b5 I noticed, is it sucks up way more CPU. Just scrolling down the page on some sites causes it to use 90% of my CPU, even with Smooth Scroll turned off. Just sitting idle it uses 1-3% CPU, which isn’t too bad, but FF 2 uses 0% sitting idle. The new UI is nice, though, and it seems “snappier” at times. Also, installing Flash works off the bat, which is really nice (before, I had to download the 32bit version of FF, and use it instead of the one that comes with Ubuntu).

One of the most irritating things about Hardy, is that Power Management is almost completely broken on my system. I set my display to go to sleep after 15 minutes… Three hours later, and it still isn’t sleeping. Now I have to turn my monitor off manually? Barbaric!!!

I don’t have any other criticisms for now. Everything else worked right away, and installing the proprietary NVIDIA driver was a breeze. Bluetooth support is enabled by default, and the usual GNOME improvements are nice… I’m sure I’ll find more to complain about later.

Update: after installing updates, Power Management is now working, and the entire system seems faster.

Update: Power Management is broken again… It works on and off.

Python: Tips For Writing Daemons

May 3rd, 2008

Here’s some useful information for writing daemons in Python.

One common problem that people run into is os.fork() producing zombie processes when children quit. This can easily be overcome by setting the SIGCHLD signal to SIG_IGN. ie:

import signal

signal.signal(signal.SIGCHLD, signal.SIG_IGN)

On some flavors of Unix, you are forced to do a double-fork on startup, in order to go into daemon mode. This is because single forking isn’t guaranteed to detach from the controlling terminal. The solution is this:

import os, sys, time

# Main loop
def main():
    # Drop privs.
    os.setgid(1000) # Replace with desired GID
    os.setuid(1000) # Replace with desired UID

    time.sleep(10)
    sys.exit(0)

if (not os.fork()):
    os.setsid() # Become session leader
    pid = os.fork()

    if (pid):
        # Parent, write PID file
        fp = open('/var/run/my-daemon.pid', 'w')
        fp.write(str(pid))
        fp.flush()

        # Forcibly sync disk
        os.fsync(fp.fileno())
        fp.close()

        os._exit(0)
    else:
        # Child, call main
        main()
else:
    # Parent
    os._exit(0)