Mar 5, 2013

Some Best Practices for your Next MySQL Installation with SSD

Do you plan on installing a new MySQL server? 
Did you ask yourself what is the best file system for it? 
What modification are recommended? 
What MySQL version to use?
Do you consider using SSD?

You got to the right place.

Linux, SSD and MySQL. The Best Practices

  1. Up to date CentOS (6.3). MySQL RPM are easily available for this platform w/o the need to compile them.
  2. ext4 file system. It is has some goodies over ext3 and is even more recommended if you plan to use SSD (and you may need SSD if your system is resource demanding).
  3. File system discard option. Recommended for SSD to avoid the need to read before write.
  4. Consider some extra cheaper disks. SSD disks are highly expensive and can have a relatively short life if they are not used properly. Consider placing some cheaper disks (SAS or SATA) to handle tasks that do not require the high end SSD disks.
  5. Some more recommendations about Linux and SSD from Patrick's:
    1. File system layer: remove 'relatime' if present and add 'noatime,nodiratime,discard' to reduce writes and improve performance and disk life expectancy.
    2. Scheduler: use the 'deadline' scheduler instead of 'CFQ' to match SSD behavior.
    3. Swap: set a small swappiness
    4. tmp: move /tmp and /var/tmp to RAM disk to improve performance and avoid unneeded writes to disk.
    5. Partition Alignment: when creating a partition, enter a start sector of at least 2,048 and divisible by 512 to align pages.
  6. MySQL 5.6. 5.6 if finally in GA and it good idea to start working with it before 5.5 become obsolete.

Bottom Line
Few decisions can enhance your MySQL performance. Make your decisions right.

Keep Performing,
Moshe Kaplan

Feb 27, 2013

Instant Deployment with git

One of the nicest things in git is that you can actually deploy code to production (or just your test environment) w/o implementing a complicated CI solution.
Off course that using CI such as Jenkins is recommended when compilation is required (JAVA/C/C++/C#) or when TDD/unit tests are use (and you better use them).
Yet, when you just need to deploy, git can be a great service for you.

Note: please note that you must an ssh access from the local machine (not always feasble).

How is done?
Actually it is very simple (and a complete explenation can be found at stackoverflow and toroid):

Step #1: Setup a repository in the development environment and commit a first file
> git init

Step #2: Setup an environment at the web server
> mkdir /path/to/dir/website.git && cd /path/to/dir/website.git
> git init --bare

Step #3: Enable a post receive hook at the web server
> mkdir /var/www/www.mydomain.com
> cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/var/www/www.mydomain.com git checkout -f
> chmod +x hooks/post-receive

Step #4: Create a trigger at the development environment (and why you need ssh access from the workstation).
> git remote add web ssh://www.mydomain.com/path/to/dir/website.git
> git push web +master:refs/heads/master

Step #5: Code, Commit and Push to production
> echo 'Rocking website!' > index.html
> git add index.html
> git commit -q -m "The index file was commited"
> git push web

Bottom Line
It is a simple task, but tricky if you don't have a direct access to the server (anyone said Jenkins?)

Keep Performing,
Moshe Kaplan

Feb 13, 2013

Tracing SQL Server Performance and Stability Issues

The following two undocumented stored procedures will do a miracle to your efforts to trace issues in SQL Server:


  1. EXEC sp_readerrorlog;
  2. DBCC LOG('DATABASE_NAME', 3);
The first can be used to find failures, backup procedures and other goodies in the database log. The second can be used to trace heavy UPDATE, DELETE and INSERT transactions in the transaction log of a specific database.

Keep Performing,


Feb 11, 2013

mongoDB Configuration File Tuning

For those of us who are regular to MySQL, its configuration file (my.cnf) and the many options in it (some may say too many), mongoDB seems to be the simple.
With only few dozens of parameters in the configuration file (mongo.conf) and a dozen that are actually related to performance tuning, it may be a relatively short task to tune a mongoDB configuration file. Probably some of us will pay for that in production...

NOTE: this post does not refer the Sharding configuration.

What Can be Done?

Number of Connections
Like many other products (Apache httpd, MySQL...) the number of user connections can affect performance. mongoDB supports that using maxConns = N. Numbers can reach 20,000, but you should adjust it to your own server resources.

Write to Disk
Disk writing is usually a bottleneck in database systems. Therefore, wrtie to disk frequency and initial storage allocation can highly efhttp://stackoverflow.com/questions/8331099/what-is-the-javascript-engine-that-runs-mongodb-shellfect your system performance. Yet notice that delaying disk writing can effect your system recovery (many of you probably familiar with it from MySQL).
You should notice the following two options:
  1. Delay journal (database log) write to disk using journalCommitInterval = 300. This parameter supports intervals between 2ms (slowest but safest for recovery) and 300ms (fastest but prone to recovery options). The default os 100ms, but you may increase it to 300ms to save resources.
  2. Preallicate space at mongoDB startup by keeping noprealloc = false.
Disable Services
mongoDB provides many supporting services. Disabling some of them (if you do not use them), may help you save some CPU cycles:
  1. BSON validation using objcheck = false.
  2. HTTP Interface using nohttpinterface = true. The mongoDB HTTP interface exposes the database statistics and enables simple REST queries through port 28017.
  3. Scripting Engine using noscripting = true. mongoDB is using SpiderMonkey JavaScript scripting engine to enable interactive shell. Somehow, I have a feeling that you are not going to disable it.
  4. REST service using rest = false. See in the HTTP interface.
  5. Profiling service (inc. slow queries logging) using profile = 0.
Bottom Line
mongoDB is a simple, yet very effective tool to solve many business needs. Doing some tuning will help you avoid issues during peak times.

Keep Performing,

Feb 7, 2013

Jenkins? Tomcat? Running Code w/ Permissions? This script will probably help you!

If you need to run some "SUDO" commands from Jenkins, you will probably need to first 1) Add jenkins user to SUDO and 2) Avoid passwords.

The following code will do it like a miracle:


#!/bin/sh
echo 'Providing SUDO script permissions to jenkins'
if ! grep -q 'jenkins' '/etc/sudoers'
then
        echo 'jenkins  ALL= NOPASSWD: ALL' >> /etc/sudoers
        echo 'Defaults:jenkins    !requiretty' >> /etc/sudoers
        echo 'Completed Successfully'
else
        echo 'Already Exists'
fi

Keep Performing,


Jan 16, 2013

How to Find MySQL Locks?

If your MySQL (Master or Slave) seems to be locked, you can always use one of the following methods to detect the locks and take care of them:
  1. If it's an InnoDB based database use SHOW ENGINE INNODB STATUS\G
  2. Check SHOW FULL PROCESSLIST; to verify if any queries are running now (or just stuck).
  3. If you use MyISAM or just need some more information, enable the MySQL debug mode by using > mysqladmin -uuser -ppassword debug and then check for the output at the error log.
  4. Consider using tools such as mysqlreport (it has a nice explanation here) or mysqltuner to verify your server configuration.
Bottom Line
Locked database is not a nice thing, but it can be detected and eliminated...

Keep Performing,

Jan 2, 2013

Scaling Your Web Farm and Keep Supporting User Generated Content using File Sharing (NFS)


Have you ever wanted to scale your web operations to multiple web servers and still needed a simple common place to share data between servers?

rsync
A very useful way for that is rsync that is commonly used to distribute the web server static content (HTML, PHP, CSS, and JavaScript files) between different servers.

What to do with User Generated Content?
When we want to store user generated content such images, documents or video that are uploaded by them from time to time we have three options:
  1. Push them as BLOBs into the database (or your NoSQL system such as MongoDB).
  2. Store them on disk that is accessible by several servers. 
  3. Store them on a "File Server as a Service" like Amazon S3.
This time we'll focus on the second option:

DIY with Network Services
The basic solution for DIY is installing a file sharing daemon on one of your servers and share a folder of it to the other web servers.
There are three common file sharing protocols that may be used:
  1. SAMBA (that is common and supported by Windows as well).
  2. NFS (supported only on  *NIX machines).
  3. CIFS that mostly used in Windows, but can be mounted to LINUX machines as well.

In this case I decided to focus on the NFS implementation, so stay tuned:

NFS Configuration
First configure the NFS server
  1. Install the NFS RPM:  yum -y install nfs-utils
    1. Start service: /etc/init.d/nfs start
  2. Open the relevant ports in the iptables FW (2049 and 111):
    1. iptables -I INPUT -p tcp -s 192.168.85.0/24 -m state --state NEW,RELATED,ESTABLISHED --dport 2049 -j ACCEPT
    2. iptables -I INPUT -p udp -s 192.168.85.0/24 -m state --state NEW,RELATED,ESTABLISHED --dport 2049 -j ACCEPT
    3. iptables -I INPUT -p tcp -s 192.168.85.0/24 -m state --state NEW,RELATED,ESTABLISHED --dport 111 -j ACCEPT
    4. iptables -I INPUT -p udp -s 192.168.85.0/24 -m state --state NEW,RELATED,ESTABLISHED --dport 111 -j ACCEPT
  3. Configure exported locations by editing /etc/exports according to the following examples:
    1. Provide every server behind the firewall R/W to this folder: /path/to/directory *(rw)
      1. Please notice that in this case you should provide the relevent permissions on disk (since the guest machine will use in default the nobody user to access this disk). For example: chmod -R 777 /path/to/directory
    2. Provide a single server read only permission to this folder: /path/to/directory 192.168.2.21(ro)
  4. Finally load these exported locations: /usr/sbin/exportfs -a

Finally mount this disk to all other servers:
  1. Create local directory: mkdir /local/directory
  2. Add line to /etc/fstab
    1. SOURCE_SERVER:/path/to/directory /local/directory nfs
  3. Mount the folder: mount /local/directory
Bottom Line
Scaling you system is possible with few simple steps, this was one of them

Keep Performing,

P.S In the DevOps world, scripts is everything. So you may use the following: 
Server:

yum -y install nfs-utils
/etc/init.d/nfs start
mkdir /path/to/directory
chmod -R 777 /path/to/directoryecho '/path/to/directory *(rw)' >> /etc/exports
/usr/sbin/exportfs -a


Client:

#!/bin/sh
mkdir /path/to/directory
echo "$1:/path/to/directory /path/to/directory nfs" >> /etc/fstab
mount /path/to/directory

ShareThis

Intense Debate Comments

Ratings and Recommendations