Vagrant providers. Virtualbox vs. VMware.

Vagrant is an awesome tool. If you’re not using it on your development project then you should get your head checked. Being able to magically recreate a whole development environment with a simple vagrant up command is a godsend even if you’re the only developer working on a project. It saves time (aka money) and countless headaches. Now, this isn’t a post about Vagrant but I wanted to set the stage. This post is about a couple of the popular providers that you can use with Vagrant — Virtualbox and VMware.

Virtualbox

Virtualbox’s best feature is it’s price. It’s free! Don’t get me wrong, it does work and for some people it works well enough. The two glaring issues I have run into with Virtualbox are the shared folders and the overall performance.  Some people that I’ve talked to have claimed that the performance hit is related to shared folders and going a different route (SMB, NFS, etc) resolves this. More critically, we have also run into a bug with how it handles symlinks. Somewhat surprisingly, we have only encountered this on Windows host machines; Mac’s seem unaffected. More on the performance issue below…

VMware

VMware has so far proven to be a great choice. It’s stable, fast, and everything simply works. The downside is that Hashicorp wants $80 for the VMware plugin. That’s on top of the price of VMware Workstation or Fusion. Note that VMware Player will not work. Not exactly cheap.

Speed

There are countless ways to measure this. The way I did it may not be the best way nor representative of your usage. Take this with a grain of salt. I work with a fairly large PHP application. To measure, I took five different pages from the app and profiled each page three times with xhprof. Then I graphed the average of the three runs for each page. For those that are curious, the app is built on ZF1. Here are the results for both Virtualbox and VMware…

xhprof results - virtualbox vs. vmware

If you’d like to see the raw numbers, comment below and I’ll post them later. All reasonable efforts were made to eliminate as many variables as possible. Although the VMware base box couldn’t be the same one as the Virtualbox one, they both were running Centos 6.2 with the same versions of Apache, MySQL, etc etc. As you can very easily see, the app ran much faster with VMware. This confirms the perceived ‘snappiness’ disparity between the two.

Conclusions

For any real work, you’ll want to at least strongly consider VMware. There is a cost but even if you save a few hours of pain later on, it’s worth it. If you do go the Virtualbox route, you’ll be happy to know that it doesn’t take too much work to make the switch later on if you have decent Vagrant and Puppet (or Chef) scripts setup already.

Update

As a workaround, NFS is looking like it’s a potentially viable alternative to the shared folders offered by VMware and Virtualbox. I’ll report those results after tinkering with NFS and profiling again.

Leave a Comment

A Simple and Effective PHP profiler: xhprof

Recently, the team that I’m involved with has started to look into incorporating some level of profiling into our workflow. To that end we looked a variety of tools including xdebug, Pear’s profiling package, xhprof, and ADP. We ended up settling on xhprof. This tool was conceived by Facebook for their own needs and eventually open sourced (lucky us!).

xhprof_screenshot

Setup and install is fairly simple. I highly recommend Lorenzo Alberton’s blog on the subject. The great thing about xhprof, and the reason we chose it over the others is that it’s lightweight, fast, and very detailed. The gui that it comes with definitely won’t win any design awards anytime soon. However, the information is all there and everything simply works.

Initially, the engineers on our team will begin to incorporate xhprof into their daily workflow to get baseline measurements which we then compare against measurements taken after a piece of code is refactored or a feature is added. We plan to discuss our experiences during code reviews on a weekly basis and perhaps at some point establish some company wide best practices (if any) regarding code profiling.

If we learn anything of note during our time with xhprof, I’ll be sure to post a follow-up article!

Comments (1)

It’s Been So Long!

Almost three years since my last post here.  I’ve been getting the itch again so stay tuned for upcoming posts on a variety of topics including (but not limited to):

  • xhprof, a PHP profiler
  • Yii, a rapid dev framework
  • Zend, largely regarded as the de facto framework
  • Symfony, another popular framework
  • initial thoughts on Python
  • Jenkins, a popular continuous integration server
  • PHPUnit, a unit testing framework
  • Vagrant & Puppet configuration & usage
  • VMware vs. Virtualbox as Vagrant providers
  • and much more

Until next time!

- George

Leave a Comment

Sphinx With MAMP

It’s late and I’m pretty damn sleepy so I’ll just do this in quick lists. Today I was trying to install Sphinx on my local machine, a Macbook Pro. I’m using MAMP 1.9 to dev a new project which will involve Sphinx. However, installing Sphinx turned out to be kind of a pain in the ass. Just as a note, my laptop wasn’t running mysql to begin with.

The problem occurred when trying to install Sphinx (latest stable version – 0.9.9) with mysql support. Apparently MAMP 1.9 doesn’t come with all the mysql files that Sphinx needs to install with mysql support. Doing ./configure on Sphinx just kept leading to dead ends and a message asking me to install the mysql-devel package or explicitly specify MySQL library folders and such and specifying various folders inside of MAMP didn’t turn out well.

Now I’m sure there’s a more ‘ninja’ way to do this but this is what worked for me:

  • Install MySQL. Download the DMG from http://dev.mysql.com/downloads/mysql/. Make sure to download the correct one (32-bit vs. 64-bit). After that it’s a surprisingly simple install. You don’t need to start the service or install the MySQLStartupItem.pkg.
  • After that, ./configure on sphinx worked just fine since MySQL and all the various files are in all the standard locations. Make sure to include the path to install to via the –prefix option. The typical Sphinx installation usually goes in /usr/local/sphinx/ so: ./configure –prefix=/usr/local/sphinx
  • Now do make and sudo make install
  • Everything else is fairly straightforward.

Some extra notes:

  • When configuring your sphinx.conf file, make sure to set sql_sock = /Applications/MAMP/tmp/mysql/mysql.sock when editing your sources. Also don’t forget to specify the right port (MAMP defaults to 8889 for MySQL).
  • Not sure why but it kept trying to look for sphinx.conf in /usr/local/etc/sphinx.conf so when running indexer or search I would have to explicitly specify the location of the sphinx.conf file.
  • If you get permission errors when doing indexer it’s probably because you forgot to sudo.

Drop me a comment if this helped you any or if you have other questions!

Leave a Comment

Importing PhotoPost Pro photos to vBulletin Albums

Background
First, a little background on this post. I own a socal mountain biking forum, www.socaltrailriders.org and recently had to upgrade from 3.8.2 to 4.04. Along the way I also updated vbSEO, and our classifieds system to make them compatible with 4.04 which was a major upgrade. However, we were using Photopost Pro for our photo gallery software but I wanted to move to vBulletin’s albums after having some issues with Photopost Pro.

I researched ways to import from Photopost Pro to vBulletin albums but found no solution. Being a dveloper myself, I decided to make one. This would be my first time making any import script for third party software but I figured it couldn’t be too crazy, right?

The Research
I started off by doing some exploration and figuring out how files and database data are laid out for both Photopost and vBulletin’s album system. I had to dig in a little bit to really figure out how both pieces of software really ticked but now have a fairly good grasp of how it’s structured which is critical if you want to make an import script. vBulletin actually had a bit more nuances than Photopost which was fairly straightforward to figure out. For example, for a user with ID of 191, vbulletin stores attachments in the path “[attachment dir]/1/9/1/”.

Validation and Checking

I’m a strong believer in building code that handles all types of situations in a graceful manner. What if Photopost’s database references a file that no longer exists? What if you’re trying to move files somewhere that you don’t have write access to? These are just a couple of situations that you have to account for in an import script. So, I built a ton of it into this import script and tested it until I was very confident that it would handle every situation in an appropriate manner.

“Features”

I say “features” because this is more of an overview of the functionality of my photopost pro -> vb import script. But I’ll just list the ones that come to mind:

  • categories are preserved and can be configured a bit. categories created by members in Photopost will become albums in vBulletin. on our Photopost gallery, we had a series of categories that were shared amongst a lot of members. since vBulletin albums aren’t shared, I coded the import script to create a new album for the user if they had uploaded to one of those common albums.
  • Also, it can import multiple Photopost categories into one album. For example – on our Photopost gallery we had close to ten categories related to bikes which everybody shared. I configured it so that if I uploaded 4 photos across four of those bike categories, it imported those photos into one vbulletin album called “My Bikes” for me.
  • Photo titles and view counts were preserved.
  • Thumbnails were created based on the max attachment width specified inside of vBulletin’s options.
  • Lots of other little things…

What it doesn’t do: preserve comments or permissions.

Do You Need a PhotoPost Pro -> vBulletin Album Import?

I realize some of you out there may want or need to move from PhotoPost Pro to vBulletin so I’ll offer this import as a paid service. Comment or email me for information about that.

albums in vbulletin freshly imported from photopost pro

Comments (8)

The Legend of the Street Programmer

     A long time ago there was a young upstart programmer who believed firmly in coding standards and the DRY principle. He was in a dev team which, for the most part was fairly productive, despite their manager. One day the dev team met with their seasoned manager who was deeply imbued with the lead-last form of leadership and well versed in the art of stifling progress, as a good seasoned manager should be.

     One day the upstart programmer disagreed with the seasoned manager on the topic of database normalization. The upstart programmer, seeing that the database was unnecessarily repeating too much of the same data, in various tables, wanted to apply DRY principles by adopting at least the first normal form, otherwise known as 1NF.

     Upon hearing the upstart’s argument, the seasoned manager responded with,

“Young upstart, you may read a lot of books, but out in the real world, out on the street, we do things differently.”

     Thus began the legend of the Street Programmer.

     You see, the seasoned manager had real world experience, and in his world, real-world programmers (the type that programmed from the street) simply didn’t have time to read books, or catch up on latest technologies. No, in fact, if they didn’t agree with the purpose of a new concept, they burrowed themselves deeper into their comfortable leather chairs and dismissed all comers for lack of experience.

     The seasoned manager, being a Street Programmer himself, went on to talk down the use of hashed and encoded passwords, the uselessness of Object Oriented Programming, and spoke lovingly of the use of REGISTER GLOBALS in PHP. This was not a man to be trifled with, he was a man of the street, and he knew his business.

     The upstart programmer, having seen the error of his ways, turned his face downward and exited the conference room where the Street Programmer reigned supreme, and subsequently got a new job that though lacking in a sufficient amount of Street Programmers, was still able to make do. The Street Programmer’s company had other ideas, he was able to sell it to marketing types who bought into the depth of his Street Programming knowledge, and he walked away a happy man.

Leave a Comment

More Speed: CSS Sprites!

Hey folks! This ones for those speed freaks who are never satisfied with their page load times. This is for good reason. Page load time could mean the difference between a conversion and a lost visitor.

Why?

There are many, many things you can do to improve site performance. Today I’ll explain CSS sprites and why they can help with performance. The goal of using CSS sprites is to minimize the number of HTTP requests. Each HTTP requests has overhead – the browser has to send a request to your web server and then the web server has to respond with an answer (which could include an image, css file, etc). So minimize the amount of HTTP requests and you speed up your page.

What’s a CSS Sprite?

What the heck is this CSS sprite thing that I’m talking about? Well you know all those little background images that you put on your webpage via CSS? They may be round corners, gradients, icons, etc. Well each of those comes with the price of HTTP requests. Using CSS sprites is essentially a technique of combining some of those background images into one image (called the sprite) to minimize the number of HTTP requests.

How?

Luckily there is a tool that makes generating this CSS sprite super easy: SpriteMe. It was created by Steve Sounders, a performance guru. Once you create your CSS Sprite, use it in your CSS by utilizing background-position. Using background-position, you can adjust which part of the CSS Sprite shows up, allowing you to reuse the CSS Sprite throughout your page. On a recent project I was involved with, we reduced the number of HTTP requests by 13!
example of css sprite

Interested in more performance tips? Feel free to check out the Yahoo Developer Network, they have some great advice on this subject.

Leave a Comment

Older Posts »
Follow

Get every new post delivered to your Inbox.