SlideShare a Scribd company logo
1 of 49
Zotonic
Making it fast!
Zotonic & performance
Erlang User Conference,
Stockholm, June 14 2013
Arjan Scherpenisse - arjan@miraclethings.nl
Let's 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 all running, all the time
Same for RoR, Django...

The problem is not that you can’t scale

The problem is that you need to scale
immediately
Yur site got /.'ed!

Many people followed popular link

A process per request

Death by too many processes

... doing the same thing!
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”
That's why we are making Zotonic.
Zotonic's goals

The frontender is in the driver's seat

Reliable performance

A web server should easily handle the load of 99% of
all web sites

Maximise the use of hardware, do more with less
hardware and less watts

Self-contained, sysadmin friendly

No external services, CDN's, caching servers,
background workers.., and, no downtime
So, what's in the box?
So, what's in the box?

Well, a lot :-P
So, what's 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 :)
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 data & rendering should be optimized
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
What saves time?

Don't repeat things that you could have done a
long time ago

HTML escaping

Content filtering

(Zotonic stores sanitized / escaped content)
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://example.org/lib/bootstrap/css/b
ootstrap~bootstrap-responsive~bootstra
p-base-site~/css/jquery.loadmask~z.gro
wl~z.modal~site~63523081976.css
Static files

File requests are easily cached

Checks on modification dates

Cache both compressed and uncompressed
version

Still access control checks for content (images,
pdfs etc.)
Templates

Drive page rendering

Compiled into Erlang byte code

Using ErlyDTL

Forked; we're merging it back
Template 101
Hello, {{ 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 caching
those results
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}]}
In-memory caching
1) Memo cache in process dictionary of the
request process
2) Central shared cache for the whole site
(“depcache”)
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
Depcache

Central cache per site

ETS based

Key dependencies for consistency

Garbage collector thread

Simple random eviction

Sharing non-cached results between processes
z_depcache:memo(fun() … end, 0, Context)
Erlang VM considerations

Cheap processes

Expensive data copying on messages

Binaries have their own heap

String processing is expensive

(as in any language)
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
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 treating
vhosts)
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
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 encoding?

Your TCP/IP stack?

Well, OK, Zotonic does NOT do so well...
Platform x1000 req/sec
Node.js 27
Cowboy 31
Elli 38
Zotonic 5.5
Zotonic w/o logging 7.5
Zotonic w/ dispatcher process pool 8.5
Some numbers
i7 quadcore M620 @ 2.67GHz
wrk -c 3000 -t 3000 http://localhost:8080/json
Techempower conclusions

We can improve some stuff

Compiled dispatch rule / host matching

Migrate to webserver that handles binaries (Elli or
Cowboy)

Merge Webzmachine ReqData/Context params

Caching template timestamps – speedup freshness
check

Not every framework implements the same test.

Pose artificial restrictions on the tests?

Zotonic's memory-caching is fast...
A recent project
Kroonappels

Nation-wide voting weekend

Client requested 100% availability + high
performance

100k “votes” in 1 hour

3x Rackspace VPS nodes, 2 GB, load balanced
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 :-)
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
Service oriented
Zynamo's downside

Hard...

to maintain,

to do caching

to write new stuff

there are DBMS's that can do this for us

Got us thinking: Do we really need this scale?
What do we want?

Multiple machines, but for error recovery

Hardware errors

Hardware upgrades

Hot failover
The P2P idea

Trusted P2P ring of collaborative Zotonic
machines

Reliable messaging / notification

Poldercast P2P model

Synced database backups / assets

Bittorrent protocol for large files

WAL for db delta's

Sites are vertical, data silo's

Run our own DNS?
Thank you!

Book chapter: “The performance of Open Source
Applications” 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...

More Related Content

What's hot

An Introduction to Ajax Programming
An Introduction to Ajax ProgrammingAn Introduction to Ajax Programming
An Introduction to Ajax Programming
hchen1
 
Ajax Introduction Presentation
Ajax   Introduction   PresentationAjax   Introduction   Presentation
Ajax Introduction Presentation
thinkphp
 

What's hot (20)

Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 
Ajax
AjaxAjax
Ajax
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax Ppt
Ajax PptAjax Ppt
Ajax Ppt
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
 
An Introduction to Ajax Programming
An Introduction to Ajax ProgrammingAn Introduction to Ajax Programming
An Introduction to Ajax Programming
 
Ajax
AjaxAjax
Ajax
 
Ajax Ppt 1
Ajax Ppt 1Ajax Ppt 1
Ajax Ppt 1
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Advantages and disadvantages of an ajax based client application
Advantages and disadvantages of an ajax based client applicationAdvantages and disadvantages of an ajax based client application
Advantages and disadvantages of an ajax based client application
 
Ajax.ppt
Ajax.pptAjax.ppt
Ajax.ppt
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
 
Ajax Introduction Presentation
Ajax   Introduction   PresentationAjax   Introduction   Presentation
Ajax Introduction Presentation
 
What is Ajax technology?
What is Ajax technology?What is Ajax technology?
What is Ajax technology?
 
Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajax
 
Ajax workshop
Ajax workshopAjax workshop
Ajax workshop
 

Viewers also liked

The State Of Israel And The Muslim World 22166
The State Of Israel And The Muslim World 22166The State Of Israel And The Muslim World 22166
The State Of Israel And The Muslim World 22166
GZ-Israel
 
Israelair Photos 1214209899278185 8
Israelair Photos 1214209899278185 8Israelair Photos 1214209899278185 8
Israelair Photos 1214209899278185 8
GZ-Israel
 
Arava Sites By Guy
Arava Sites By GuyArava Sites By Guy
Arava Sites By Guy
GZ-Israel
 
Ezvc
EzvcEzvc
Ezvc
ezvc
 
Israel 1214781329718633 9
Israel 1214781329718633 9Israel 1214781329718633 9
Israel 1214781329718633 9
GZ-Israel
 
Alice Quick Guide
Alice Quick GuideAlice Quick Guide
Alice Quick Guide
KJSROSE
 

Viewers also liked (20)

Maketechwork4u
Maketechwork4uMaketechwork4u
Maketechwork4u
 
The State Of Israel And The Muslim World 22166
The State Of Israel And The Muslim World 22166The State Of Israel And The Muslim World 22166
The State Of Israel And The Muslim World 22166
 
Mark Chagall
Mark ChagallMark Chagall
Mark Chagall
 
Duo Disco - doing the Erlang dance
Duo Disco - doing the Erlang danceDuo Disco - doing the Erlang dance
Duo Disco - doing the Erlang dance
 
IPsec
IPsecIPsec
IPsec
 
Israelair Photos 1214209899278185 8
Israelair Photos 1214209899278185 8Israelair Photos 1214209899278185 8
Israelair Photos 1214209899278185 8
 
El Pueblo Gallego 1948
El Pueblo Gallego 1948El Pueblo Gallego 1948
El Pueblo Gallego 1948
 
Rami Meiri
Rami MeiriRami Meiri
Rami Meiri
 
Zotonic presentation Erlang Camp Boston, august 2011
Zotonic presentation Erlang Camp Boston, august 2011Zotonic presentation Erlang Camp Boston, august 2011
Zotonic presentation Erlang Camp Boston, august 2011
 
Arava Sites By Guy
Arava Sites By GuyArava Sites By Guy
Arava Sites By Guy
 
Ezvc
EzvcEzvc
Ezvc
 
Mediamatic Night Lab #2
Mediamatic Night Lab #2Mediamatic Night Lab #2
Mediamatic Night Lab #2
 
O mar desde esa banda. De Carlos Penela
O mar desde esa banda. De Carlos PenelaO mar desde esa banda. De Carlos Penela
O mar desde esa banda. De Carlos Penela
 
Tel Aviv 1920 1940
Tel Aviv 1920 1940Tel Aviv 1920 1940
Tel Aviv 1920 1940
 
Israel 1214781329718633 9
Israel 1214781329718633 9Israel 1214781329718633 9
Israel 1214781329718633 9
 
Road
RoadRoad
Road
 
O Meu Pequeno Pais
O Meu Pequeno PaisO Meu Pequeno Pais
O Meu Pequeno Pais
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Seica o basilisco é animal de compaña
Seica o basilisco é animal de compañaSeica o basilisco é animal de compaña
Seica o basilisco é animal de compaña
 
Alice Quick Guide
Alice Quick GuideAlice Quick Guide
Alice Quick Guide
 

Similar to Making it fast: Zotonic & Performance

Scalable Apache for Beginners
Scalable Apache for BeginnersScalable Apache for Beginners
Scalable Apache for Beginners
webhostingguy
 
Krug Fat Client
Krug Fat ClientKrug Fat Client
Krug Fat Client
Paul Klipp
 
Tips for a Faster Website
Tips for a Faster WebsiteTips for a Faster Website
Tips for a Faster Website
Rayed Alrashed
 
W-JAX Performance Workshop - Web and AJAX
W-JAX Performance Workshop - Web and AJAXW-JAX Performance Workshop - Web and AJAX
W-JAX Performance Workshop - Web and AJAX
Alois Reitbauer
 
WE18_Performance_Up.ppt
WE18_Performance_Up.pptWE18_Performance_Up.ppt
WE18_Performance_Up.ppt
webhostingguy
 
PHP Performance: Principles and tools
PHP Performance: Principles and toolsPHP Performance: Principles and tools
PHP Performance: Principles and tools
10n Software, LLC
 

Similar to Making it fast: Zotonic & Performance (20)

Scalable Apache for Beginners
Scalable Apache for BeginnersScalable Apache for Beginners
Scalable Apache for Beginners
 
OSDC 2012 | Ultra-performant dynamic websites with Varnish by Dr. Chriatian W...
OSDC 2012 | Ultra-performant dynamic websites with Varnish by Dr. Chriatian W...OSDC 2012 | Ultra-performant dynamic websites with Varnish by Dr. Chriatian W...
OSDC 2012 | Ultra-performant dynamic websites with Varnish by Dr. Chriatian W...
 
Krug Fat Client
Krug Fat ClientKrug Fat Client
Krug Fat Client
 
Configuring Apache Servers for Better Web Perormance
Configuring Apache Servers for Better Web PerormanceConfiguring Apache Servers for Better Web Perormance
Configuring Apache Servers for Better Web Perormance
 
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Web Performance, Scalability, and Testing Techniques - Boston PHP MeetupWeb Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
 
Tips for a Faster Website
Tips for a Faster WebsiteTips for a Faster Website
Tips for a Faster Website
 
W-JAX Performance Workshop - Web and AJAX
W-JAX Performance Workshop - Web and AJAXW-JAX Performance Workshop - Web and AJAX
W-JAX Performance Workshop - Web and AJAX
 
Client Side Performance @ Xero
Client Side Performance @ XeroClient Side Performance @ Xero
Client Side Performance @ Xero
 
AD102 - Break out of the Box
AD102 - Break out of the BoxAD102 - Break out of the Box
AD102 - Break out of the Box
 
WE18_Performance_Up.ppt
WE18_Performance_Up.pptWE18_Performance_Up.ppt
WE18_Performance_Up.ppt
 
PHP Performance: Principles and tools
PHP Performance: Principles and toolsPHP Performance: Principles and tools
PHP Performance: Principles and tools
 
Why Wordnik went non-relational
Why Wordnik went non-relationalWhy Wordnik went non-relational
Why Wordnik went non-relational
 
Natural Laws of Software Performance
Natural Laws of Software PerformanceNatural Laws of Software Performance
Natural Laws of Software Performance
 
Jax Ajax Architecture
Jax Ajax  ArchitectureJax Ajax  Architecture
Jax Ajax Architecture
 
MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011
 
HTML5
HTML5HTML5
HTML5
 
Velocity 2010 - ATS
Velocity 2010 - ATSVelocity 2010 - ATS
Velocity 2010 - ATS
 
Life on the Edge with ESI
Life on the Edge with ESILife on the Edge with ESI
Life on the Edge with ESI
 
Scaling wix with microservices and multi cloud - 2015
Scaling wix with microservices and multi cloud - 2015Scaling wix with microservices and multi cloud - 2015
Scaling wix with microservices and multi cloud - 2015
 
Magento Imagine eCommerce Conference February 2011: Optimizing Magento For Pe...
Magento Imagine eCommerce Conference February 2011: Optimizing Magento For Pe...Magento Imagine eCommerce Conference February 2011: Optimizing Magento For Pe...
Magento Imagine eCommerce Conference February 2011: Optimizing Magento For Pe...
 

More from Arjan (6)

De Naakte Noorderlingen
De Naakte NoorderlingenDe Naakte Noorderlingen
De Naakte Noorderlingen
 
Erlang: Software for a Concurrent world
Erlang: Software for a Concurrent worldErlang: Software for a Concurrent world
Erlang: Software for a Concurrent world
 
Physical Computing with Android and IOIO
Physical Computing with Android and IOIOPhysical Computing with Android and IOIO
Physical Computing with Android and IOIO
 
Hello, world
Hello, worldHello, world
Hello, world
 
Open-CI for beginners
Open-CI for beginnersOpen-CI for beginners
Open-CI for beginners
 
OBG Presentatie Mediamatic Salon
OBG Presentatie Mediamatic SalonOBG Presentatie Mediamatic Salon
OBG Presentatie Mediamatic Salon
 

Recently uploaded

Recently uploaded (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Making it fast: Zotonic & Performance

  • 1. Zotonic Making it fast! Zotonic & performance Erlang User Conference, Stockholm, June 14 2013 Arjan Scherpenisse - arjan@miraclethings.nl
  • 2. Let's 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 scale immediately
  • 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. That's why we are making Zotonic.
  • 13. Zotonic's goals  The frontender is in the driver's seat  Reliable performance  A web server should easily handle the load of 99% of all web sites  Maximise the use of hardware, do more with less hardware and less watts  Self-contained, sysadmin friendly  No external services, CDN's, caching servers, background workers.., and, no downtime
  • 14. So, what's in the box?
  • 15. So, what's in the box?  Well, a lot :-P
  • 16. So, what's 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 :)
  • 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?  Don't repeat things that you could have done a long 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:  http://example.org/lib/bootstrap/css/b ootstrap~bootstrap-responsive~bootstra p-base-site~/css/jquery.loadmask~z.gro wl~z.modal~site~63523081976.css
  • 25. Static files  File requests are easily cached  Checks on modification dates  Cache both compressed and uncompressed version  Still access control checks for content (images, pdfs etc.)
  • 26. Templates  Drive page rendering  Compiled into Erlang byte code  Using ErlyDTL  Forked; we're merging it back
  • 27. Template 101 Hello, {{ 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 caching those 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 caching 1) Memo cache in process dictionary of the request process 2) 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 processes z_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 treating vhosts)
  • 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? http://www.techempower.com/benchmarks/
  • 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/sec Node.js 27 Cowboy 31 Elli 38 Zotonic 5.5 Zotonic w/o logging 7.5 Zotonic w/ dispatcher process pool 8.5 Some numbers i7 quadcore M620 @ 2.67GHz wrk -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 or Cowboy)  Merge Webzmachine ReqData/Context params  Caching template timestamps – speedup freshness check  Not every framework implements the same test.  Pose artificial restrictions on the tests?  Zotonic's memory-caching is fast...
  • 41. Kroonappels  Nation-wide voting weekend  Client requested 100% availability + high performance  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.
  • 44. 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
  • 46. Zynamo's downside  Hard...  to maintain,  to do caching  to write new stuff  there are DBMS's that can do this for us  Got us thinking: Do we really need this scale?
  • 47. What do we want?  Multiple machines, but for error recovery  Hardware errors  Hardware upgrades  Hot failover
  • 48. The P2P idea  Trusted P2P ring of collaborative Zotonic machines  Reliable messaging / notification  Poldercast P2P model  Synced database backups / assets  Bittorrent protocol for large files  WAL for db delta's  Sites are vertical, data silo's  Run our own DNS?
  • 49. Thank you!  Book chapter: “The performance of Open Source Applications” 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...