3

Well, to be specific, I'm running my own content management system running on Linux Apache2 MySQL PHP server. The system is comparable to Linux kernel w/ modules.

--(request start)--

The system launches his "init" script that takes care of dependency-based module loading (only minimum modules are loaded, in proper order, so it "just works", but nothing else (disabled/unused modules are not loaded)).

Once the system is ready, request processing comes in - all the data gets loaded, parsed, processed, buffered, chewed and so on, until we have a complete (x)HTML page.

--(request end)--

Once the request is processed, the data are passed to browser and the system is killed. All this happens in a very short time, but the most cpu-intensive is the beginning part (preparating system for use).


I have a few options:

  1. Let system be in a way it's now (and risk performance issues after it's deployed for REAL usage (approx. 100-500 requests/s per system))
  2. Do some kind of preloading (preparing the system manually and not let anything magic happen then)
  3. Find a way to keep the system in ready-for-use state (all modules loaded, classes initialized, ready MySQL link, etc.)

Question is:

  • Is there a way to accomplish point 3? (point 2 is what I want the least)
  • If it's possible, how?

Thanks for any advices that'll point me right way!

lmojzis
  • 551
  • 7
  • 17
  • Do you want to keep one process per user / session? This seems to be a very bad idea, because it would have a huge hit on memory usage even if there is some CPU gain. You may want to try a PHP accelerator, like APC or Zend Optimizer, first, to cache the precompiled PHP bytecode. – Philippe Plantier Aug 15 '11 at 21:50

2 Answers2

1

Probably what you need is PHP APC, eAccelerator or some other extension that parses your code and keeps it as byte-code in the memory, which for CPU hungry situations can help your performance a LOT. It seems that you have the knowledge to setup such extension, I would recommend you the "APC" being the most used and tested one out there:

http://en.wikipedia.org/wiki/List_of_PHP_accelerators

Edit: For MySQL I would go with using "persistent connection" which might help as well.

ddinchev
  • 33,683
  • 28
  • 88
  • 133
  • Or he can cache the html page and refresh the cache after he updates with new information. That way he has the page already and the load is reduced. – Vince V. Aug 15 '11 at 21:52
  • That is correct, though I doubt he is using CGI/FastCGI anyway :) – ddinchev Aug 15 '11 at 21:52
  • 2
    @Vince, I generally do not like caching. Caching basically means you have more then one truth (cached content and real content) and you should have mechanism to invalidate the cache when the real content changes, which in the long run could be a pain. But of course, if we are talking a system that would take hundreds of requests per second, most logical approach is to cache the content for given URL as plain HTML and serve that instead and rebuild the HTML when content changes. – ddinchev Aug 15 '11 at 21:56
  • @Veseliq, how can you say you generally don't like caching, but suggest to use byte-code caches like APC? – wonk0 Aug 15 '11 at 21:58
  • @wonk0 there is a big difference - some theory: running the same script over and over again for N times would result in the very same byte code (if the compiler version doesn't change, etc). But if for example you CACHE a page as plain HTML, and the content for this page comes from DB, every time you change the content in the DB, you have to flush your cache (or else the user will keep seeing the old thing until the cache expires or is deleted by hand). And also as far as I remember, APC handles file changes well - if the file changes its parsed again. So its just different. – ddinchev Aug 15 '11 at 22:05
  • @Veseliq, I cannot see a difference there. You have some source (which is a PHP script in case of APC, which might be DB data in case of caching HTML), and whenever the source changes you have to flush your cache, Where is the big difference? Yes, APC does that for you, you don't have to care for it. But any (self-made) caching should do the same. – wonk0 Aug 16 '11 at 03:14
  • Should do and actually doing it is not the same thing. While APC is stable enough to do what it's intended to do, doing yourself cache implementations is a whole different story. Also doing caching in complex CMS whould mean you have mechanisms to cache 1) whole pages 2) specific heavy db queries 3) fragments of pages. For each place caching is implemented you will have to implement cache invalidation when the content behind it changes. I speak from experience that for big projects this leads to bugs/problems (although sometimes its absolutely necessary). While APC - its just there, and works. – ddinchev Aug 16 '11 at 06:37
  • 1
    Programming towards solving such problems is called "technical masturbation". If you can get away by implementing a module in 1 hour or buy an SSD to solve query problems caused by slow disk seek or get a better server with better cpu - then do that. Money and open source is always better then programming, because usually in such situations its cheaper how much an SSD costs, how much your time does? Also it's less likely to lead to bugs and other time wasting problems. Implementing CMS caching is not an overnight thing and I would try to avoid it at all costs if not absolutely necessary. – ddinchev Aug 16 '11 at 06:42
  • Hi there. Just bringing up this post to say I'm halfway done and I've not yet implemented the caching. If a page is executing 50ms from first line to the last one, is it a good time or is there something wrong? My server's specs are: 2×IntelXeon @ 2 GHz w/ 2 threads/CPU (4 threads total) 3 GiB RAM DDR RAID1 (HW) 500GB @ 5400 RPM Linux alpha 2.6.32-35-generic-pae #78-Ubuntu SMP Tue Oct 11 17:01:12 UTC 2011 i686 GNU/Linux – lmojzis Nov 20 '11 at 23:30
0

You may Want to compile your Php into a c++ Or Java and gain performance by sacrifice a little Bit go check the wikipedia for more info's HipHop

Qchmqs
  • 1,803
  • 2
  • 20
  • 29
  • HipHop is plain C and it should be noted that it can't be used in case you use "eval" somewhere and there are other problems connected to it. HipHop won't give you much more than PHP APC and tend to be much bigger trouble to use (while APC works transparently for you, with HipHop you have to recompile your project every time you push a release). – ddinchev Aug 15 '11 at 21:59