November 17, 2019, 10:47:57 pm

News:

Have you visited the Allwinner Chipset wiki? - http://linux-sunxi.org/


Reduce response time of a web server on cubieboard2

Started by victor, November 04, 2013, 09:13:04 am

Previous topic - Next topic

victor

Hello,
I am really new to cubieboard and I already like it a lot. I have a cubieboard2 and a 8Go SD card.
Thanks to the forum, I have been able to successfully install several distributions on a SD Card.
Trying to install a webserver (Apache, PhP, Mysql) on it often lead to a broken package system (apt-get); until I tried the .img packaged by patwood  :)

This OS is working very well so far. I have been able to extend the initial partition to fill my 8GB SD Card (using fdisk and resize2fs).
I have installed my web application on the cubie, and it works :)
Next steps for me :
   - Move the OS from SD to NAND (I have found usefull ressources on the forum)
   - Optimize my web application response time
   
I am now writing here to get some help on the second point : my app uses a lot of different files, stored on the SD card + a Mysql DB. It is quite slow now. I suspect that the disk access are slow, which impacts the overall reactivity of the app.

Can you give me advices on how to determine why my app is slow on this machine ?

Thanks a lot,
Victor

patwood

You can try setting some of the I/O flushing settings in mysql to see if that's what's slowing things down.  From what I've seen of sqlite, an update can cause lots of small writes and file system changes (create a new file, copy data to it, flush, unlink, rename).  Most SD card firmwares are not optimized for small data writes.

gustagi

For PHP 5.4 use apc cache.
For PHP 5.5 use Zend OPCache.

hwatari

Your problem is with OS running out of SD card, I had the same problem.
Now I'm running lubuntu on NAND and I installed MySQL with apt-get.
I installed 2.5" disk for database storage.
Hope this helps.

milkboy007

easiest solution:

1. use better lightweigt app (lighhtpd, ngix, sqlite, etc...)
sqlite work well on sd card since its a single-file based database, unlike mysql's multiple file. IMO
google on the pros an con first to see it fit your need

2. better SDcard or move root to hdd.

3. lastly if you really line to know what's what, im assuming your skill are limited,
http://www.hackmysql.com/nontech
abit old but should work, and it can determine what are the slow queries.

victor

Hi,
First, I would like to thank you all for your answers. I will try to give a proper response to everyone :)

Quote from: patwood on November 04, 2013, 03:18:30 pm
You can try setting some of the I/O flushing settings in mysql to see if that's what's slowing things down.  From what I've seen of sqlite, an update can cause lots of small writes and file system changes (create a new file, copy data to it, flush, unlink, rename).  Most SD card firmwares are not optimized for small data writes.

Thanks for the advice, but I don't really know which settings you are talking about... From what I read here, I tried to set  key_buffer_size, sort_buffer_size and read_buffer_size to higher values (they were 16Mb, 2MB, 125Kb; and I set to 64Mb, 4Mb, 1Mb as proposed by the link). I kept table_open_cache to 400 because I have about 330 tables in my DB.
Saddly, it didn't made any noticeable change in the response time... (almost 2sec to display a list of 10 users in a window). Were you thinking to other parameters ?

Quote from: gustagi on November 05, 2013, 02:34:39 am
For PHP 5.4 use apc cache.
For PHP 5.5 use Zend OPCache.

I use php 5.4. From what I can understand, using this means re-writting a great part of the source code, which is not an option.

Quote from: hwatari on November 05, 2013, 12:47:26 pm
Your problem is with OS running out of SD card, I had the same problem.
Now I'm running lubuntu on NAND and I installed MySQL with apt-get.
I installed 2.5" disk for database storage.
Hope this helps.

As I said, my next step is to move the OS on NAND. I want to keep the cubieboard alone (the goal is to have a standalone server that you can bring in your pocket to make a presentation of the app that is host inside), I don't want to add a SATA disk to it (even if I know that file transfers may be faster). I will keep you posted on this.

Quote from: milkboy007 on November 05, 2013, 03:38:33 pm
1. use better lightweigt app (lighhtpd, ngix, sqlite, etc...)
sqlite work well on sd card since its a single-file based database, unlike mysql's multiple file. IMO
google on the pros an con first to see it fit your need

2. better SDcard or move root to hdd.

3. lastly if you really line to know what's what, im assuming your skill are limited,
http://www.hackmysql.com/nontech
abit old but should work, and it can determine what are the slow queries.

I would prefer not to use 1 (to keep the same config that is used on production servers)
Thanks for the link in 3, I am working on using mysqlreport, I guess this will help me understand Patwood's advice.

What do you think of the option of creating a ramdisk to host the Php/js files ?

Thanks a lot for your help, I keep you posted on this.
Victor

gustagi

Just install (sudo apt-get install php-apc, when enable apc.so with php).
Your php source is same.


patwood

Quote from: victor on November 07, 2013, 06:17:02 am
Hi,
First, I would like to thank you all for your answers. I will try to give a proper response to everyone :)

Quote from: patwood on November 04, 2013, 03:18:30 pm
You can try setting some of the I/O flushing settings in mysql to see if that's what's slowing things down.  From what I've seen of sqlite, an update can cause lots of small writes and file system changes (create a new file, copy data to it, flush, unlink, rename).  Most SD card firmwares are not optimized for small data writes.

Thanks for the advice, but I don't really know which settings you are talking about... From what I read here, I tried to set  key_buffer_size, sort_buffer_size and read_buffer_size to higher values (they were 16Mb, 2MB, 125Kb; and I set to 64Mb, 4Mb, 1Mb as proposed by the link). I kept table_open_cache to 400 because I have about 330 tables in my DB.
Saddly, it didn't made any noticeable change in the response time... (almost 2sec to display a list of 10 users in a window). Were you thinking to other parameters ?


http://blog.monitis.com/index.php/2011/07/12/101-tips-to-mysql-tuning-and-optimization/
http://dev.mysql.com/doc/innodb/1.1/en/innodb-performance-adaptive_flushing.html

Quote
What do you think of the option of creating a ramdisk to host the Php/js files ?


The way the linux file system cache works, you'd only see slow loading of PHP/js files the first time they're used.  In essence, the file system cache works like a ramdisk for reads.  For writes, a ramdisk is better, as the data doesn't get written to non-volatile storage.  Databases (including sqlite) go to great lengths to make sure the data that's written out makes it all the way to the storage media and not just to a memory cache somewhere (including calling sync).  This is great for data robustness, but a pain when the DB files are on slow media, like SD.  Note that nand isn't much faster than a class 4 or 6 SD card (but might be better for smaller writes and random writes -- some SD cards are specifically designed for writing large, contiguous chunks of data, like jpegs and mpegs).