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

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 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
 
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
 
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
 
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
 
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

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 

Recently uploaded (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.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...