2

I'm running a web server on my pi at the moment, I run a forum that uses PHP and Mysql. The Average load time is 1 – 2 seconds for a page, I know for sure this can be a lot faster. This is because when I request a HTML page it's there in a few milliseconds (We have Fiber Optic Internet with 40Mbit upload speed).

I would like to know what I can do to make it even faster, there are no slow query's detected and Mysql caches have enough space. So I guess Mysql is not the problem. I also optimized Apache a bit, but I actual don't know what I could do to make it even faster.

So what tools are available on Debian to determine what the systems bottleneck is? And are there any tools like “Mysql tuner” for PHP?

When I run the command “top”, there is max 40% CPU and 50% ram usage when a user is browsing. So I guess more CPU power can be used to process data faster. I don't know about Disk usage, but I have a class 10 SD card that I want to keep. So I don't want to expand the SD card.

I know it's better to optimize the applications on the server, but first I would like to have Apache, PHP and Mysql as fast as possible for my system configuration.

Laurence
  • 365
  • 1
  • 4
  • 14

3 Answers3

2

The usual way to speed up the delivery of dynamic web pages (no matter on what kind of server) would be server-side caching.

Instead of running the PHP code and the database queries on every page request, you can save the resulting HTML as a static page and deliver it on subsequent requests. It would have to be updated only when there is a new post in your forum.

There are plenty of resources and tools available for this, one very powerful and popular choice is Varnish:

Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents. Varnish Cache is really, really fast. It typically speeds up delivery with a factor of 300 - 1000x, depending on your architecture.

Varnish is included in the Debian sources, their website has detailed documentation on setting it up.

Basically it sits between your user and Apache. Its usefulness depends heavily on your forum App sending the correct cache headers with its HTTP responses, so expect some tweaking and research to be necessary.

pixelistik
  • 121
  • 2
  • Its not really a solution, look at this link: https://www.varnish-cache.org/lists/pipermail/varnish-misc/2010-October/019259.html "The only real potential for caching vBulletin pages is for guests. Logged-in members are much more difficult to handle." My forum is a private form, so it's not very usefull. – Laurence Nov 27 '12 at 14:56
1

To be honest, a load time of 1-2 seconds for a PHP based forum page isn't unusual, no matter what hardware you're running on. Static pages will be coming from memory cache pretty much, where-as dynamic pages just require time to process and build. Depending on the PHP application (i.e. the forum app) it may be possible to turn on per-page diagnostics which detail where time was spent building the page.

EightBitTony
  • 111
  • 3
  • On my own pc it loads in a few MS. I reinstalled my PI and overclocked it to 1 GHZ, all my Apache configurations are rested. Now it will use around the 70% CPU. I guess that the problem is the calculating part. PHP is not a good performance language, so I guess that I need to program a new forum in C++ if I want to get better performance. – Laurence Nov 27 '12 at 15:03
  • On your own PC there's no network latency involved or any number of other issues, and there's a single user. You're not comparing like for like even before you talk about the massive performance difference between your PC and your Pi. The Pi performs at roughly the same level as a 300MHz Pentium 2. – EightBitTony Nov 27 '12 at 15:15
  • That is correct, but I also tested my PC as host from the outside, that was a lot faster. I don't want the same speed as my PC, but a little faster would be handy. Its good enough now, I didn’t suspect that the PI was as fast as it is, but it's fun to optimize it even more. So, the real bottleneck from the PI is the processor, to avoid this you need to cache data so that the processor doesn't need to do much work. – Laurence Nov 28 '12 at 07:59
0

So, the real bottleneck from the PI is the processor, to avoid this you need to cache data so that the processor doesn't need to do much work. It's not possible to do this with a 3th party caching tool because there is not much same data. So you need to implement caching on your own. I like to program software, its a hobby of mine for more than 6 years. So that is how I'm going to solve the problem.

So the short answer is, no, you can't get it much faster with some tweaks, but there is an other way. You could make your own forum for the PI in service style. A real time program that handles the engine in for example C++, this way you don't need to calculate everything over and over again, and you can manage cache data when there is no one on your forum.

When you need Apache to run other software, you could let Apache send the requests to the service, but you also can make a manager that send it to Apache or the Forum.

To make it fast, you can keep a lot of information that is in the database in memory, for example 50 MB of forum posts, and the forum overview. But make sure it's easy to update. Keep this in an arrays for example, this way you can easily update elements when something is changed (Don't forget to apply the updates in your database!).

50 MB is really a lot of text. That way the PI can just copy the most out of memory, that way it will preform very fast. And because you do the caching yourself, you know what you can show to every user, so you don't need to cache data for every single situation.

I never implemented something like this, but I’m sure you could make very good caching solutions for a Forum.

Laurence
  • 365
  • 1
  • 4
  • 14