Ideal line length

I had a discussion the other day about ideal line length for reading content. I’ve got an ideal number in my head, but I wondered if there was any consensus out there on how long lines should be. With so many sites going responsive these days, there’s a tendency to let the max-width on the content container be huge — often upwards of 1200px. That’s just way too wide for me. On sites that do that, I’ll normally resize my browser window to pull things together a bit better. Seems to matter less for others, and some research is indicating that it matters less online overall.

It certainly matters to me! Google “ideal line length” to find more than you’ve ever wanted to read on the subject.

Out of curiosity, I went to some of the sites I visit with some regularity. Here’s what I found:

Seems that at least the news sites are in alignment with where I like things to be.

Sketch resources

It feels like I’m always tweeting about Sketch—mostly because I love it so much. I haven’t opened Illustrator or Photoshop in many months, a fact that makes me happy on a daily basis. I wanted to have a good running list of resources that I come across, so I’m hoping that this will grow into that. It will likely be small to start, but should grow over time. I’ll post updates as it fills out.

Surviving a HackerNews traffic spike on a $5/mo host

The two alternate titles of this post are Everything I know about running your own VPS or Host a pile of your high-traffic WordPress sites for just $5/mo, but let’s go with what we have.

A few months back, after scrolling over enough promoted tweets from Digital Ocean in my timeline, I got curious enough to spend the $5 for the basic plan and sign up. At that point I was simply interested in seeing what they had to offer — see what their interface was like, see what WordPress felt like on an SSD, etc. I certainly wasn’t intending on spending hours and hours tuning and tweaking and configuring, but yet that’s exactly what I did.

Surviving a Hacker News spike

When Throwing in the Towel on Programming hit Hacker News, I was at home cooking supper and playing with Jack. I happened to check in on the traffic about half-way through the spike and could see that things were humming along perfectly well. In the end, I had almost 10k visits in the span of less than 2 hours. Not huge traffic by any stretch, but more than most small blogs like this get in the run of a few hours. In the time since, I’ve done all kinds of additional tweaking and tuning, and I think at this point I could serve much much more traffic without the server breaking a sweat.

But that’s the end of the story. Let’s start at the beginning!

Setting up your new VPS

I chose Digital Ocean (DO) because of that enticing $5 gateway. You could absolutely go with Linode as well — I have no preference and have used and liked both. Here’s what I did at DO:

  1. Install Ubuntu (12.04 in my case)
  2. Install the lamp stack I need to run WordPress
  3. Setup my dotfiles
  4. Install wpcli
  5. Setup a new virtual host for a WordPress site
  6. Install WordPress! (though I did this mostly through wpcli
  7. Profit!

And basically that was it, all except for step #7. Turns out that even on a fresh server install on a blazing fast SSD, things were moving extremely slowly. I was trying to import some .xml export files from some of my sites and MySQL kept falling over and needing to be restarted, and things generally were not going well. It made no sense to me — I had a brand new setup, on a very fast hard drive but my one single site was just crawling along. That’s when I hit #digitalocean on Freenode to get some help.

The good folks in #digitalocean were extremely friendly and helpful. Not all IRC channels are friendly to beginners—that’s an understatement—but DO’s certainly was. They helped me with my initial setup and are still helping me today with the more complicated stuff I run into. Before hitting a wall and giving up, you should definitely head over there and start asking for help.

Tweak and Tune

After a considerable amount of time spent reading and asking questions on IRC, I had a good sense of what I needed to do to make my server perform. Here’s roughly what I did:

  1. Tune Apache
  2. No, I mean, really tune Apache
  3. Spend an entire day reading about KeepAlive
  4. Keep reading about KeepAlive
  5. Tune MySQL
  6. Loose sleep over setting the ideal key_buffer_size
  7. Install MySQLTuner (you should let MySQL run for 24hrs or more before acting on the recommendations this gives you

After I went through all of this, performance really picked up. MySQL wasn’t falling over while doing relatively simple tasks, and things were generally much much faster. But how fast? How could I tell that everything was performing better?

Tools of the Trade

The hardest part of the learning curve to running your own VPS is getting a handle on the tools you have available to you. Understanding how much memory you have and how much you’re using at any one time is the big one, and that took me a while to catch on to. Basically there’s two main commands/tools that you’ll want to keep an eye on. Every morning when I get into work, I’ll open up two terminal windows and run two commands to see how things are doing:

1. top 

Just log in to your VPS and run the command ‘top’. That should fill your screen with a whole pile of info. Everything from how long your server has been “up”, how much memory you’re using, what processes are running and what % of CPU power they’re using. I like to sort the processes by %CPU or %MEM — do that by typing Shift+O then either n or k.

Here’s what that looks like :

top

2. free -m

Top gives you a sense of how much memory you’re using at any one time, but keeping an eye on free is a better way. Just type that into your terminal and see the how much memory you’re using. The output looks like this:

free-m

The line you’ll want to look at here is the second one:
-/+ buffers/cache:        339        655

This is telling me that I’m currently using 339MB of memory and have 655MB free. I’ve recently upgraded to the $10 plan, so that’s why I have 1024MB (1GB) of memory and not 512MB. But that’s what you’ll want to look at. Of course you’re not going to want to have to keep typing that free -m command every time you want to see how much memory you’re using, so you should watch it instead:

watch -n 10 free -m
That will run this command for you every 10 seconds.

Ok, so let’s recap where we are. We’ve got a lamp stack installed on Ubuntu, created a virtual host, got WordPress installed, and we’ve got Apache and MySQL all tuned up and ready for another Hacker News spike. The only thing is, how do we know we’re ready? How do we test that everything we’ve done has helped? I’m still struggling with this part a little myself, but I’ve come up with a few strategies.

Load Testing

I use two tools for testing:

Apache Bench

This is a system tool that will let you send traffic from your desktop to your server. To use it, logout of your VPS and try sending some requests along. I use something like this:

ab -n 1000 -c 50 http://waterstreetgm.org/

This simulates requests (1000) and concurrent users (50) to your site. The output looks like this:

apache-bench

That’s a lot of information there. A few key lines to look at are your Request per second and the percentages at the bottom. The 50% 1410 is telling me that 50% of the 1000 requests were served to my visitors in less than 1.4s, which isn’t too bad. I’d like to get the mean time per request down a little lower (1874ms or 1.8s) but it’s still pretty good.

Blitz.io

Blitz is an extremely neat tool. This does a more real-world benchmark than Apache Bench does. It rushes your site with traffic and gives you a report of how you did. My report currently looks like this:

blitz

Blitz is suggesting that I survived 463 hits/s, and that my site could handle 40M hits/day (!), which seems a bit insane to me. That said, this one rush sent 27,804 hits to my site in 60s and I handled that no sweat, so maybe I could handle 40M visits per day.

How do I know it was no sweat? While running this Blitz, I have two terminal windows open running free -m and top so I can see what’s happening. Here’s what that looked like during this rush:

blitz-top-free

It’s a little hard to see the output in the terminal windows there, but the top CPU-consuming application during this blitz was Varnish, and on the bottom you can see that during all this I was still only using around 364MB of memory—I noticed virtually no spike in memory use during this test. That’s pretty neat. I’m also this close to scrapping the Apache setup altogether and taking Nginx for a spin—but that’s a conversation for another day.

Oh yeah, I installed Varnish here too, forgot to mention that! Honestly, at this stage, I still don’t know enough about Varnish to comment on the performance gain. I know it’s supposed to be a magic unicorn for managing traffic, but I don’t know too much about it yet. What I do know is that when I finally got Varnish setup and running properly, I tailed my mysql log and did the Apache Bench and Blitz testing and found that there were no (zero!) requests going to MySQL. Whether that has to do with WP Super Cache or Varnish, I’m honestly not sure. I hope to read much more about this in the coming weeks.

And that’s about it! With a finely tuned lamp stack, you really can serve a huge pile of traffic from just a 512MB, $5 VPS. It will take some time and effort, but you’ll learn a ton along the way. I will point out one caveat with this though: the need for speed is addictive. I started out just wanting to see what Digital Ocean was like a month later I’m editing a Varnish vcl file and sweating page load times over 500ms. But the good news is that it’s actually a lot of fun along the way. Enjoy!

The messaging app of tomorrow

A few weeks back, Facebook bought the (poorly named) messaging app, WhatsApp, for a metric tonne of gold bars. I’d never used WhatsApp before the acquisition (and now that Facebook owns it, I’m extremely unlikely to), but my curiosity was piqued. I downloaded and installed it, opened it up and expected something different than what I found.

whatsapp

This bajillion dollar app really doesn’t do anything until I connect with all my friends and convince them to go download it too. I can’t even send a message (the only thing the app does) to anyone unless they also have the app installed. Talk about a bummer.

So I went about trying to convince some of my contacts to give it a try. I went to three key people in my rolodex:

  • My brother:  “Can’t install any new apps. I don’t know what my App Store password is. Forgot it some time last year.”  aaah, ok.
  • My friend Matthew: “Nope” oh well then 
  • My wife: “I’m breastfeeding now. Maybe later, but unlikely.”  hard to argue with that then

I get the problem that Whatsapp solves, and I’ve seen the absolutely insane numbers they’ve posted since starting just 5 years ago. They’re enormous in Europe, South America and in lots of places in the developing world, and basically, everywhere except North America. I get why it’s a huge thing there and not such a huge thing here in Canada or in the US. I get it—I really do.

So when I describe the perfect messaging system in a few minutes, I don’t want you to say, “Aaah….he’s from North America. He doesn’t have the messaging problems that other places have. He doesn’t get it.” I’ve thought a lot about this and while I think Whatsapp is a neat app, I really don’t think it’s the messaging app of the future.

This isn’t your Dad’s messaging app

The messaging app I want doesn’t exist yet. For all I know, it’s technically impossible to make. The messaging app I want is extremely simple in theory: an always sync’d, any-device messaging service. Think iMessage for any phone, anywhere.

The messaging app I want will let me receive a message from a Samsung or Blackberry or flip phone on my desktop, let me reply to it right from there, and be instantly sync’d to my iPhone, my Nexus7, my home laptop, and — this is the big one — anywhere via the cloud from a web browser.

The messaging system of the future doesn’t care about contacts or devices or phone carriers. You send or receive a message from any device, on any device. Having messages tied to your phone is silly when you think about it—you don’t just send messages from your phone, do you? No. You send messages all day long, from wherever you are. Your desktop, your laptop, your phone, your tablet, your in-laws computer, etc. Messages should be tied to you, not to your phone.

Whatsapp is pretty neat for what it does, but it isn’t the messaging app of the future. This always ready, always sync’d, any-device system is. Again, maybe it’s technically (or politically) impossible — it’s hard to imagine Apple, for example, opening up its iMessages to another vendor, but we can dream.

This is the system I want, the system of the future — all your messages, available all the time, on any device. The company that can make this happen will be worth far more than $19 billion. Now we can only hope that Facebook doesn’t end up buying it.

How to Quickly clean up your iPhone photo stream

Two weeks ago my iPhone had 2,817 photos in it. It now has just 1,918.

How did I delete almost a thousand blurry, out of focus photos? I certainly didn’t click the little trash can at the bottom of each one. Nor did I have to go through and select all the rejects from my huge stream. I used Image Capture, a simple import application that ships with every Mac.

Image Capture

Screen Shot 2014-03-04 at 11.14.58 AM

Just connect your phone to the computer, start Image Capture and you can see all the photos you’ve ever taken. To delete the ones you don’t want, just scroll through and command-click to select the rejects. When you’re done, just select the red circle delete button at the bottom and the photos will be removed from your phone. The beauty here is that you can sort by size too, so you can see all those huge videos you’ve taken.

But now my backup folder is out of sync

Right, so now you’ve tidied your iPhone library, but the backup folder on your computer still has all the photos you’ve ever taken. Of course that’s a simple fix now too: just delete all these photos and re-import the culled photos from your phone.