Apr 21, 2008

Limits of Django or limits of db back-end?

Fiam has posted a slightly controversial piece titled The Limits of Django. It is a great read, I totally enjoyed it. However, he has come up with some very shocking stats of Django ORM approach vs. C caching daemon (93 seconds vs. 0.8 second to query a database of 500,000 votes of 1,000 users on 5,000 stories. A few have suggested that his database/data model maybe to blame, I think there's a great degree of truth to that. To try it out, I have created a sample database called django_test and populated it with a bunch of data like so:

-- users
create table users (id integer not null primary key);
-- stories
create table stories (id integer not null primary key);
-- votes
  story_id integer not null
     constraint story_id_fk references stories,
  user_id integer not null
     constraint user_id_fk references users,
  score integer default 0);
create index user_story_idx on votes (story_id, user_id);

Populating with some random data:

PSQL="/opt/local/bin/psql8 -q"
for ((i=1;i<=50000;i+=1))
    $PSQL -c "insert into stories (id) values ($i);" django_test
for ((i=9922;i<=10000;i+=1))
    $PSQL -c "insert into stories (id) values ($i);" django_test
for ((i=1;i<=500000;i+=1))
    let "score %= 100"
    let "userid %= 1000"
    let "storyid %= 10000"
    $PSQL -c "insert into votes (user_id,story_id,score) values ($userid,$storyid,$score)" django_test

(Yes, this is very-very crude, I know)

Here are my results on PostgreSQL 8.1.3, running on a G4 PowerBook with 2GB of RAM under Mac OS X 10.5.2:

django_test=# select count(*) from users; select count (*) from stories; select count(*) from votes;
(1 row)

(1 row)

(1 row)

I gave up waiting for population of 500K rows into votes table and run a few selects like the following one as it were (inserts were still running on background and I have not done VACUUM ANALYSE yet):

django_test=# \timing
Timing is on.
django_test=# select distinct(story_id), score from votes where votes.user_id=123 order by votes.score desc;
 story_id | score 
     3391 |    95
      812 |    94
     9215 |    93
     9599 |    92
     8510 |    85
      220 |    84
     8611 |    81
      740 |    78
     9193 |    74
     2406 |    70
     2201 |    61
     2740 |    59
     4500 |    52
     5993 |    52
     5692 |    51
     2912 |    49
     6566 |    49
     2950 |    48
     3149 |    47
       36 |    45
     1193 |    43
      629 |    38
     5720 |    36
     9429 |    35
      455 |    33
     6628 |    32
     2598 |    30
     2623 |    28
     2224 |    24
     6794 |    24
     2254 |    20
      934 |     8
     6267 |     8
     3999 |     7
     5879 |     3
(35 rows)

Time: 27.376 ms

That's less than 0.03 seconds. Not bad, eh?

Apr 12, 2008

The day I've opened up my WiFi

It is today, the day I thought to myself: "If Schneier thinks it can/should be done, why don't I do it?" And I changed my DD-WRT settings to fully open up my wireless to anyone.

I've made some changes to QoS and DHCP setup. DHCP addresses will only be assigned to .64-.255 range and that range has been throttled down in QoS to bulk access status. If I could figure out a way (and I might, if I am motivated to do that), I'd also disallow the DHCP'ed clients to have access to file sharing traffic (only for economical reasons, as right now I am paying for high-speed access, but with bandwidth restrictions).

Apr 10, 2008

Daring Fireball: Safari’s Tab Dragging Modes

John Gruber questions the two drag modes in Safari:

I don’t see why the intra-window (left-right) mode even exists. With the inter-window mode, you can do everything: reorder a tab within a window, move a tab to another existing window, or move a tab to its own new window. The intra-window mode only allows one thing: reordering tabs within their current window. I can’t think of a single reason why this mode exists.

Actually, intra-window drag is a nice feature that has been available in FireFox and Opera for quite some time. While it usefulness may, indeed, be somewhat questioned (it allows to reorder tabs only, that's pretty much it), I found not once not twice that putting a few tabs next to each other when running comparison or piling information for a report is very nice.

Inter-window dragging works very well together with "Merge all windows" option — in case you were reckless and allowed a bunch of windows to sprout thanks to target attribute of an a tag. The pattern I use in this case is to first merge them all together, then one of the tabs up-down to create a new "anchor" window, then move other tabs over to that "zone." But what I find very much useful after that is ability to move tabs around rearranging them for better usability.