Tuesday, February 2, 2010

Throw the First (n-1) Versions Away

There is a great article on scaling web apps on Ars Technica, What Second Life can teach all companies about scaling web apps, which is about.. well, exactly that the title says.

From this passaage:

... but herein lies a trap for smaller ones: the belief that you can "do it right the first time." (Or, in the young-but-growing scenario, "do it right the second time.") This unlikely to be true in the real world, so successful scaling depends on adapting your technology as the system grows.

Regarding this, I said "You always throw the first one away"

My collegue Ross improved upon this with:

I'd say you throw the first (n-1) away since you're never really "done"

There is a great mathematical induction or recursion joke in here. This is left as an exercise to the reader.

Monday, January 25, 2010

On Sending Automatic and Bulk Email

Wow, email sure became complicated, especially from the cloud, especially from EC2. Oh you'll need to know about BIND, reverse DNS or alternatives, SPF records, blacklists, and all sorts of other crap.

But just as you have outsourced your datacenter by using the cloud, outsource your email sending as well. Checkout AuthSMTP. With pricing start at $24/YEAR, you might as well start using it before you get yourself into trouble.

And check out Paul Dowman's great article on how to configure this: A rock-solid setup for sending SMTP mail from your EC2 web server

More Notes

AuthSTMP let's set up a list of authorized "From" accounts that can send email. If it's not on the list, it will be rejected. Both the unix user and the email from: must in AuthSTMP's list. If you webserver running as "www-data" is sending email as "bobsmith@yourcompany" then you have to authorize both "www-data@..." and "bobsmith@...".

You are going to want to set up a bogus "root@..." account that will be forwarded to you, and add "root@..." to the approved senders. If a cronjob or some system process sends email, you want to make sure you get it. As as mentioned, you'll also want to allow "www-data" (or whatever user your webserver runs as) or "nagios" to be allowed to send email too.

In most cases, uou will also want to set up that bogus "noreply" email group too and add that to the approved list.

Handy Postfix Commands

While configuring all this, you'll like screw up and have a bunch of mail stuck in the postfix queue. To delete them all do:

sudo postsuper -d ALL

Sunday, January 24, 2010

Installing Virtual Box Guest Additions for Linux

The guest additions add all sorts of goodies, most importantly, syncing the time with your host computer.

Since I always forget here are the instructions:

  • Click on the console (the black screen) of a running VBox.
  • In the menu bar, select Menu -> Install Guest Additions
  • Then....
# on the virtual box menubar
# select Devices > Install Guest Additions....
#  this "inserts a fake CD"
#
sudo mkdir /mnt/cdrom
sudo mount /dev/cdrom /mnt/cdrom/
cd /mnt/cdrom
# pick the amd64 for 64bit
# pick x86 for 32bit
sudo ./VBoxLinuxAdditions-amd64.run
date
# should be synced with your computer

Tuesday, January 19, 2010

Google Analytics async tags

Google Analytics has some snazzy new async tags that should minimize page hangs and blocking. For some reason, they hide the code to this on a separate page. Since I have to spent 15 minutes poking around on their site to find it, may I present:

http://code.google.com/intl/en-US/apis/analytics/docs/tracking/asyncTracking.html

enjoy

Wednesday, December 23, 2009

Version 2.0 of print_r and var_dump for php

A colleague just showed me krumo, which is "Version 2.0 of print_r() and var_dump();". This is for php kids, and krumo ain't kidding -- it's a nifty redo of those debugging functions with collapsable trees, colors, line numbers, the work. Check it out.

Tuesday, December 22, 2009

EcmaScript 5 Final Spec is out

The latest spec for javascript aka EcmaScript 3.1 aka EcmaScript 5 aka Ecma-262 is out. Annex E contains a change log. Besides a long list of minor changes and spec-bug fixes, you could say the theme is "doing more with what already exists".

Strict Mode

By being in strict mode, a lot of the pitfalls in javascript can be avoided (similarly to how perl 5 works). See "Annex D" for details on the rules, but it's stuff like:

It is a SyntaxError if strict mode code contains an ObjectLiteral with more than one definition of any data property (11.1.5).

Reflection

Most of this is take what you can in a C/C++/Java version of the engine, and exposing it into the language.

Object.getPrototypeOf, Object.getOwnPropertyDescriptor, Object.getOwnPropertyNames, Object.create, Object.defineProperty, Object.defineProperties, Object.seal, Object.freeze, Object.preventExtensions, Object.isSealed, Object.isFrozen, Object.isExtensible, Object.keys,

This big one is defineProperty, it can set up getters/setters, if it's enumerable, and all sorts of other stuff.

Functional Programming

Array.prototype.every, Array.prototype.some, Array.prototype.forEach, Array.prototype.map, Array.prototype.filter, Array.prototype.reduce, Array.prototype.reduceRight,

A lot of these are in the wild already. Haven't tested the performance to see if they help, or if they are just handy.

Minor Enhancements

Array.prototype.indexOf, Array.prototype.lastIndexOf, String.prototype.trim, Date.now, Date.prototype.toISOString, Date.prototype.toJSON

Hurrah, trimming whitespace of a string is now part of javascript. How it took 10 years is a mystery.

JSON

The only new global object is to handle JSON data structures. These are in the latest versions of most browsers.

JSON.parse, JSON.stringify

What's not in

Sadly, a "Byte Array/String" is not present. Working with raw binary data is really painful right now, and having a real mechanism would open the door for all sorts of new javascript applications. boo.

In case you were wondering.

EcmaScript 4 (sometimes known as Javascript 2) died on the vine. It was very ambitious.

Sunday, December 6, 2009

Virtual Box 3.1, Ubuntu and Mac: Networking Tricks

Yup, it's that time again, more Virtual Box and Mac tricks. First Virtual Box 3.1 came out recently. It contains something called "Host Only Network" which is very handy

If you are running a guest desktop OS and do not need to network connect to a server running on the guest OS, then the NAT networking option is all you need. Ignore the rest of the article. NAT "shares" an interface with the host, it's great to allow the guest make outbound connections. But you can't SSH in.

To do that, you need to use "Bridged Adapter." It behaves like a "different computer" on the network. The guest gets it's own IP address from the whatever DHCP server is out there. But: No wifi, no IP. Which means you can't log into the server. Ooops. And if there is wifi, the IP address might (will) be different every time. It also means your guest can be attacked by the outside world.

With Virtual Box 3.1, comes with a new type of networking called "Host Only". It is a bit weird. The guest can't connect to the internet, and "only your computer" (the host) can connect to it (the guest). The IP address it gets is "stable" (the same every time it boots)

So if you set up two networking adapters (virtual box supports 4), one being the "NAT", and the other being "Host Only", you get the best of both worlds. Outbound connectivity when it exists, and inbound activity only from your host (which likely means YOU at the keyboard). Ta-da!

Adding a new network and existing Ubuntu Server

Great you updated your VBox settings and have a snazzy new interface. How can you get Ubuntu recognize it? Hack the /etc/network/interfaces file. You probably just want to add to the end:

auto eth1
iface eth1 inet dhcp

New installs should recognize the adapters automatically.