NOTICE. New version available. Now you can use evo_nginx_boost without nginx. You need ony TYPO3 and memcache. New manual of evo_nginx_boost - techblog.evo.pl/en/evo_nginx_boost-extension/
TYPO3 cache
The TYPO3 performance issue is often a subject of discussion. I found a number of various tricks, which can speed up the page generation time, including nc_staticfilecache and dmc_highperformance modules. The latest alpha version of TYPO3 contains radical changes in the caching mechanism, enabling us to choose from various support functions, such as file, memcache, database or apc.
Problem
All of the above solutions, with the exception of nc_staticfilecache, have one thing in common: in order to read cache, one has to invoke a php process, read and parse the cached data, and then send the information to the browser.
Let’s perform a simple test using the ab tool. We will check the number of queries per second for a complex Web
ab -n 100 -c 1 <a href="http://localhost/" >localhost</a> Server Software: Apache/2.2.6 Server Hostname: localhost Server Port: 80 Total transferred: 5064709 bytes HTML transferred: 5031914 bytes Requests per second: 1.02 [#/sec] (mean) Transfer rate: 50.66 [Kbytes/sec] received
The number of request per second amounts to 1.02!
What if our site has to support a thousand of such queries every second? Even with the most efficient caching mechanism, each PHP parser call will result in very heavy server load.
Nginx
The NGINX proxy server can help us with this problem. While not a completely new solution, a clever combination of this proxy and TYPO3 can result in a two hundred-fold performance increase! The solution I’m describing will support traffic for logged in and guest users, can take into account any Web site changes implemented upon user login, as well as support various TYPO3 cache settings.
This is how it looks on diagram:
The user requests a page. Nginx checks the user’s cookie. If we set a cookie named nginx_boost_noCache, the query is sent directly to the Apache server and then to TYPO3, bypassing the memchache entirely. Thus, the cookie allows for easy control of memcache caching mechanism, providing the ability to turn the mechanism off unconditionally in specific situations. This can be implemented in any plugin present in our system. An excerpt from the nginx config file used to support this situation is presented below.
if ($http_cookie ~* "nginx_boost_noCache=1") { proxy_pass <a href="http://domain" >domain</a>; break; }
If nginx cannot find the nginx_boost_noCache cookie, it will check for a cached page in memcache. $request_uri is used as a search key.
# set default memcache key set $memcached_key $request_uri; # Check if local memcached server can answer this request default_type text/html; memcached_pass 192.168.168.3:11211;
If our page is not present in the memcache, nginx will again send a query to the Apache server. Apache, in turn, invokes TYPO3, generates the page, and evo_nginx_boost writes this page to the memcache, using the requested url for the memcache_key.
$memcache_key = "domain/about-us"
Each subseqent request for this page will be sent directly from the memcache, without the need to run the PHP process again.
Our plug-in fully supports TYPO3 caching times for each party, as well as the cache_period value. If the caching time value is not set in TYPO3, we will be using a default value set in the plug-in’s configuration file.
What if the user logs in?
It all depends on what we do. Using nginx and evo_nxginx_boost, we can completely disable caching for logged in users. However, while analysing our needs and web page statistics, we have come to the conclusion that logged in users often read - and return to - the same pages. A change must be made when the user sends a POST request, i.e.: writes a comment or a blog article. In this situation, will be using the hook in the class.tslib_fe.php – initFEuser class.
If the user logs in, we set the nginx_boost_fe_user cookie to the value of the fe_typo_user cookie.
$memcache_key = "domain/blogs/us1b27c2c23bdb600912561e08a7e4886b"
Upon receiving a POST or another operation which requires content refresh, we add versions to this value. The evon_nginx_boost plugin then writes a new version of the page to the memcache.
$memcache_key = "domain/blogs/us1b27c2c23bdb600912561e08a7e4886b_1"
After a five minute period, this version of the page will expire and nginx will send a new request to Apache and Typo3. If another user adds a comment to the blog at this time, we will see it in 5 minutes.
It would also be advisable to set short caching times to pages with quickly-chanigng content. In a social website under a heavy load, we remove the page from cache in 1 to 5 minutes, which gives us the ability to support heavy traffic.
Now to perform ab tests of the above solution.
ab -n 100 -c 1 <a href="http://localhost/" >localhost</a> Server Software: nginx/0.6.35 Server Hostname: localhost Server Port: 80 Total transferred: 10103800 bytes HTML transferred: 10089200 bytes Requests per second: 400.05 [#/sec] (mean) Transfer rate: 39468.58 [Kbytes/sec] received
The number of request per second is 400.05!
evo_nginx_boost configuration description
Property: | Data type: | Description: | Default: |
|---|---|---|---|
enable | string | enable disable memcaching | 1 |
forceTimeoutToAllPages | int | set default memcache expiration time (has priority over TYPO3 setting) | 0 |
disableCacheForLoogedUsers | int | enable/disable memcaching for logged users | 0 |
cleanOnClearAllCache | int | if set, memcache is cleared when backend user click clear cache | |
setPageCacheTimeout OverrideAllTypoSettings | int | if you enable this option, you can override all expires time from your user_int extension, fg if you have page with four extensions and each extension calls static function: if (method_exists('tx_evo_nginx_boost', 'setPageCacheTimeout') tx_evo_nginx_boost::setPageCacheTimeout($timeout); evo_nginx_boost set expire time to the lowest value set in all 4 plugins | 1 |
_mainServerIP | string | memcache server ip | |
_mainServerPort | string | memcache server port | |
_mainServerPersistent | int | enable persistant connection | 1 |
_mainServerTimeout | string | memcache server connection timeout | 1 |
memcacheSignature | int | add signature to end o pages | 1 |
memcacheSignatureText | string | text of signature fg "CACHED BY ME :)". If you set memcacheSignature = 1 time of expiration is added to the end of memcacheSignatureText | 1 |
excludedUrls | array | Set in ext_localconf. This is array of urls which should be excluded from memcaching. Let say you have confirmation message after successfuly saving post in user's blog. Page with message "your post was saved" will be memcached. You can add parameter message=1 and put this in array. Evo_nginx_boost exclude this url from memcaching. | 1 |
The plugin is also equipped with a BE module, which allows us to monitor all parameters related to the memcache server. The cachedump option allows for viewing saved web pages and their assigned memcache keys:
The solution was tested on a very complex Web site with a large number of USER and USER_INT extensions. Comments are suggestions are very welcome.
Download files:
- nginx configuration file nginx.conf
- typo3 extension evo_ngix_boost
- the nginx server can be downloaded at nginx.net
Please note:
The versions of nginx available through apt-get in Ubuntu 8.04.1 exhibits an error.
Bugfix: a segmentation fault occurred in worker process, if the “memcached_pass” and “if” directives were used in the same location.
If nginx and apache are run on separate machines, remember to match their date/time values. :)



Latest comments
Daniel
I get a fatal error with this extension: Fatal error: Call to undefined method t3lib_div::makeInsta... / 07 May. 20:53
Zaawansowana subskrypcja, nasze nowe rozszerzenie
Michael
The correct Amazon S3 API TER link is http://typo3.org/extensions/repository/view/amazon-s3-api T... / 24 Apr. 11:44
s3example - TYPO3 i Amazon S3
Adi
Pod nową wersją t3 z gałęzi 4.5.14 (gdzie w korze znalazły się jakieś krytyczne luki) wtyczka też ni... / 02 Apr. 19:52
Zaawansowana subskrypcja, nasze nowe rozszerzenie
Rafał Brzeski
Nasze niedopatrzenie, w nowej wersji dodamy opcję wyboru tej opcji. / 21 Mar. 20:22
Zaawansowana subskrypcja, nasze nowe rozszerzenie
bocianos
Wszystko super tylko jak zrobic aby nowe adresy domyslnie miały zaznaczone otrzymywani maili w forma... / 20 Mar. 13:08
Zaawansowana subskrypcja, nasze nowe rozszerzenie