Peformance tuning at BaseKit
Who am I?
Co-organizer of PHPSW
@adeslade
Work here at BaseKit! We're hiring.
jobs@basekit.com
What is BaseKit?
Website editor
Live (brief) demo... what could possibly go wrong?
Technologies
Redis
Memcached
MySQL
Apache
PHP
HAProxy
Varnish ... :)
Plus more I've forgotten...
Platform
REST API
Editor
Environment management control panel
Site management
User account management
Some of the ways we reduce response times
Varnish
The star of the show
What is Varnish?
Varnish Cache
Web application accelerator
or
a caching HTTP reverse proxy
All of our HTTP requests go through Varnish
Sits in front of Apache
VCL determines what is cached
Not everything is cached (not everything is suitable)
Why we love Varnish...
-
Very fast
- Highly flexible configuration language (VCL)
...
Varnish helps primarily to:
- Serve all the published sites quickly
- Serve assets quickly
- Including dynamically resized images
- Dynamically generated combined asset files - Assetic
- Translations
CDN?
Only used on a handful of environments
Reducing the number of API calls
Sending multiple API requests at once
Trivially easy to do using Guzzle
Or you can use the curl_multi_* functions yourself (good luck!)
Caching API responses
...
Stale responses are unacceptable for the most part
:(
Proactive cache invalidation
So we proactively invalidate the cache when data is changed
Key prefixes
An example:
Keys:
foo.bar
foo.bar.baz
To invalidate both keys and cause the data to be loaded again:
delete foo.bar
delete foo.bar.baz
Or...
Keys:
prefix = 1234
1234:foo.bar
1234:foo.bar.baz
By changing the prefix the keys become:
prefix = 2345
2345:foo.bar
2345:foo.bar.baz
Queueing
We use redis and supervisord to achieve this
Potentially more fragile so requires logging and monitoring
CDN
Using someone else's infrastructure to serve assets
Cloudfront
Use custom origins and Cloudfront with S3
Assetic
Library used to combine assets
Assets to load are specified in Twig templates
Asset versioning
Include version in URL
Unique asset URLs between deployments
On deployment version is changed
Dynamic asset versioning
Translations
For those assets which are updated between deployments
These are given hashes from memcache
Unique URL
Caching headers
As many assets as possible cached in the browser for a long time
Network console in the browser is your friend
Profile
Very important to discover what the actual slow parts are of our applications
Sometimes surprising
XHProf
Questions?
Scaling at basekit
By adeslade
Scaling at basekit
- 3,996