Latest Tweets:
Name's Jacob Thomason. This is my blog. Ignore the rants, comment on opinions, and enjoy the rest.
About Jacob | Questions? | Archive | RSS
Sometimes I wonder about people. I mean, I get it. This person probably speaks English as a second language. But, at what point do you not think that you should get your marketing material proofread before handing it out to potential clients?
How am I to think that you’re going to do a great job on my lawn care when you won’t even take the time to do a great job for your own business?
While this is a very simple and clear example. I think the message here is powerful for anyone.
Take the time to do it right.
Update: I should mention that some newer frameworks like Symfony2 and Rails3 solve this issue through bundles and plugins respectively. I haven’t had the opportunity to play with these just yet, or their exact implementation specifics, but it sounds super promising for solving this issue.
One of the problems with MVC is it’s lack of flexibility when it comes to sharing “chunks” of code/logic between various parts of your project. Invariably, as the size of your project grows, you’ll be faced with the need to share these “chunks”. Without thinking outside the box just a bit, you’ll be stuck replicating code, or possibly including another helper function or file.
I’ve been faced with this issue multiple times. Usually the answer has been to just replicate the code, since there has been bits that are slightly different each time anyway, at least that’s how I justified the behavior. But, even still, it didn’t make me feel good and certainly didn’t make me feel good when edits have to be made at a later date.
So, in my latest encounter with this issue, I decided to come up with a more “proper” solution to this quandary. First, I should preface that I’m using symfony 1.x. However, most MVC archs are similar in their approach.
The issue I was faced with was the controller logic that’s shared between various applications. Each application is certainly it’s own beast, but there are a few small “chunks” that are nearly identical between these applications. In our case, our billing profiles are used the same across all applications. Therefore, the controller logic is nearly identical. So, as opposed to setting up methods for each of these routes within each applications’ specific controller, I’ve decided to create a new set of global controllers in our library. These global controllers extend the framework’s default controller class so we maintain all the same functionality as a typical controller. Then, in the controller for each “module” (read: section of a site /blog /products, etc), I just replaced what class is extended to our new global controller class. So in effect, I created an intermediary class that can then be used across any controller that needs access to the specific controller methods (routes).
In retrospect, the concept is pretty obvious and really quite simple. However, it may not be inherently obvious at first, so I wanted to share this bit with anyone else that might be facing a similar issue. Code on!
One of the issues with creating highly normalized database designs is that you invariably end up with a lot of inefficient joins in your queries. This can really start to slow down an application. At RentPost, we were recently faced with this issue when building out a new flexible address system for all the entities within the database. The db schema is awesome, super flexible, but it made the select statements an absolute nightmare.
Enter MySQL VIEWS with query_cache. Because these entities don’t change a whole lot and they’re primarily used for select statements, we can fully take advantage of the speed that query_cache can offer in this scenario. The trick though (unless you’re running a website with a large number of selects vs insert/update/delete queries) is to set query_cache_type = 2. This enables your query_cache in an ondemand fashion, so it’s not interfering with the rest of your queries.
So, now, you can create your super fancy VIEW with your crazy joins and then apply sql_cache like the following to enable caching on your VIEW.
CREATE VIEW `foo` AS SELECT sql_cache a.id, a.name...
This is simply going to tell mysql to cache this select statement and now your view is going to be super duper snappy! So, when you have a particular dataset that’s commonly used across your application, where you have a lot of join issues, the combination of VIEWs and query_cache can offer some serious speed benefits.
I didn’t run any actual speed tests on this, but I observed a localhost query in a loop go from roughly 30 seconds to just under 2 seconds. Your mileage will vary and this example is a very drastic one, but the benefits are clear when used in the right situation.
Here are the mysql config settings you’ll need. I’ve added these to my my.cnf
query_cache_size = 64M #query cache of 64M
query_cache_type = 2 #ondemand use sql_cache after SELECT
You designers know the story… You need to pick that perfect font, but you have soo many on your local system and it takes a lot of time and effort to go through them all and test with your words to see how they turn out.
Well, I’ve just come across an excellent site (yes a website) for doing this and I had to share with everyone. wordmark.it allows you to import all of your fonts for preview directly within the browser. The interface is very clean and intuitive. My favorite part, is that I can add a word I want to test with, see all the fonts side by side, and then select all the ones I want to keep for now. Then I can filter down based on the ones I selected and further compare, until I’ve picked that perfect font!
Now picking that perfect font doesn’t have to be such a chore. I use to dread this process b/c of how tedious it was. But with this method, it’s even enjoyable. Color me happy!
So, after dealing with APC and all the troubles and woes, I’ve finally decided to give xcache a go. I originally decided to go with APC as there were talks of it being included in php6. However, as php6 was backported to php5.4, APC support was dropped. Recently there have been discussions on including Zend’s Optimizer+ in PHP. However, this is discussion and Zend’s Optimizer+ appears to have been baked into their encoding plugin which I’m not interested in. So, XCache it is!
Upon the decision to go with XCache, I first tried installing the homebrew repo package. That didn’t go so well as that installed version 2.0 and also it flat out didn’t work. It’s quite possible that it was a version issue, and possibly also a php binary issue (I have 2 installed). So, I decided to compile it manually. The first step was to look for a quick guide from someone who had done this before. But as luck would have it, I couldn’t find one. So, while doing this myself, I figured I’d document the steps for others looking to do the same.</>
The first step is to download the src code from lighttpd’s site.
After downloading, you’ll want to run the following commands.
Keep in mind that I’m using homebrew’s install of php5.4. If you’re using another package you’ll want to customize your configure parameters accordingly.
The following assumes you’ve setup your homebrew php in your default $PATH accordingly
$ wget http://...(the release url)
$ tar -zxf xcache-*.tar.gz
$ cd xcache
$ phpize
$ ./configure --enable-xcache --with-php-config=/usr/local/Cellar/php54/5.4.8/bin/php-config
$ make
#note the installed extension path for your extension = "/path/to/xcache.so" after the following make install
$ sudo make install
Now that you’ve successfully installed the extension. You’ll want to edit your php config and add the extension path, restart php-fpm if you’re using FastCGI or Apache if you’re using mod_php.
After that’s been done, you should have xcache up and running.
Note that I had an issue with /dev/zero as the xcache.mmap_path path. I’ve set mine to /tmp/xcache instead. However, you might consider correcting this issue. I suspect it’s permissions related.
Some additional things you may wish to do is optimize your settings for best performance. In particular, you may with to increase the RAM allotment.
Also, in the source files, you’ll see an htdocs folder. If you copy this over to your web root and call the path to the cacher folder, you’ll be able to access the interface for viewing your xcache performance and more.
Best of luck!
OK, it never fails, something happens, your slave gets out of sync with your master, your binary logs fall behind, something gets corrupted, etc, and there you are sitting with a worthless slave. In my case, the database and binary logs had outgrown the partition set aside for the database, it also caused alerts to not get fired, but that’s another story for another day. Luckily I was able to target it b/c our backup system, which uses the slave for point-in-time archived backups, started throwing errors.
So, enough of my story, I’m sure yours will be a bit different. Now the question is, how do you fix this? It’s possible that you can restart the server and it will bring it back up to speed. However, in my case, the bin logs were way out of wack, so if you’re in the same boat, or just want to take this cleanup route anyway, here is how you can get everything back on track.
First, you should make a backup of your master database just in case something goes wrong, you never know.
After making a backup of your master database, you’ll want to access the master server and run the following:
#you'll need the master mysql password here
#you'll need to make note of the master status, file and position
mysql -u root -p
mysql> RESET MASTER;
mysql> SHOW MASTER STATUS;
mysql> EXIT;
#you'll need the root mysql password for slave. You'll also need to configure the slave host in your .ssh/config file and ensure your ssh keys are setup on the master
mysqldump -u root -p --master-data --opt --single-transaction --comments --hex-blob --dump-date --no-autocommit --all-database | gzip -cv | ssh user@host 'cat > ~/dump.sql.gz';
mysql -u root -p -S /path/to/mysql-slave/mysql.sock
mysql> STOP SLAVE;
mysql> RESET SLAVE;
mysql> CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.xxxxxxx', MASTER_LOG_POS=xxxxxxx;
mysql> EXIT;
#this could take a bit depending on the number of databases/tables you have
gunzip ~/dump.sql.gz
mysql -u root -p -S /path/to/mysql-slave/mysql.sock < ~/dump.sql
mysql -u root -p -S /db/lib/mysql-slave/mysql.sock
mysql> START SLAVE;
mysql> SHOW SLAVE STATUS;
At this point, you can now check and confirm that the slave status reports that replication is running on I/O and SQL. If you see “Yes” on both of these values then you should be in business. It never hurts though to perform another check by making sure that data is getting synced.
God speed!
So, google got around to updating the Panda version of their algo this weekend. This is what Google officially had to say about it…
Panda refresh rolling out now. Only ~1.6% of queries noticeably affected. Background on Panda: http://t.co/Z7dDS6qcSo, only 1.6% of the queries were affected. While this might not seem like a very large percentage, I’d argue that it actually is, b/c the ones that it affected, it affected in a very large way.
As we’ve seen time and time again with Panda, Google has been slowly killing off the black-hat SEO networks. (Finally! I’m not a fan of people who cheat the system, as I am sure most people who play by the rules agree.) And, this update is really no exception. Google has made it clear they are targeting the blog networks and link farms. If you are using any of these services, you’re wasting your time. They aren’t necessarily going to hurt you but, they aren’t going to help. Google has started de-indexing these services one at a time, and I think this is primarily what this update has done, adding to their list of de-indexed networks.
Let’s take a look at the history of the Panda updates, compliments of SELand.
So, in short, don’t try and cheat the system, you’re only wasting your time and resources. Unless you’re doing affiliate marketing where you want to get to the top of the results for a short lived period of time, investing your time and money in these techniques isn’t going to get you anywhere in the long run.
So, I’m trying to pull together some electronic music fans! I need a little help here. If you are into electronic music and have a Spotify account. Please check out my collab playlist, Electro-fi. I’d like to get one really large, really awesome playlist put together that everyone can enjoy.
For me, I like to listen to electronic music while I am coding. It’s excellent for keeping the pace, subtle and not distracting as music with words can be many times.
Dreams make for awesome ideas. I want to see a room where the painting is done by multiple colors of foot prints all across the ceiling and possibly down the walls as if someone was walking. Feet of all sizes too. I think this has epic potential.
Maybe you have this really crazy multicolored chandelier in the middle of a room, fairly high ceilings, and all of these multicolored foot paths steps away from the chandelier and slowly fade out as they would naturally from the paint running out. Some would come down the walls just a bit, others only a few steps away from the chandelier, etc.