ZotonicMaking it fast!Zotonic & performanceErlang User Conference,Stockholm, June 14 2013Arjan Scherpenisse - arjan@miracl...
Lets make a website!
I have <? PHP ?>It is on this machine.Everyone uses it.So it must be good.Let’s use it... (and think later)
I use <? PHP ?>
I use <? PHP ?>
I use <? PHP ?>
What happened?I got mentioned on popular blogToo many PHP+Apache processesMelt down
I can use PHP!Of course you canUse more hardwareUse caching proxyUse xyz and a bit of abcAdd complexityAnd keep it a...
Same for RoR, Django...The problem is not that you can’t scaleThe problem is that you need to scaleimmediately
Yur site got /.ed!Many people followed popular linkA process per requestDeath by too many processes... doing the same ...
Most websites are...quite smalle.g. less than a million pagesexcept for a couple of huge onesnot visited that muche.g...
Thats why we are making Zotonic.
Zotonics goalsThe frontender is in the drivers seatReliable performanceA web server should easily handle the load of 99...
So, whats in the box?
So, whats in the box?Well, a lot :-P
So, whats in the box?Multiple sitesAdmin interfaceUser managementPage managementMenu editorCommentingImage manageme...
The request stack
Steps for a requestAcceptParseDispatch(match host, URL, controller)Render template(fetch data)Serve the result
Where is the time spent?Simple request: 7.5k/secTemplate rendering request: 10msLots of content: a lot less :pFetching...
What takes time?Fetch data from databaseSimple query roundtrip takes 1 – 10 msFetch data from caching serverNetwork ro...
What saves time?Dont repeat things that you could have done along time agoHTML escapingContent filtering(Zotonic store...
What saves time? pt IICombine similar (and especially simultaneous)actions into oneRequestsDB resultscalculations...
Where can we save timeClient-side cachingStatic filesTemplatesIn-memory caching
Client-sideLet client (and proxies) cache css, javascript,images etc.Combine css and javascript requests: http://exampl...
Static filesFile requests are easily cachedChecks on modification datesCache both compressed and uncompressedversionSti...
TemplatesDrive page renderingCompiled into Erlang byte codeUsing ErlyDTLForked; were merging it back
Template 101Hello, {{ m.rsc[123].title }}This is the id of your first image:{{ m.rsc[123].o.depiction[1] }}Search query:{%...
Template caching{% include “_template.tpl” maxage=100 %}and{% cache 3600 vary=z_language %}This gets cached per language f...
In-memory caching1) Memo cache in process dictionary of therequest process2) Central shared cache for the whole site(“depc...
Memo cacheIn process heap of request handlerQuick access to often used valuesResources, ACL checks etc.Flushed on writ...
DepcacheCentral cache per siteETS basedKey dependencies for consistencyGarbage collector threadSimple random eviction...
Erlang VM considerationsCheap processesExpensive data copying on messagesBinaries have their own heapString processing...
Erlang VM and ZotonicBig data structure, #context{}Do most work in a single processPrune #context{} when messagingz_co...
Aside: WebmachineWe created a fork, webZmachineNo dispatch list copyingNo PmodsMemo of some lookupsOptimizations (pro...
Slam dunk protectionHappens on startup, change of images,templates, memory cache flush etc.Let individual requests failB...
So, what about performance?http://www.techempower.com/benchmarks/
How important are these, really?JSON testSpit out “hello world” in jsonWhat are you testing?HTTP parsing?JSON encodin...
Platform x1000 req/secNode.js 27Cowboy 31Elli 38Zotonic 5.5Zotonic w/o logging 7.5Zotonic w/ dispatcher process pool 8.5So...
Techempower conclusionsWe can improve some stuffCompiled dispatch rule / host matchingMigrate to webserver that handles...
A recent project
KroonappelsNation-wide voting weekendClient requested 100% availability + highperformance100k “votes” in 1 hour3x Rack...
Kroonappels1 vote was about 30 requestsDynamic i18n HTMLAjaxStatic assetsLoad test needed adjustmentsDid not push to...
Kroonappels – made with ZynamoData layerDistribution ring based on Dynamo principlesConsistent hashing, work distributi...
Service oriented
Zynamos downsideHard...to maintain,to do cachingto write new stuffthere are DBMSs that can do this for usGot us thin...
What do we want?Multiple machines, but for error recoveryHardware errorsHardware upgradesHot failover
The P2P ideaTrusted P2P ring of collaborative ZotonicmachinesReliable messaging / notificationPoldercast P2P modelSync...
Thank you!Book chapter: “The performance of Open SourceApplications” coming out soon (http://www.aosabook.org/)…and chat...
Making it fast: Zotonic & Performance
Upcoming SlideShare
Loading in...5
×

Making it fast: Zotonic & Performance

7,624

Published on

Talk given at the Erlang User Conference, june 2013, Stockholm, about the performance of Zotonic, the Erlang Web Framework and CMS.

It highlights Zotonic's architecture, performance charts and provides a glimpse into the future of this web development framework.

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
7,624
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
0
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Making it fast: Zotonic & Performance

  1. 1. ZotonicMaking it fast!Zotonic & performanceErlang User Conference,Stockholm, June 14 2013Arjan Scherpenisse - arjan@miraclethings.nl
  2. 2. Lets make a website!
  3. 3. I have <? PHP ?>It is on this machine.Everyone uses it.So it must be good.Let’s use it... (and think later)
  4. 4. I use <? PHP ?>
  5. 5. I use <? PHP ?>
  6. 6. I use <? PHP ?>
  7. 7. What happened?I got mentioned on popular blogToo many PHP+Apache processesMelt down
  8. 8. I can use PHP!Of course you canUse more hardwareUse caching proxyUse xyz and a bit of abcAdd complexityAnd keep it all running, all the time
  9. 9. Same for RoR, Django...The problem is not that you can’t scaleThe problem is that you need to scaleimmediately
  10. 10. Yur site got /.ed!Many people followed popular linkA process per requestDeath by too many processes... doing the same thing!
  11. 11. Most websites are...quite smalle.g. less than a million pagesexcept for a couple of huge onesnot visited that muche.g. less than 10 pages per secondUnless linked to from popular placeRelative small set of “hot data”
  12. 12. Thats why we are making Zotonic.
  13. 13. Zotonics goalsThe frontender is in the drivers seatReliable performanceA web server should easily handle the load of 99% ofall web sitesMaximise the use of hardware, do more with lesshardware and less wattsSelf-contained, sysadmin friendlyNo external services, CDNs, caching servers,background workers.., and, no downtime
  14. 14. So, whats in the box?
  15. 15. So, whats in the box?Well, a lot :-P
  16. 16. So, whats in the box?Multiple sitesAdmin interfaceUser managementPage managementMenu editorCommentingImage managementVideo embeddingi18nE-mail sending,receiving (!)Importer modulesREST API…You name it, we(probably) got it :)
  17. 17. The request stack
  18. 18. Steps for a requestAcceptParseDispatch(match host, URL, controller)Render template(fetch data)Serve the result
  19. 19. Where is the time spent?Simple request: 7.5k/secTemplate rendering request: 10msLots of content: a lot less :pFetching data & rendering should be optimized
  20. 20. What takes time?Fetch data from databaseSimple query roundtrip takes 1 – 10 msFetch data from caching serverNetwork roundtrip = 0.5 msSo: do not hit the network or the database
  21. 21. What saves time?Dont repeat things that you could have done along time agoHTML escapingContent filtering(Zotonic stores sanitized / escaped content)
  22. 22. What saves time? pt IICombine similar (and especially simultaneous)actions into oneRequestsDB resultscalculations...
  23. 23. Where can we save timeClient-side cachingStatic filesTemplatesIn-memory caching
  24. 24. Client-sideLet client (and proxies) cache css, javascript,images etc.Combine css and javascript requests: http://example.org/lib/bootstrap/css/bootstrap~bootstrap-responsive~bootstrap-base-site~/css/jquery.loadmask~z.growl~z.modal~site~63523081976.css
  25. 25. Static filesFile requests are easily cachedChecks on modification datesCache both compressed and uncompressedversionStill access control checks for content (images,pdfs etc.)
  26. 26. TemplatesDrive page renderingCompiled into Erlang byte codeUsing ErlyDTLForked; were merging it back
  27. 27. Template 101Hello, {{ m.rsc[123].title }}This is the id of your first image:{{ m.rsc[123].o.depiction[1] }}Search query:{% for id in m.search[{query cat=person}] %}...Call the models – models responsible for cachingthose results
  28. 28. Template caching{% include “_template.tpl” maxage=100 %}and{% cache 3600 vary=z_language %}This gets cached per language for an hour{% endcache %}Whole and partial caching possibleMaxage in dispatch rules{page, [“hello”], controller_template,[{template, “hello.tpl”}, {maxage, 3600}]}
  29. 29. In-memory caching1) Memo cache in process dictionary of therequest process2) Central shared cache for the whole site(“depcache”)
  30. 30. Memo cacheIn process heap of request handlerQuick access to often used valuesResources, ACL checks etc.Flushed on writes and when growing too big
  31. 31. DepcacheCentral cache per siteETS basedKey dependencies for consistencyGarbage collector threadSimple random evictionSharing non-cached results between processesz_depcache:memo(fun() … end, 0, Context)
  32. 32. Erlang VM considerationsCheap processesExpensive data copying on messagesBinaries have their own heapString processing is expensive(as in any language)
  33. 33. Erlang VM and ZotonicBig data structure, #context{}Do most work in a single processPrune #context{} when messagingz_context:prune_for_{database, template, async}/1Messaging binaries is ok
  34. 34. Aside: WebmachineWe created a fork, webZmachineNo dispatch list copyingNo PmodsMemo of some lookupsOptimizations (process dictionary removal,combine data structures)Custom dispatcher (different way of treatingvhosts)
  35. 35. Slam dunk protectionHappens on startup, change of images,templates, memory cache flush etc.Let individual requests failBuild in artificial bottlenecksSingle template compiler processSingle image resize processMemo cache – share computationsmod_failwhaleMeasure system load, serve 503 page, retry-after
  36. 36. So, what about performance?http://www.techempower.com/benchmarks/
  37. 37. How important are these, really?JSON testSpit out “hello world” in jsonWhat are you testing?HTTP parsing?JSON encoding?Your TCP/IP stack?Well, OK, Zotonic does NOT do so well...
  38. 38. Platform x1000 req/secNode.js 27Cowboy 31Elli 38Zotonic 5.5Zotonic w/o logging 7.5Zotonic w/ dispatcher process pool 8.5Some numbersi7 quadcore M620 @ 2.67GHzwrk -c 3000 -t 3000 http://localhost:8080/json
  39. 39. Techempower conclusionsWe can improve some stuffCompiled dispatch rule / host matchingMigrate to webserver that handles binaries (Elli orCowboy)Merge Webzmachine ReqData/Context paramsCaching template timestamps – speedup freshnesscheckNot every framework implements the same test.Pose artificial restrictions on the tests?Zotonics memory-caching is fast...
  40. 40. A recent project
  41. 41. KroonappelsNation-wide voting weekendClient requested 100% availability + highperformance100k “votes” in 1 hour3x Rackspace VPS nodes, 2 GB, load balanced
  42. 42. Kroonappels1 vote was about 30 requestsDynamic i18n HTMLAjaxStatic assetsLoad test needed adjustmentsDid not push to the maxStopped at 500k votes / hr; 1.5M req/hrCustomer satisfied :-)
  43. 43. Kroonappels – made with ZynamoData layerDistribution ring based on Dynamo principlesConsistent hashing, work distributionService architecture w/ GET/PUT/DELETE semanticsLike riak_core without vnodes
  44. 44. Service oriented
  45. 45. Zynamos downsideHard...to maintain,to do cachingto write new stuffthere are DBMSs that can do this for usGot us thinking: Do we really need this scale?
  46. 46. What do we want?Multiple machines, but for error recoveryHardware errorsHardware upgradesHot failover
  47. 47. The P2P ideaTrusted P2P ring of collaborative ZotonicmachinesReliable messaging / notificationPoldercast P2P modelSynced database backups / assetsBittorrent protocol for large filesWAL for db deltasSites are vertical, data silosRun our own DNS?
  48. 48. Thank you!Book chapter: “The performance of Open SourceApplications” coming out soon (http://www.aosabook.org/)…and chat with me & Andreas :-)Come get a tshirt!Online resources:http://zotonic.com@zotonic - http://twitter.com/zotonicIRC, XMPP, mailing listsTalk slides, tutorial slides, tutorial source code...

×