Installing libmemcached on CentOS

I recently updated the Memcached WP Object Cache plugin to use the Memcached PHP extension – it currently uses the Memcache extension. My plugin is called Memcached Redux, and it’s delicious. The Memcached PHP extension implements methods from libmemcached, the C / C++ Memcached library.

Installing the extension on MacPorts is beyond easy:

port install php5-memached

Installing on Amazon EC2 instance running CentOS 5 is WAY more esoteric. I spent about 2 hours mucking around until I figured it out, so here it is (this assumes you are already using memcached and have libevent, libzlib, etc installed):

cd /etc/yum.repos.d/
wget http://rpms.famillecollet.com/remi-enterprise.repo
wget http://syslogserver.googlecode.com/files/epel-release-5-3.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm
yum --enablerepo=remi install libmemcached*
pecl install memcached

vi /etc/php.ini

// (under Dynamic Extensions) Add "extension=memcached.so":

extension=apc.so
extension=http.so
extension=memcache.so
extension=memcached.so

Servers have to be restarted – this has be done before code is deployed or the class won’t exist, which will cause a fatal error.

This process looks harmless, but I had to read 3.7 million blog posts before I found the right path forward.

Memcached Redux

I’ve been reading about Couchbase, and I knew it was compatible with Memcached out of the box. One of the features I wanted to start using was Memcached::getMulti and Memcached::setMulti. I knew the Memcached WP Object Cache plugin had a get_multi method, but I didn’t know what it did or how it did it. Turns out, it doesn’t implement Memcached::getMulti.

When I looked under the hood, I realized that the Memcache extension is loads different than the Memcached extension in PHP. Memcached has the getMulti method, Memcache does not. So I set out to change this: I have altered the famed Memcached plugin to actually use the Memcached class.

Because I did this, you can now use methods like this:

wp_cache_get_multi( array(
	array( 'key', 'group' ),
	array( 'key', '' ),
	array( 'key', 'group' ),
	'key'
) );

wp_cache_set_multi( array(
	array( 'key', 'data', 'group' ),
	array( 'key', 'data' )
) );

Rather than making many calls to grab data, especially related data, you can grab it in one hop.

I’m gonna keep working on the plugin, and drop a line if you install it and have comments / concerns.

The Plugin: Memcached Redux

Why Spotify Sucks

I just watched the Session Highlights of Spotify CEO Daniel Ek and investor/adviser Sean Parker’s talk with Walt Mossberg at the All Things Digital Conference, and it confirmed what I have thought for a long time: Spotify sucks, is bad for artists, and hopefully does not succeed. I am not saying this because I have bias (I work for eMusic). I am saying this because I am a musician, I know a ton of musicians, I play in a band, I have toured with my band, and I have seen behind the curtain of how the music industry works. I know how little money there is to go around it, and I can give you some examples.

Return of the Era of the Single?

One of the most irritating things I hear is that “people don’t want full albums, they only want singles.” People generally will say “albums only have one or two songs that are worth hearing, the rest is filler.” So, that’s a giant lie. Yes, I’m sure the one Chris Brown song you heard at the mall is the only good song on his record. But if you’re buying a Chris Brown record and going to the mall, you aren’t the kind of person that is going to deeply engage with a digital music service anyways. You probably also have bad taste. If you are a real music fan, you buy records because you like the artist. You want to hear the entire record.

Artists don’t go into the studio to record one good song and then load up the rest of the record with filler. I’m sure there are plenty of pop factory records that do, but in that case, the label is probably shooting to moon and trying to launch the new teen sensation or something. *Real* artists are trying to create something great. You would never get a Radiohead record and skip through the tracks until you found the hit. You listen to the entire record, know every song, and view the work as a whole, as a period in the band’s life.

Saying that people only want to consume bands and artists in a hyper-unaware, ADD fashion is insulting and a piece of misdirection. “Album sales are down, accept that people might pay for one song only and be happy about it!” No. There is nothing better than a great album by a great band. And there are many, new ones arriving weekly.

The simple facts are: an artist will make more money from the purchases of their album, digital or otherwise, than they will from the sum of streaming royalties. Let’s say an album sells for $10 on iTunes, the label gets $7, and the artist gets $2 of that. If the albums sells 100,000 copies – which in this day and age, is what a semi-famous indie will sell – the artist gets about $200,000. Assume the artist is a band with 4 people: $50,000 each (let’s make it $37,000 after taxes). If you’re from my hometown where the median income is in the mid-$20K range, congrats: you’re in the middle class. If you live in Brooklyn (probably Bed Stuy or Flatbush on that money), you make less than a 23 year old on their first job post-college.

So that money doesn’t look very good, right? Let’s look at another scenario. YOU’RE the label. You made the record in your bedroom, but it sounds great, and Pitchfork wrote about you. 100,000 albums is a dream, you sold 20,000 albums – huge numbers for a DIY-er. You make $140,000 / take off taxes / divide by 4. You’re poor.

Artists Have Other Revenue Streams, Right?

Um, not really…. I mean, there is touring. Let’s break down touring. Assume you are in my band, and you want to go on tour for 2 weeks (we’ve done this, a bunch of times). Before you even leave home, the vehicle rental is a fixed cost, about $3,000 – could be cheaper depending where you tour, but ultimately, it’s expensive. If your only income is your band, this could be a non-starter. $750 per man from someone making $1,000 a month is a lot of money. Remember, the money made from an album doesn’t come in one lump sum, and the royalties are cumulative for an entire 1-2 years, and money is probably only paid every quarter, if that often. And the money is only a reality if 1) you made an awesome record and 2) people buy it. Not just “people,” but every person who likes the album. You can see where our numbers fall apart again.

So not only do we have to pay about $3,000 for our van, we need to put gas in it every day. Not sure if you’re aware how expensive gas is these days, but speculation by banks into the commodities and futures markets have caused things like gas to shoot up into the holy shit expensive range. When you go to fill up your gas tank, expect to drop $100 every time. Let’s assume you fill up 2/3 of the days you are on tour (10 days). There’s another $1000 in fixed costs.

You might be asking, why not play venues that are closer together? You would save money! That would be awesome, but that’s not gonna work. Every state in America has a finite number of towns in it that are even remotely interesting. Try this: name 6 towns in Virginia that have music venues that support your style of music. Ok, now get booked in all 6 towns. You can’t because: you may have zero draw (number people willing to come see and pay money for it), the venue is already booked, the promoter might not like your music.

But let’s shoot the moon. Let’s say you booked all 6 venues back to back. Since you’re on a 2 week tour, let’s assume you’re playing every night. For one hour. Monday-Saturday, 6 nights in a row in Virginia. Since you’re new to the area, cover is $5 and you keep everything after the first 20 people pay. For four people in your band to split $100 a night, you need to have 40 paying customers every night for 6 nights. That means: to cover your gas for Tuesday and zero dollars left to split, you need to bring 40 people out to a music venue in Virginia, that may or may not even know who you are and have them plop down $5 to do so. You’re also trying to do this at a venue in a potentially backwoods town, and the venue might have 5 bands a night, 7 days a week.

This is not meant to be a horror story, this is reality. It is insanely hard to make money touring at a DIY level. But what you’re probably thinking is: yeah, but larger acts make a fucking killing, it’s just your shitty band that can’t make any money. Fair, but let’s break that down. Aerosmith? Yes, private jets, made $20M for 10 shows in Rio recently, boatloads of cash. Springsteen could sell out 20 nights in a row at Giants Stadium. But the number of people who can even come close to doing anything like that is very very small.

I know a band (they’ll remain nameless) that was recently in Pollstar’s Top 50 grossing acts. The band grosses about $1M a year from touring. They make guarantees at venues. A talent buyer calls up their booker and says he’ll give them $X to play at Y venue. The band thinks it over and might accept. They have a consistent draw in enough markets to command a decent guarantee. The band also sells a lot of merch. Because they are a jammy / folky kind of band, they don’t sell a lot of records. So, touring is their main source of income. Band has a booker, a manager, a crew, and 5 band members. My friend is in the band. What is his cut of that million dollar pie? $32,000 a year. $10K less than I made at my first job in NYC. And they’re a SUCCESS story!

Their tour bus runs about $700 a day. They have to add some production value to their show, so they have a crew. Manager takes his cut off the top, and they have to take out money for taxes. My friend assures me that NO ONE is making the money you think they are making from touring. A lot of major pop acts will release a single from a new album, and if it doesn’t blow up like they expect, they’ll cancel their stadium / arena tour, knowing how expensive it is to not have consistent sellouts (Kelly Clarkson and Christina Aguilera both cancelled tours a few years ago, rather than scale back).

So where are those other revenue streams?

Spotify pays about $0.0004 per stream. Let’s say you write an amazing pop tune, the internet goes crazy, and Spotify’s users stream that song One Million Times. $400. You and your 3 bandmates are taking home a cool $100 a piece. Having your song streamed a million times means your band has some level of fame. And your reward for blanketing Spotify with your single is 400 fucking dollars. Let’s assume my math is WAY off and Spotify actually pays a penny ($0.01) per stream. Congrats on your cumulative payout of $2500 per man. If you are super broke, you’re happy, for a month.

Of course, let’s realize that almost no one generates 1 million streams. So almost no one is making that much money, which isn’t even a lot of money.

Artists Get Exposure?

I have heard SO MANY people defend Spotify and say “but artists get exposure.” How? How does generating a $0.0004 payout to an artist qualify as anything other than “I just got to hear music on demand for free.” That artist probably spent $2000-10000 making their record. So those million streams are just paying them back for that (if they get the huge royalty rate of one fucking penny per stream, which is absurdly high). They then hope to translate those listens into paying customers at their shows.

Here is where the logic falls apart for me, because none of the people who say that (“artists get exposure”) are in a band, have toured, and have had to generate an audience of paying customers. It is very very hard to get all of your FRIENDS to come to a show, much less strangers in a area where you are not from and have no roots. Saying that streams translate into concert attendance makes the false assumption that everyone who listens to music sees all of those bands in concert every chance they get.

MOST people don’t ever see live music. MOST people don’t go out on Tuesday nights. Some markets work different than others. In NYC, you might have people come out on a Tuesday night and see you. In some college markets, the same. But even in rowdy college towns, you can’t always rely on a huge turnout on weeknights, even from those people who enjoy your music.

To make the argument that somehow Spotify changes this is ludicrous. Otherwise, what does “exposure” mean? Does it mean this listener is now going to spend top dollar for your goods? They were just of Spotify to SAVE MONEY, and NOT PAY full price, or at all, for your music.

There is no added exposure, there’s $0.0004 to you and your buddies.

Music is not Free

I don’t care how this sounds – Lars Ulrich was ahead of his time. Napster somehow made everyone believe that music is free and it is Your Right to be able to download the shit out of it, at will, for eternity. In that scenario, musicians are basically expected to live in abject poverty. Yes, you’ll have your manufactured stars that appear to have it all, and the few that break through actually will. But in society these days, music and movies and art are seen by the general public as not a product, but as an unalienable right that all people have to download and then vote on the life or death of the artists who created them.

At the end of last year, I was really into The War on Drugs lastest record. I actually see all the bands I respect live, so I was at their sold-out show at The Bowery Ballroom. I hung around after to have some beers and maybe meet the band, since I noticed they were packing up their merch tables themselves. Standing there, I overheard the lead singer’s friend ask the band where they were crashing that night (the band is from Philly). Lead singer: “The Red Roof Inn in Secaucus, my dad got us 2 rooms.”

LCD Soundsystem played their final show at Madison Square Garden last year, rounding off a year of a tour or 2 at some of the biggest venues and festivals across the world. James Murphy appears to make a bunch of dough, but I know someone who knows Nancy Whang (maybe the 2nd most recognizable person in the band), and she’s close to 40 years old and lives with 2 roommates. I know other members of the band do a lot of substitute teaching.

When I saw the Dirty Projectors play the 4th of 4 sold-out shows at The Bowery Ballroom a few years ago, they were setting up their own gear because they don’t have a crew, and that was at the height of their popularity – The Roots and David Byrne joined them on stage that night.

When Sharon Van Etten made her record last year, she actually didn’t live anywhere – she was crashing with different friends throughout. And these are the SUCCESS stories. These are some of the most revered artists of present day. Magazine covers, indie label contracts, the occasional video, Take Away Shows, sold out NYC shows. And they’re just scraping by. Spotify’s not saving them, and won’t.

Imagine what Spotify’s not doing for artists that aren’t at the top of the game.

Chatype, font for Chattanooga

I think I posted this on Facebook a while ago, but I was talking to some people about this weekend randomly so I figured I would post it here. Chattanooga is in Tennessee, about 2 hours from where I lived full-time from age 6-18, meaning I “grew up in Tennessee.” Everybody who is from Tennessee knows there are awesome aspects to the state, and there are bad / weird / crazy parts of it.

As with any landlocked state of Greater ‘merica, there are basically 3-5 towns that are even worth visiting, and a few more that are ok if you are from the area, and then the rest make up a strong voting contingency of the GOP and Fox News’ viewership. Nashville and Knoxville are cool. My hometown, Cookeville, is halfway in between them.

I’ve been to Chattanooga on several random occasions. It’s cooler than you’d expect. And by way of these Vimeo and Kickstarter posts, it appears someone fancies the town to be “the next ___” – I’m gonna guess Portland.

Anyways – I’m posting the links here so people can check them out, cool ideas:

Official Site: Chatype
Kickstarter (already funded): Chatype: A Typeface for Chattanooga, Tennessee.

Audio Redux + Updated Plugins

I had the pleasure recently of realizing that some of my plugins had disappeared from the WordPress dot org plugins repo because I haven’t updated them in 1.5ish years. Last year at WordCamp San Francisco, I used part of my talk to explain why plugins aren’t always awesome, and me not updating my own plugins is a great example of why. You might think to yourself, “Scott’s pretty good, I’m sure his plugins are awesome, I could probably get pregnant just by activating one of them!” To which I would reply: “If you are using my Movies plugin, I have absolutely no idea if it still works, and I’m sure every javascript library in it is 50-75 versions behind.”

So I am trying to right this wrong and update my code. Back in 2010, I was still under the impression that procedural programming was da bomb. Needless to say, the plugins should work a lot better now and will be maintained / are more maintainable.

Here are some of the plugins that are updated, along with their companion blog posts:

Minify
Plugin: http://wordpress.org/extend/plugins/minify/
Blog Post: http://scotty-t.com/2012/05/24/minify-redux/

Shuffle
Plugin: http://wordpress.org/extend/plugins/shuffle/
Blog Post: http://scotty-t.com/2010/11/15/my-first-plugin-shuffle/

Audio
Plugin: http://wordpress.org/extend/plugins/audio/
Blog Post: http://scotty-t.com/2010/11/22/new-plugin-audio/

Audio is awesome, and here’s why:

  • WordPress doesn’t come packaged with an mp3 player
  • Your player can be styled 100% with CSS – (drop in a replacement: STYLESHEETPATH . ‘/audio.css’)
  • If you use Shuffle, you can attach .ogg files to your .mp3s, and they will be used in native HTML5 browsers that don’t natively support .mp3
  • If you use your own styles, you can style a playlist automatically, and with Shuffle, attach image(s) to each MP3

BOOM. I will try to be a better man in the future and keep my plugins bleeding edge.

xoxo

Minify Redux

As you may or may not know, I wrote a plugin a while back called Minify. Its purpose was to automatically concatenate your JS and CSS files for you in your WordPress theme. Concatenation and minification are good front-end performance optimization techniques.  The thinking is simple: why request 10 files when we can request 1 optimized file? So that plugin existed for a little while, I said nothing about it, 20 people downloaded it, and then it completely disappeared from the WordPress plugin repo – random.

As of today, it’s back, and it’s way different. When I originally wrote it, I wasn’t working in a load-balanced environment with WordPress. I was working on one or 2 servers at a time on sites that were inconsequential as far as traffic goes. So initially, I was generating flat files.

When you get into the cluster business, you need to give up the notion of working with dynamically-generated flat files. Unless a user is “pinned” to a particular server in the environment, there is no way to determine if you are on the same server from page to page without some logic you shouldn’t feel like messing with – ah, the statelessness of HTTP.

When you are on many servers, Memcached is a great conduit for maintaining state and sharing resources. If that is true, why not use it for JS and CSS? As with all static assets, in the end, you are producing a URL that points at data. Where that data comes from shouldn’t matter. It should be produced fast, and if it can be distributed, great. Especially if you are behind a CDN like Akamai, once the data is requested, it will be cached there, where your local flat files aren’t being utilized.

How Does It Work

WordPress provides tools for enqueue’ing scripts / styles and resolving dependencies among them. When all is said and done, WP will output these scripts / styles when wp_head() and wp_footer() are called. Minify works by using add_action() and output buffering. Let’s take a look:

<?php
/**
 * Essentially, what happens
 *
 */
function minify_start_buffer() {
    ob_start();
}
add_action( 'wp_head', 'minify_start_buffer', 0 );
add_action( 'wp_footer', 'minify_start_buffer', 0 );

function minify_combine_scripts() {
...... a bunch of stuff happens / buffer is released .......
}
add_action( 'wp_head', 'minify_combine_scripts', 10000 );
add_action( 'wp_footer', 'minify_combine_scripts', 2000 );

From there, JS and CSS files are slurped out. Using JS as an example:

  • All srcs are retrieved
  • They are placed side by side in a string, which is then md5‘d
  • At this point – we either already Minify’d them, or they need to be Minify’d
  • Provide locking to serve old scripts temporarily to prevent cache miss stampedes on the new script generation

Cache Busting

Minify will essentially serve your files from the cache into infinity unless:

  • the cache expires
  • you edit the file to indicate expiration
  • you change the name of any file that is enqueued in the set

A Minify tab is specified in the admin to let you update your Minify increment. This is crucial for cache-busting a CDN like Akamai that won’t always request a new version of the file when the query string changes. The increment is included in the list of files that is stored and the generated source, so updating it will create a new list and new source.

Loading WordPress Without Loading ALL of WordPress

Using Andrew Nacin’s favorite constant, SHORTINIT, you can require wp-load.php and not load a billion plugins along with it. This is useful when you are pointing at a PHP file with a RewriteRule and need some WordPress functionality, but you have no desire to generate HTML source, or use plugins and themes. Since plugins are loaded by calling require( $plugin_file ) anyways, after you load wp-load.php, you can selectively load any plugin you need just by requiring it. That’s what I do in Minify:

<?php
define( 'SHORTINIT', 1 );

/**
 * load bare-bones WP so we get Cache / Options / Transients
 *
 */
$load_path = $_SERVER['DOCUMENT_ROOT'] . '/wordpress/wp-load.php';
if ( !is_file( $load_path ) )
	$load_path = $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php'

if ( !is_file( $load_path ) )
	die( 'WHERE IS WORDPRESS? Please edit: ' . __FILE__ );

require_once( $load_path );
/**
 * SHORTINIT does NOT load plugins, so load our base plugin file
 *
 */
require_once( 'minify.php' );

Anyways, we use Minify at eMusic. It has dramatically sped up our site / Javascript execution, perhaps more than any other single optimization. Take a look and drop a note if anything offends you.

Listen To This: “Bloom” by Beach House

The first time I listen to any Beach House record, I am turned off by Victoria Le Grand’s husky baritone of a female voice. But after awhile, I get more used to it and I hear more color. Plus, in real life, her voice doesn’t match her hipster-sexy vibe:

Oh Vicky…. (from @edroste’s Instagram)

The music is great, and does not disappoint after their last attempt, which most consider an indie masterpiece, Teen Dream.

Here are my favorite tracks from Bloom:

“Myth” – Live on The Late Show with David Letterman

“The Hours”

“New Year”

Couchbase

After reading an article on Tumblr’s architecture, I was intrigued by their affinity for Redis. I know lots of other projects use it, so I did some reading to find out if it was a suitable replacement for Memcached (it is marketed as “Memcached on Steroids”).

Redis is not an LRU Cache out of the box, it requires configuration for that. Redis is a NoSQL solution that provides a replication solution and can store key-values with expiration similar to Memcached.

A little about Membase:

Membase was developed by several leaders of the memcached project, who had founded a company, NorthScale, expressly to meet the need for an key-value database that enjoyed all the simplicity, speed, and scalability of memcached, but also provided the storage, persistence and querying capabilities of a database.

A then Membase became Couchbase:

As of February 8, 2011, the Membase project founders and Membase, Inc. announced a merger with CouchOne (a company with many of the principal players behind CouchDB) with an associated project merger. The merged project will be known as Couchbase. In January of 2012, Couchbase released a product building on Membase, known as Couchbase Server 1.8.

Most of the benchmarks I saw comparing Memcached and Redis: Memcached is still way faster yet “lacks the featureset of Redis.” Most of the benchmarks I saw for Couchbase used phrases like “sub-millisecond responses” / “twice as fast as Memcached.” I understand it’s cool to use sets and append / prepend to them in Redis, but other than those features, what makes it ultimately the better choice? I have concluded it just isn’t. If you like the tools it provides, awesome! If you want something that’s fast, has great tools, and is powerful all day long – why aren’t we all using Couchbase?