In my application development, we have a ZFDebug installed. It displays benchmark results such as load times and memory usage in a toolbar, which I find quite useful.
On average my application uses about 19000k of memory.
The application uses Doctrine 2 and DQL to create profile and home page feed results. When the results are populated, memory usage could go up to 22000k of memory.
The application also has a complex modular structure of loading resources such as javascript libraries, and other external libraries using plugins.
As far as it goes we haven’t implemented Zend_Cache yet for optimization.
I’m a little bit confused about how to approach application optimization using these benchmark results. How am I supposed to judge whether the memory usage is acceptable or not? What is the typical zend framework application memory usage for instance?
Oh good old times. That was my problem too.
I’m using ZF since 2007. Memory Usage was always a problem for ZF. 16-17M is “normal” for simple MVC in ZF. If you add Doctrine, it goes up to 20M – like you said.
First of all, install APC on your server. This is the most important thing because it speeds up everything even in it’s default settings. Measure the page load times. After APC, you will at least gain 30% performance.
After that use Zend_Cache with APC backend. Doctrine allows caching for queries, results and hydration. Use them with APC too.
I see you are using ZFDebug. Profile Doctrine queries and optimize them too. Add indexes where appropriate.
I’m always on the “manageability over performance” side. Yes, ZF is slow. Yes, Doctrine makes it slower. But the size of my project requires using frameworks and ORMs and dependency injection containers ETC. All these things give me ability to rapidly develop projects.
I’m the developer of Gazi University web page. Since the last year, i tried to convert the static web page to a CMS for ALL of our academic and administrative units. For example iibf.gazi.edu.tr and bidb.gazi.edu.tr uses the same template, same CMS and same DB but all sites have their own subdomain.
Oh boy, the day the site went “live” i was dying. The page load time was 15 seconds. 15 seconds. Google Webmaster Tools said i was slower then the whole internet. Everyone got timeouts. All cores of the VM was working at 100%. I couldn’t even SSH into the machine!
The every piece on the page can be controlled via the CMS admin interface (if you could login into admin area :D). The blue menu on the top? From CMS. News? From CMS. Announcements? From CMS. Quick Links area? From CMS. Quick Links with icons? From CMS. Even the twitter/facebook/youtube links are coming from DB because every department’s links are different.
And the real weird part? I was using caching! I was caching every part i counted in previous paragraph.
Now? Google Analytics Site Speed graph is flat on 1.5s. Google Webmaster Tools says i’m faster than 91% of the sites on the internet. And the site has 60k daily visitors.
Here is the list of some things you can do. But don’t do everything at once. Do one thing. Measure new metrics and iterate:
Profile your page. See what code slows down the page. Use Xdebug and CacheGrind. For example if you are using Zend View partials… just don’t use it. Use $this->render(). But you can’t know what is slowing you down until you measure it. Do the profiling!
Use Opcode caching. As i said APC is cool for opcode caching. Optimize it. For example, disable apc.stat setting and it will speed up more. (stat checks if a file is changed since it’s first caching but it requires disk seeks and slows down things. If you disable this setting, things will speed up. But you have to restart PHP after you change a PHP file)
Database is the another slow thing. Cache the result set. Nobody cares if a news item shows up with 1min delay after inserting into database. Believe me even 1min caching will makes difference.
Use a CDN or at least configure your web server to set expiring times +1year for static content. And remove the Session ID from static contents. +1 year for static content is necessary. Do it. For example we have a 620×327 jpg banner and it’s the %20 of our total page weight.
Learn settings of your web stack. Configure MySQL, Apache, PHP, PHP-FPM, Apache, Nginx or whatever you use. But change one setting a time and test it at least 100 times. Some settings doesn’t create problems on first refresh.
Trace your metrics. Use strace, top, iostat, vmstat, htop or whatever. If mysql is always always using CPU cycles it means you are not caching query results.
Remove unused modules: Remove the !#@$ LDAP module! You are not gone use it. If you need to use it one day, it one “apt-get”, “yun install” away.
Your home page is the most important thing. True story: Our homepage gets 2 million monthly views. The next most visited page gets just 420k. Use “full page caching” for your home page. But don’t forget you can’t invalidate full-page cache because it’s URL based and doesn’t even touch your MVC stack. As i said before, cache it for 1minute. Even 1 minute makes a huge difference for high-traffic sites.
Push as much work as you can to client’s computer. Google doesn’t care about 620×327 px jpg of our medical school’s lab. Even our visitors doesn’t care. Load them after page load with AJAX.
That’s all i can remember from my experiences.