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 modi๏ฌcation 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 ๏ฌ‚ush 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

Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Adnan Sohail
ย 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajaxNir Elbaz
ย 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajaxRaja V
ย 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentationjrdoane
ย 
An Introduction to Ajax Programming
An Introduction to Ajax ProgrammingAn Introduction to Ajax Programming
An Introduction to Ajax Programminghchen1
ย 
Ajax
AjaxAjax
AjaxTech_MX
ย 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajaxVenkat Pinagadi
ย 
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 applicationPlacinta Alin
ย 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentationBharat_Kumawat
ย 
Ajax Introduction Presentation
Ajax   Introduction   PresentationAjax   Introduction   Presentation
Ajax Introduction Presentationthinkphp
ย 
What is Ajax technology?
What is Ajax technology?What is Ajax technology?
What is Ajax technology?JavaTpoint.Com
ย 
Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajaxPihu Goel
ย 
Ajax workshop
Ajax workshopAjax workshop
Ajax workshopWBUTTUTORIALS
ย 

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

Maketechwork4u
Maketechwork4uMaketechwork4u
Maketechwork4uSandra Hines
ย 
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 22166GZ-Israel
ย 
Mark Chagall
Mark ChagallMark Chagall
Mark ChagallGZ-Israel
ย 
Duo Disco - doing the Erlang dance
Duo Disco - doing the Erlang danceDuo Disco - doing the Erlang dance
Duo Disco - doing the Erlang danceArjan
ย 
Israelair Photos 1214209899278185 8
Israelair Photos 1214209899278185 8Israelair Photos 1214209899278185 8
Israelair Photos 1214209899278185 8GZ-Israel
ย 
El Pueblo Gallego 1948
El Pueblo Gallego 1948El Pueblo Gallego 1948
El Pueblo Gallego 1948GZ-Israel
ย 
Rami Meiri
Rami MeiriRami Meiri
Rami MeiriGZ-Israel
ย 
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 2011Arjan
ย 
Arava Sites By Guy
Arava Sites By GuyArava Sites By Guy
Arava Sites By GuyGZ-Israel
ย 
Ezvc
EzvcEzvc
Ezvcezvc
ย 
Mediamatic Night Lab #2
Mediamatic Night Lab #2Mediamatic Night Lab #2
Mediamatic Night Lab #2Arjan
ย 
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 PenelaGZ-Israel
ย 
Tel Aviv 1920 1940
Tel Aviv 1920 1940Tel Aviv 1920 1940
Tel Aviv 1920 1940GZ-Israel
ย 
Israel 1214781329718633 9
Israel 1214781329718633 9Israel 1214781329718633 9
Israel 1214781329718633 9GZ-Israel
ย 
O Meu Pequeno Pais
O Meu Pequeno PaisO Meu Pequeno Pais
O Meu Pequeno PaisGZ-Israel
ย 
Android workshop
Android workshopAndroid workshop
Android workshopArjan
ย 
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รฑaGZ-Israel
ย 
Alice Quick Guide
Alice Quick GuideAlice Quick Guide
Alice Quick GuideKJSROSE
ย 

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 Beginnerswebhostingguy
ย 
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...NETWAYS
ย 
Krug Fat Client
Krug Fat ClientKrug Fat Client
Krug Fat ClientPaul Klipp
ย 
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 PerormanceSpark::red
ย 
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 MeetupJonathan Klein
ย 
Tips for a Faster Website
Tips for a Faster WebsiteTips for a Faster Website
Tips for a Faster WebsiteRayed 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 AJAXAlois Reitbauer
ย 
Client Side Performance @ Xero
Client Side Performance @ XeroClient Side Performance @ Xero
Client Side Performance @ XeroCraig Walker
ย 
AD102 - Break out of the Box
AD102 - Break out of the BoxAD102 - Break out of the Box
AD102 - Break out of the BoxKarl-Henry Martinsson
ย 
WE18_Performance_Up.ppt
WE18_Performance_Up.pptWE18_Performance_Up.ppt
WE18_Performance_Up.pptwebhostingguy
ย 
PHP Performance: Principles and tools
PHP Performance: Principles and toolsPHP Performance: Principles and tools
PHP Performance: Principles and tools10n Software, LLC
ย 
Why Wordnik went non-relational
Why Wordnik went non-relationalWhy Wordnik went non-relational
Why Wordnik went non-relationalTony Tam
ย 
Natural Laws of Software Performance
Natural Laws of Software PerformanceNatural Laws of Software Performance
Natural Laws of Software PerformanceGibraltar Software
ย 
Jax Ajax Architecture
Jax Ajax  ArchitectureJax Ajax  Architecture
Jax Ajax ArchitectureAlois Reitbauer
ย 
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 2011Mike Willbanks
ย 
Velocity 2010 - ATS
Velocity 2010 - ATSVelocity 2010 - ATS
Velocity 2010 - ATSLeif Hedstrom
ย 
Life on the Edge with ESI
Life on the Edge with ESILife on the Edge with ESI
Life on the Edge with ESIKit Chan
ย 
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 - 2015Aviran Mordo
ย 
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...varien
ย 

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

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

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

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 MilvusZilliz
ย 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
ย 
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...apidays
ย 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
ย 
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 educationjfdjdjcjdnsjd
ย 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
ย 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
ย 
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 CVKhem
ย 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
ย 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
ย 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
ย 
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].pdfOverkill Security
ย 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
ย 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
ย 
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...Zilliz
ย 
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 2024The Digital Insurer
ย 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
ย 
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 TerraformAndrey Devyatkin
ย 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
ย 

Recently uploaded (20)

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
ย 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
ย 
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...
ย 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
ย 
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
ย 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
ย 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
ย 
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
ย 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
ย 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
ย 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
ย 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
ย 
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
ย 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
ย 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
ย 
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...
ย 
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
ย 
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
ย 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
ย 

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 modi๏ฌcation 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 ๏ฌ‚ush 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...