Your SlideShare is downloading. ×
Making it fast: Zotonic & Performance
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Making it fast: Zotonic & Performance


Published on

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

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

  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. ZotonicMaking it fast!Zotonic & performanceErlang User Conference,Stockholm, June 14 2013Arjan Scherpenisse -
  • 2. Lets make a website!
  • 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. I use <? PHP ?>
  • 5. I use <? PHP ?>
  • 6. I use <? PHP ?>
  • 7. What happened?I got mentioned on popular blogToo many PHP+Apache processesMelt down
  • 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. Same for RoR, Django...The problem is not that you can’t scaleThe problem is that you need to scaleimmediately
  • 10. Yur site got /.ed!Many people followed popular linkA process per requestDeath by too many processes... doing the same thing!
  • 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. Thats why we are making Zotonic.
  • 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. So, whats in the box?
  • 15. So, whats in the box?Well, a lot :-P
  • 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. The request stack
  • 18. Steps for a requestAcceptParseDispatch(match host, URL, controller)Render template(fetch data)Serve the result
  • 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. 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. What saves time?Dont repeat things that you could have done along time agoHTML escapingContent filtering(Zotonic stores sanitized / escaped content)
  • 22. What saves time? pt IICombine similar (and especially simultaneous)actions into oneRequestsDB resultscalculations...
  • 23. Where can we save timeClient-side cachingStatic filesTemplatesIn-memory caching
  • 24. Client-sideLet client (and proxies) cache css, javascript,images etc.Combine css and javascript requests:
  • 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. TemplatesDrive page renderingCompiled into Erlang byte codeUsing ErlyDTLForked; were merging it back
  • 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[{query cat=person}] %}...Call the models – models responsible for cachingthose results
  • 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. In-memory caching1) Memo cache in process dictionary of therequest process2) Central shared cache for the whole site(“depcache”)
  • 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. 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. Erlang VM considerationsCheap processesExpensive data copying on messagesBinaries have their own heapString processing is expensive(as in any language)
  • 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. 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. 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. So, what about performance?
  • 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. 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. 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. A recent project
  • 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. 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. 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. Service oriented
  • 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. What do we want?Multiple machines, but for error recoveryHardware errorsHardware upgradesHot failover
  • 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. Thank you!Book chapter: “The performance of Open SourceApplications” coming out soon (…and chat with me & Andreas :-)Come get a tshirt!Online resources:@zotonic -IRC, XMPP, mailing listsTalk slides, tutorial slides, tutorial source code...