TODDBLOG/ tags/ tech

This feed contains pages in the "tech" category.

how to keep an ovrloaded db running

Here is my new trick to keep a website running when mysql is overloaded:

Assuming you can narrow down your problem to a bad query on the site and you have no sensible way to disable what is causing it [or if you don't know the source of the bad queries] you can kill queries by regex using something like this

MYSQL="mysql -u root --password=passwd"
BAD_QUERY_REGEX=".*select * from users limit 100000.*"

while `true`; do 
  for x in echo 'show processlist'|$MYSQL|grep $BAD_QUERY_REGEX|awk '{ print $1 }'; do
    echo kill $x | $MYSQL
    done
  sleep 2
done

This will kill any query matching BAD_QUERY_REGEX every 2 seconds. This technique is valuable when some part of a site is killing the whole site because of bad queries. It's not immediately obvious that you can do this to save a site.

Posted Wed 28 Oct 2009 11:51:01 PM UTC Tags: tech
arduino heartbeat code

I recently got a mail from Chris McGuire asking about how I made the LED heartbeat effect.

For anyone interested, my code is here

Posted Mon 02 Mar 2009 09:49:49 PM UTC Tags: tech
2008 email sending statistics

Somehow I figured these numbers would be higher. I ran statistics back to 2004:

lolz% ./toys/mailstat ~/Mail/sent-mail
Mail sent by month: 2008
{1: 174,
 2: 293,
 3: 274,
 4: 322,
 5: 207,
 6: 238,
 7: 222,
 8: 274,
 9: 322,
 10: 473,
 11: 276,
 12: 193}
total: 3268
avg: 272

Avg for 2008: 272
Avg for 2007: 193
Avg for 2006: 187
Avg for 2005: 126
Avg for 2004: 159
Posted Sat 17 Jan 2009 11:37:25 PM UTC Tags: tech
startups and freedom

Paul Graham makes some intelligent calls on scale with regard to size and age and freedom of companies. The article is about allowing your team to ship code, but I found the part about startups being more free most interesting. I have noticed this pattern too. Since there are no established patterns and rules in young companies, they are free to do things now that will take much longer to pass in established companies. It is no wonder that art happens in the trenches.

For good programmers, one of the best things about working for a startup is that there are few checks on releases. In true startups, there are no external checks at all. If you have an idea for a new feature in the morning, you can write it and push it to the production servers before lunch. And when you can do that, you have more ideas.

From: The Other Half of "Artists Ship"

Posted Tue 02 Dec 2008 11:05:23 PM UTC Tags: tech
awesome wm

I have been very happy with the awesome window manager for several months since switching from Ion.

Here is a screenshot of my config:

awesome screenshot

Posted Tue 19 Aug 2008 09:02:39 AM UTC Tags: tech
what querycache sounds like

Last night Andrew, Viddler's frontend guy suggested to me that the MySQL querycache free space graph looked like a waveform and that MySQL was trying to tell us something.

So of course I had to convert the RRD data into a waveform.

The resulting sound is here.

I can't make anything out. It could be a different language.

Here is the code I used to make the sound:

#!/usr/bin/python

import pygame
import time

from Numeric import array
pygame.mixer.init(800, 8, False)

#sndarray = pygame.sndarray.array()

sndarray = []

f = open('vals.txt')
for line in f:
    val = float(line.strip())
    sndarray.append(int(val*10))
f.close()
#numsndarray = numpy.array(sndarray)
numsndarray = array(sndarray)
snd = pygame.sndarray.make_sound(numsndarray)
snd.play()
time.sleep(20)

Posted Fri 08 Aug 2008 04:11:54 PM UTC Tags: tech
iceweasel addons

Something in my iceweasel configuration is causing images to break, and I don't want to lose my many years of carefully crafted configuration, so I'm removing add-ons one by one to determine what is causing this.

I though this would be a good opportunity to list my favorite add-ons.

It turned out Torbutton was the culprit. Kind of surprising considering it was in the "tor off" state when it was causing the image bug.

Posted Tue 01 Jul 2008 07:23:59 PM UTC Tags: tech
generating video thumbnails

Here is today's contribution to the global pool. This data is a little hard to find.

As far as I know there are two FLOSS ways to make video thumbnails. Using mencoder:

mencoder /tmp/tmpMPbaKN/35dffc402a4b439978e6e05170d401c76b3c8cf0 -ovc lavc
-nosound -lavcopts vcodec=mjpeg:vqscale=2 vf scale=100 -of lavf -lavfopts
i_certify_that_my_video_stream_does_not_use_b_frames:format=image2pipe -ss
1.0 -frames 1 -o out.jpg

...and using ffmpeg:

ffmpeg -i /tmp/tmpMPbaKN/35dffc402a4b439978e6e05170d401c76b3c8cf0 -f mjpeg -t 0.01 -y out.jpg

Neither one works particularly well with incomplete video files.

Posted Fri 23 May 2008 12:15:19 AM UTC Tags: tech
reddit and hacker news

Two feeds I've tracked regularly for quite some time are Reddit and the slightly better version of the same site Hacker News. Lately I've been very disappointed with the posts that come to the forefront, perhaps in the same way I eventually became disappointed with Digg.

For those living in caves, all of these sites operate on a collaborative filtering model. Users submit interesting links and vote on what they think is most interesting. The top voted posts are put on the site's front page.

This model seems to work out great for the early lifetime of these sites, but every site I've followed eventually gets popular, and subsequently gamed. People vote up insignificant things, and posts get read because of their misleading buzz-filled headlines. Some such templates for this theme are:

  • Why controversial thing X is better than controversial thing Y.
  • 5 Easy steps to make your code sing
  • Why [thing you like] sucks
  • Tutorial on currently-buzzed topic that could easily be found simply googling

I feel like my limited attention is gamed by these "give me hits" posts even though some are potentially interesting. This is why I long ago unsubscribed from Digg and will probably have to do the same for HN and Reddit. I don't have a better solution yet. I think I could probably write a lot more about this. Back to work!

Posted Tue 13 May 2008 06:27:53 PM UTC Tags: tech
capture real audio with mencoder

Because I forget such things all the time, this is how you rip real audio to a wav:

mplayer -ao pcm:file=target.wav pnm://stream.lol.lol/lol.rm

The reason that I needed this today? To archive the famous Bell Labs recording of the IBM 704 singing Daisy Bell :)

ibm7094singsdaisy1961.mp3

Posted Fri 11 Apr 2008 09:53:24 PM UTC Tags: tech