Blog

MySQL is (Reportedly) Still Terrible
SQL mysql
Published: 2013-02-10
MySQL is (Reportedly) Still Terrible

Many years ago, when I actually paid attention to such things, I rejected MySQL in favor of PostgreSQL because of the former’s terrible defaults (e.g. no ACID guarantees on the default storage engine at the time, MyISAM) and missing features (in 3.23, no subqueries, stored procedures, views, etc.).  The only time I regretted it was when dealing with other software that required MySQL and would not work with PostgreSQL.

Looks like not much has changed.

Read more...
Python Multiprocessing Module and Closures
Python closures python
Published: 2013-01-16
Python Multiprocessing Module and Closures

At work, I wrote a Python script which uses the multiprocessing module to process many servers in parallel. The code looks something like:

1
2
3
4
5
6
7
def processServer(server):
    # Do work...

numParallelTasks = ...
servers = [...]
pool = multiprocessing.Pool(processes=numParallelTasks)
results = pool.map(processServer, servers)

I wanted to pass some extra state to processServer without using a global variable. My first attempt was to use a closure, so I wrote the following:

Read more...
Longest Interactive Command Yet
Unix git puppet unix
Published: 2012-08-02
Longest Interactive Command Yet

This is perhaps the longest command I’ve ever entered on the interactive command line:

1
2
3
4
5
6
[113 sengelha@centosdev-vm]% cd modules/puppet && git init && git add --all
&& git commit -m "Initial Commit" && git remote add origin https://xxxxxxx@x
xxxxxx/scm/PM/puppet.git && git push origin master && cd ../.. && git rm -r
modules/puppet && rm -rf modules/puppet && git submodule add https://xxxxxxx
/scm/PM/puppet.git modules/puppet && git commit -m "Move puppet to submodule
" && git push

It moves a Puppet module to its own, separate git project and sets up a Git submodule reference to the moved module.

Read more...
Varnish Expiration Thread Lock Contention
Varnish varnish
Published: 2012-07-27
Varnish Expiration Thread Lock Contention

I recently helped introduce a Varnish cluster at work to offload a significant number of requests from a heavily-trafficked internal web service.  This Varnish cluster serves approximately 10,000 requests/second (with peaks in the 20-30,000 requests/second range) 24x7x365.

While working on this project I ran into a few interesting problems with Varnish.  The most interesting one I saw was that Varnish would consume more and more RAM until eventually it would consume all the memory on the box and crash.  Using varnishstat, we diagnosed that this was due to unbounded growth of transient storage within the Varnish process.

Read more...
Reader/Writer Lock Pattern
Concurrency locking
Published: 2010-03-04
Reader/Writer Lock Pattern

A reader-writer lock is a lock which will allow multiple concurrent readers but only one writer. A reader-writer lock can be significantly more efficient than a standard mutex if reads on your shared memory far outnumber writes.

Reader-writer locks naturally fit together with caches, as caches are only effective if reads far outnumber writes.

Here is a general pattern for using a reader-writer lock with a cache:

  1. Acquire a reader lock.
  2. Check the cache for the value. If it exists, save the value and go to step 8.
  3. Upgrade the reader lock to a writer lock.
  4. Check the cache for the value. If it exists, save the value and go to step 7.
  5. Calculate the value (expensive, otherwise we wouldn’t cache it)
  6. Insert the value into the cache.
  7. Release the writer lock.
  8. Release the reader lock.
  9. Return the value.

The reason why we have to check the cache for the value again in step (4) is because of the following possibility (assume step 4 doesn’t exist):

Read more...
Handling Multiple QueryString Parameters With the Same Key in ASP.NET
ASP.NET asp.net csharp
Published: 2009-09-23
Handling Multiple QueryString Parameters With the Same Key in ASP.NET

When you are processing an HTTP request in ASP.NET you can retrieve the user-provided query string parameters using the HttpRequest.QueryString property. This property is an instance of the NameValueCollection class.

If the user has provided multiple parameters with the same key in the query string, HttpRequest.QueryString[key] will return all the values concatenated together with commas. If you would rather process the values individually, use HttpRequest.QueryString.GetValues(key), which will return an array of all the provided values.

Read more...
Balloon Tooltips
Win32 c win32
Published: 2008-06-12
Balloon Tooltips

In the Windows XP login screen, the password text box will warn you with a balloon tooltip if you accidentally turn Caps Lock on. The balloon tooltip appears to be a Windows tooltip common control with the TTS_BALLOON style.

To replicate this functionality, I decided to write a function called ShowMsgBalloon() which, given a control and the various balloon tooltip parameters, creates and shows the balloon tooltip below the control.

Read more...