加速Plone之降龙十八掌——之一

加速Plone之降龙十八掌——之一
本帖最后由 adam(三人行) 于 2011-9-3 14:50 编辑

[align=center][size=6]Overview[/size][/align][align=left]
● Big Picture
– The Problem: Plone is slow
– The Solution: CacheFu
● How does CacheFu work?
– Key concepts
– Gory details
● Squid
How fast is your site?
● Simplest measurement: Apache benchmark (ab)
– comes with Apache 2.0 distribution
– simulates lots of users hitting a single page sequentially and / or simultaneously
– measures pages served / second
● Limitations of ab
– doesn't load associated images, CSS, JS
● JS and CSS matter a lot! ~50% of your bandwidth
– doesn't know about browser caching, etc
● Better benchmarks feasible with Selenium??
How fast is Plone out of the box?
● ab = Apache benchmark
– part of the Apache 2.0 distribution
● ab -n 50 http://localhost:8080/myplonesite/
– 50 requests for front page
– Key number to look for is “Requests per second:” (average; median is better)
Using ab
● Tips:
– Make sure you add the trailing “/” to the URL
– Be sure your site has “warmed up” before running
● Lots of one-time startup expenses
–ZODB needs to load objects into memory
–pages templates need to be parsed, etc
● Run twice and look only at second result
– Make sure Zope is not in debug mode
Results
● ~3.5 requests/sec on my laptop
– SLOW!
● Front page is only part of the problem:
– also have ~200K of CSS / JS / images!
● Quick tip: If you have an English-only site, delete PlacelessTranslationService
– Boosts speed to 4 req/sec (~15%)
CacheFu
● Download CacheFu
– Copy 4 packages to my Products directory:
● CacheSetup
● PageCacheManager
● PolicyHTTPCacheManager
● CMFSquidTool
– Install CacheSetup with QuickInstaller
● Repeat the ab test:
– Get ~35 req/second
– ~10x faster; also improves JS, CSS, and images
CacheFu + squid
● Set up squid
– Install squid
– Set up the squid.conf that ships with CacheFu
– Adjust squid settings in the cache settings portlet
● Run ab again
– Get 150 req/sec
– ~40x faster
Transparency
● CacheFu is almost completely transparent
– CacheFu caches content views (not everything)
– Big problem: cache needs to be purged when content changes
– CacheFu takes care of this for you
● When you update your content, changes will appear on your site immediately!
– A few exceptions; we will discuss these
– Need to understand how things work to make this work for you
– Very straightforward in most cases
How does CacheFu work?
● CacheFu is pretty complicated
– Ideas are straightforward
– Infrastructure in Zope for implementing them is not
– Lots of partial solutions that step on each other
– Biggest value-add: (relatively) seamless integration
● Not a perfect solution
● Hopefully will provide a better way to think about the problem in Zope 3
Why is Plone slow?
● Multiple sources
● In order of decreasing importance:
– Page rendering
– ZServer
– Network latency
– Connection setup times
● We will attack each problem separately
– Multiple approaches to some problems
Speeding things up
● Page Rendering
– Lots of benchmarking
– Biggest time sink is TAL rendering
– Not much we can do about it
– EXCEPT not render
● Cache pages to reduce rendering time
– Several different ways
Speeding things up
● ZServer sluggishness
– Don't use ZServer when we don't have to
● ZServer is smart
– Don't need brains to serve up static content
● Set up fast proxy cache (squid)
– Proxy cache handles static stuff
– ZServer handles things that require some smarts Speeding things up
● Network latency
– Tell browsers not to ask for things they don't need
● Caching!
– Don't re-send pages when you don't have to
● More caching!
– Compress content
● gzip HTML pages
● JS / CSS whitespace removal related tricks Speeding things up
● Connection setup times
– Combine multiple CSS files into one
– Combine multiple JS files into one
– Prevent unnecessary requests
● Cache as much as possible (but no more) in the client
Caching, Caching, and more
Caching
● Common theme in all approaches: Cache!
● Several different types of caching
– Cache in server memory
– Cache in proxy cache
– Cache in client's browser
● “Unconditional” client-side caching
– Browser always uses local file
● “Conditional” client-side caching (NEW!)
– Browser checks with server before using local file
[/align]
设置