Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Performance optimization for a TYPO3 website
1. Performance optimization for a
TYPO3 website
Alexandre Gravel-Raymond, Web developer
a.gravel-raymond@alienor.net
Aliénor.net : Bordeaux based Web agency
2. Plan
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
3. Enterprise level solution
Multilingual, multidomain websites
Workflows
Powerful user rights management
Great importance given to retro-compatibility
More than 4000 extensions on the TYPO3 Extension
Repository (TER)
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
4. Typoscript
Tree-based configuration langage (forming templates)
No functions (but references to PHP functions)
No variable (but the possibility to use a registry for
information exchange between parts of the template)
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
5. Criticism about TYPO3
End user: The website seems slow.
Sys admin: The server load can be important on complex
websites.
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
7. Solutions to the
performance issues
Three main reflexion areas:
Code optimization: of course !
Make the application lighter: not at the expense of
flexibility !
Fine-grained cache : this is the way.
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
8. Standard cache
TypoScript objects composing a template fits in two
categories :
Cacheable objects (USER plugins, TEXT objects,
Content Object Array - COA, etc.)
Dynamic (non-cacheable) objects (USER_INT plugins,
dynamic Content Object Array - COA_INT)
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
9. When the requested page is
not cached yet
Standard (cached) typoscript objects are rendered
Dynamic (_INT) typoscript objects are replaced by specially
crafted tags (<!--INT_SCRIPT … >)
The result is stored in the cache system (usally the database)
A second rendering phase replaces the tags by the
corresponding objects' HTML representation
The final document is sent to the user
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
10. When the requested page is
in cache
The cached representation of the page is pulled from the
cache system
Tags representing dynamic objects are replaced by the
objects' HTML representation
The final document is sent to the user
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
11. Limits of the cache system
Every request, including those concerning already
cached pages, force the web server to execute
TYPO3.
It is (very) resource-intensive
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
13. Alternative solution :
nc_staticfilecache
Extension developed by Netcreators
Some benchmarks show a page delivery speed
multiplication by 230 !
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
14. nc_staticfilecache extension
Stores the final document in a static HTML file
This file (if it is present) is directly delivered by the web
server
PHP and TYPO3 are not loaded at all !
If the static cache is not found, the standard rendering
process is executed
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
15. nc_staticfilecache advantages
Follows standard TYPO3 cache rules (ex: if the cached version of a
page has expired, the corresponding static file is deleted
Possibility to extend static cache delivery rules in a .htaccess file :
Ex : Cookie identifying users that must have a dynamic version
of the website
Possibility to deactivate the static cache on a page-by-page basis
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
16. Installing nc_staticfilecache
Apache and mod_rewrite are needed
Download and install the extension :
http://forge.typo3.org/projects/extension-nc_staticfilecache
Add basic rewrite rules given in the example .htaccess file
Add a cronjob that points to the script that cleans expired
static files (via scheduler)
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
17. nc_staticfilecache constraints
POST requests are excluded (to maintain the dynamic
nature of the forms)
All GET parameters must be rewritten on statically cached
pages (with realurl or cooluri extensions)
No page containing dynamic (_INT) objects will have static
cache
One solution to have a dynamic page : make the _INT
object static, and use AJAX to render the « personalized »
content (use with caution)
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
18. Architectural solutions
Use Nginx as a reverse proxy to deliver static files
(lighter and quicker than Apache)
Use eAccelerator or another PHP op-code cache
system to boost PHP performance for dynamic pages
and for the first hits of static pages
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
19. For dynamic plugins
When the standard cache system doesn't help and
nc_staticfilecache doesn't apply
Use an alternate cache system
Memcached is a « high-performance, distributed
memory object caching system » that can help override
bottlenecks in an application.
Since TYPO3 4.3, you can define an alternate cache
backend (file or memcached instead of database)
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
20. Further optimization : reduce the
number of HTTP requests
CSS and JS fusion / minification tools (TYPO3 extensions)
scriptmerger: extensive configuration, possibility to
exclude individual files
load_optimization: HTML compression, only files added
via typoscript are processed
js_css_optimizer: uses the new page rendering API, fine-
grained configuration file by file
Minify: easy to install and use
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
22. Good practice #1
Do not deactivate the cache ! When you have cache
problems, refrain from doing this :
www.example.com/?no_cache=1
$GLOBALS[‘TSFE’]->set_no_cache() ;
config.no_cache = 1 (typoscript template)
« No cache » checkbox in backend in the page properties form
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
23. Good practice #2
Adapt the cache duration to the project
Ex: At least one day for a typical publication website
Make TYPO3 clear the cache of affected pages
automatically when needed
In page TSConfig : TCEMAIN.clearCacheCmd = 1,2,3
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
24. Good practice #3
Audit the extensions you use
With the help of the community…
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
25. Good practice #4
Uninstall unused extensions (they can load typoscript
or PHP), even if an autoloading mecanism was
introduced in TYPO3 4.3
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
26. Good practice #5
Lessen the complexity of the typoscript templates
It is possible to accomplish very complex tasks in pure
typoscript, but sometimes it's more clear to encapsulate
the functionnality in a specialized PHP class, and you
get more speed at the same time.
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
27. Good practice #6
For parts of the website that don't need it, do not use the
full TYPO3 rendering mecanism
AJAX script can be externalized with the eID
method :
www.example.com/index.php?eID=ajax_script
Only loads necessary parts of TYPO3 core
Do 404 error pages need to be dynamic ? Prefer the
standard ErrorDocument method.
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions
28. Good practice #7
Optimize SQL tables added by your extensions with
well chosen indices, notably if it was automatically
created with the Kickstarter
I – TYPO3 presentation
II - Performance and limits of standard rendering
III - Solutions