Archive for the ‘Computing’ Category

MySQL Optimization on FreeBSD.

Friday, January 29th, 2010

I have my aviation site Planenews on a FreeBSD server. As traffic increased, I was getting more database errors. Looking around the web for clues, I discovered that FreeBSD did not have a default my.cnf file in /usr/local/etc. You can find sample files in /usr/local/share/mysql. I used my-huge.cnf, renamed it to my.cnf, put it in /usr/local/etc, et voila (don’t forget to restart MySQL)!

Problem solved? Nope.. I was still getting errors at peak traffic. I then found mysqltuner, a Perl diagnosis tool for MySQL. I was missing a few variables in my.cnf. See the file below, and notice the additions under “Added by Gil.”


# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-locking
key_buffer = 384M
max_allowed_packet = 1M
table_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 128M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 4

# Added b Gil:
# max_connections 250 crashes my server, use with caution..
#max_connections = 250
wait_timeout = 180
interactive_timeout = 45
tmp_table_size = 64M
max_heap_table_size = 32M

# Disable Federated by default
skip-federated
skip-innodb
skip-bdb

# Replication Master Server (default)
# binary logging is required for replication
#log-bin=mysql-bin

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id       = 1

# Point the following paths to different dedicated disks
#tmpdir         = /tmp/
#log-update     = /path-to-dedicated-directory/hostname

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

The site seems to be running fine now, with no errors. I guess I will have to wait for a story to make it to a major social networking site to see if it really can take a heavy load. Please tell me about your optimization tips, and how you prepared for traffic spikes…

VN:F [1.8.4_1055]
Rating: 0.0/5 (0 votes cast)
  • Share/Bookmark

Pretty Link Wordpress Plugin, Prettyfy Old Links Script.

Thursday, December 24th, 2009

I just discovered the Pretty Link Wordpress plugin, and I think it will help getting more returning visitors to my site, especially using the Pretty Bar feature. Problem is, I have 11,000 posts, with almost as many links. So, I wrote a Python Script to convert all your old post links to Pretty Links. You need to insert your database login on lines 23,24,25,26. Replace ‘planenews’ on line 49 by your site name, without the .com. Replace my domain by yours on line 58. If you leave line 69 as it, the script will set your Pretty Links to show with the Pretty Bar, standard parameter forwarding, group 1, traking on. If it works for you, you better send me a few bucks to buy a Cigar or a Cointreau, because this will save you a lot of time! (Click on the Donate button below), Scroll down to get the code…




Update: You may have to run it a few times until the script returns no result.. No time to figure out why.. Make sure you backup your database before playing with this!

VN:F [1.8.4_1055]
Rating: 0.0/5 (0 votes cast)
  • Share/Bookmark

Sitemap Python Script for Wordpress.

Sunday, December 13th, 2009

I had problems with the Google XML sitemap generator plugin because of my database size, more than 10,000 articles. Here is a Python script that will work no matter how large your database is. Make sure you edit the domain name at the end, for the home page entry, path to the sitemap.xml file, and of course, put in your database login info. Put the script on a cron-job, et voila! See the code below…


VN:F [1.8.4_1055]
Rating: 0.0/5 (0 votes cast)
  • Share/Bookmark

Converting From PHPNuke to Wordpress.

Thursday, December 10th, 2009

Here is a script to convert you PHP-Nuke database to your new Wordpress one. It does not transfer comments, but does users, topics and stories. It is written in Python. You need to edit the database logins and specify your url and PHPNuke admin user id. The MySQLdb Python module must be installed. If it works for you, you better send me a few bucks to buy a Cigar or a Cointreau, because this will save you a lot of time! (Click on the Donate button below), Scroll down to get the code…





And by the way, here are the two lines to put in your .htacesss file to convert the old PHPNuke URLs to the new Wordpress numeric urls. The will turn, for example:

http://planenews.com/modules.php?name=News&file=article&sid=11117

into: http://planenews.com/archives/11117

So your visitors coming from an old link won’t miss a beat.. Here it is:

RewriteCond %{QUERY_STRING} ^name=News&file=article&sid=([0-9]*)
RewriteRule ^modules\.php$ /archives/%1? [R=301,L]

VN:F [1.8.4_1055]
Rating: 5.0/5 (1 vote cast)
  • Share/Bookmark

Backing Up Your Computer.

Wednesday, November 11th, 2009

I can’t tell you how many times an acquaintance or friend has come to me with a broken hard drive asking “Can you get my data back?” as if their lives depended on it. The experience can be quite dramatic. I feel like a doctor telling family members that their loved-one has passed away. Losing all your data can be very stressful. Think about photos you can never get back, hours, weeks, months of work erased, just like that. You get the picture. Hard drives have moving parts, they spin at around 5000rpm. Soon or later, they will break, you can’t avoid it. Is your data backed-up? If you say yes, go do something else. Otherwise, keep on reading, you will thank me profusely some day.

It used to be that a couple CDs, or more recently, DVDs was enough to back-up all of one’s data. Today, with videos, movies, high resolution cameras, data fills-up hard drives like shoppers at Walmart on black Friday. Not to mention that if your drive bites the dust, you will have to reinstall your operating system. If you’re using Ubuntu like I am, not big deal, it’s free. If however you can’t find your Windows registration, guess what, $200 for Micro$oft. Hopefully you also have all your software somewhere safe, ready to be reinstalled.. Think about the amount of work though.. Who has the time to sit in front of a computer looking at a progress bar all day, or pay some geek a fortune to do it for them? I don’t.

These days, you are looking at two options. 1, a full drive backup on separate hard drives. 2, an online backup service. Let’s look at both solutions..

A full drive backup is great because you can make a mirror image of your drive, which can then be restored to a similar drive. You don’t have to reinstall anything, your entire drive is copied bit by bit independently of your operating system. It takes a few hours, but the recovery is painless and very easy. You will need two USB external hard drives of the same capacity as your main hard drive. Why two? Because your hard drive can fail during a backup operation, rendering your backup useless! So, you alternate the drives and backup every other week. At the most, you’ll lose one month of data updates. The downside of this scheme is that you can’t use your computer while it is backed-up. I do it at night, usually it is finished when I get up. You can also lose quite a bit of data if you are not diligent enough. You will need a drive cloning tool. Get G4L, it’s free and works great. You burn it onto a CD and use it to boot your computer. Be careful when you choose your source and target drive, you don’t want to backup an empty or old image to your current drive! An remember, it only works if you actually do it regularly!

The online backup solution is very convenient. You pay a small monthly fee, usually $10, to have your data automatically uploaded to a storage facility via the Internet. You can choose what folders to save, or exclude certain types of files by extension or size. What I like most about it is that it is transparent. You can still use your computer as usual while the program works in the background. I don’t notice any performance difference with the service I use. You need to make sure that the transmission of your data is encrypted, and that it also be encrypted wherever it is saved. Nobody should be able to read your files. The best service I have found is SpiderOak. They give you 2Gb for free, and charge only $10 per 100Gb. Their client program is great, and all data is encrypted. You can even synchronize your laptop with your desktop, or other computers. The process is pretty slow the first time you use it. I just uploaded about 84Gb in the span of a week. After your initial upload however, it is much faster. The good part was that I didn’t have to care about it at all. It works on Windows, Linux and Mac.

Which solution is best? Well, I highly suggest doing both! Make a mirror copy of your hard drive (you can use only one drive then), and have your data backed-up online with SpiderOak. This way, after a crash, you load the drive image with G4L, then update your data from your online backup. Everything is up-to-date, and you don’t have to reinstall anything.

Can you afford to spend $80 on an external hard drive, or/and pay $10 per month? Can you afford not to? Can you lose all your data? Remember, it’s not “if,” it’s “when.” Back-it-up!

VN:F [1.8.4_1055]
Rating: 4.5/5 (2 votes cast)
  • Share/Bookmark

Gil's Blog is Digg proof thanks to caching by WP Super Cache