SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Downloaden Sie, um offline zu lesen
Server Side Story
An asynchronous ballet
Simone Deponti - simone.deponti@abstract.itEuroPython 2013
Who am I
Python web developer since 2006
Work at Abstract as web developer
Plone contributor
Do more Javascript than I'm willing to
admit
Abstract @ EuroPython 2013
Am I in the wrong room?
This talk will focus on:
• Where web development comes from
• Challenges of real-time applications
• Patterns and tools to deal with that
Abstract @ EuroPython 2013
CODE SAMPLE FREE! (ALMOST)
A LITTLE BIT OF HISTORY
Let there be <a> link
The web was born as:
• Simple document retrieval
• Interlinking of documents
Abstract @ EuroPython 2013
Have you seen?
Next step:
• Searching documents
• Query parameters
• POST and Forms
• CGI
• We start having stuff that's not
documents
Abstract @ EuroPython 2013
Statefulness
HTTP is stateless
• stateless isn't good for applications
• cookies add statefulness
Abstract @ EuroPython 2013
Javascript
Executing code on the client was needed:
• provisions for scripting were there
• we lacked a language and a way to
interact with the document
• Javascript and the DOM came
Abstract @ EuroPython 2013
AJAX
Javascript was limited to mangling the
DOM
• AJAX added the ability to make
requests "on the side"
• One-page applications
• State lives on the client, too!
Abstract @ EuroPython 2013
CURRENT SITUATION
Web applications
So far:
• the server is the master
• all data lives there
• the client requests stuff and gets a
reply
Abstract @ EuroPython 2013
Web applications (server side)
Every "classic" web app does this on every
request:
• pull up the state
• process the request
• assemble a response
• save the new state and return it back
Abstract @ EuroPython 2013
I've got something to say!
The server can speak only when asked.
This maps poorly on these cases:
• Notifications
• Chat systems
• Real time applications
Abstract @ EuroPython 2013
SOLUTIONS
Polling
Polling is the simplest solution, and the
worst
• You keep annoying the server
• Wasting memory, CPU, bandwidth on
both sides just to annoy a component
of your stack
• Logarithmic polling isn't a solution
Abstract @ EuroPython 2013
COMET
Also called long polling
• Still based on request-reply
• The server replies very slowly,
allowing time to elapse and hoping
that something happens
Abstract @ EuroPython 2013
BOSH
The formal way to do COMET, as done by
XMPP:
• Client starts a long-polling connection
• If something happens on the client
side, client sends a second request,
server replies on the first and closes,
second remains open
• Before expiration time, server sends
empty message and closes, client
reopens connection.
Abstract @ EuroPython 2013
http://xmpp.org/extensions/xep-0124.html#technique
You might not be able to deal with this
If your execution model calls for one
thread/process per request, you're out of
luck.
You must use an asynchronous server.
Abstract @ EuroPython 2013
Websockets
A new protocol
• a bidirectional connection tunneled
through HTTP (similar to a raw TCP
connection)
• HTTP 1.1 has provisions for this
• Sadly, it's the part of the protocol
where many implementors got bored
Abstract @ EuroPython 2013
http://tools.ietf.org/html/rfc6455
Websockets in Python
from geventwebsocket.handler import WebSocketHandler
from gevent.pywsgi import WSGIServer
[...]
@app.route('/api')
def api():
if request.environ.get('wsgi.websocket'):
ws = request.environ['wsgi.websocket']
while True:
message = ws.wait()
ws.send(message)
return
if __name__ == '__main__':
server = WSGIServer([...],handler_class=WebSocketHandler)
[...]
Abstract @ EuroPython 2013
https://gist.github.com/lrvick/1185629
Asyncronous I/O
Is hard.
• Processes and traditional threads don't
scale for real-time apps
• Callback based systems are one
solution
• Green threads are another one
In Python, there is no clean and easy
solution.
Abstract @ EuroPython 2013
http://stackoverflow.com/a/3325985/967274
Tulip (PEP 3156)
Tries to provide a common groud for all
frameworks targeting asyncronous I/O
• Has a pluggable event loop interface
• Uses futures to abstract callbacks
• Allows using callbacks or coroutines
(via yield from)
• Uses the concept of transports and
protocols
Abstract @ EuroPython 2013
Tulip (PEP 3156)
Pros and cons
• Tulip isn't simple or straightforward
• Because of its constraints
• Reinventing the whole Python
ecosystem ain't an option
• Tulip is a library, frameworks can build
on top of it
• Planned to land in 3.4
• Conveniently wraps parts of the
standard library
Abstract @ EuroPython 2013
Tulip and websockets
Tulip supports websockets
• Has an example in the source, solving
the broadcaster use case
• The example is fairly complete (and
complex)
Abstract @ EuroPython 2013
http://code.google.com/p/tulip/source/browse/examples/wssrv.py
Architectural considerations
Most of the quick fixes you're used to
won't work
• Caching can't be layered over the
frontend to mask problems
• Code flow must receive extra care
• You still need to deal with an awful lot
of synchronous calls, and orchestrate
them with asynchronous calls
Abstract @ EuroPython 2013
http://python-notes.boredomandlaziness.org/en/latest/pep_ideas/async_programming.html
Shar(d)ed state
Real time applications behave like clusters
• State is sharded between nodes
• You must orchestrate and deal with
inconsistencies
• People doing clusters (or cloud
systems) have already some
theoretical work done
Abstract @ EuroPython 2013
Scaling
Once you're able to manage the shared
state, scaling becomes easier and linear.
However, due to the nature of the control
flow, it will cost more than with non-
realtime web applications.
Abstract @ EuroPython 2013
Security considerations
Websockets have security provisions to
avoid blatant abuses.
However:
• Authentication and authorization are
delegated to the application
• Statefulness is a double-edged sword
• The protocol itself is fairly new and
underdeployed
Abstract @ EuroPython 2013
Security considerations (2)
Websockets use the origin model
• These provisions are relevant for
browsers only
• Intended to impede browser hijacking
• RFC clearly states that validation of
data should always be performed on
both sides
• Resist the urge to allow for arbitrary
objects to be passed between server
and client
Abstract @ EuroPython 2013
Conclusions
• Real time applications require a
fundamental change of paradigm
• This paradigm change spawned a new
protocol on the client side
• The server side should abandon the
standard model and embrace event
based asynchronous systems
• In python we already have tools to
deal with these challenges, but the
landscape is fragmented
Abstract @ EuroPython 2013
Conclusions (2)
• Python 3.4 will (hopefully) lay a
common layer to address these
architectural problems
• There are fundamental architectural
changes that the paradigm brings to
web applications, making it almost
equal to native applications
• The area still needs to mature to fully
expose challenges especially in the
area of security
Abstract @ EuroPython 2013
Simone Deponti
simone.deponti@abstract.it
@simonedeponti
Questions?
Abstract @ EuroPython 2013

Weitere ähnliche Inhalte

Was ist angesagt?

Reactive programming
Reactive programmingReactive programming
Reactive programmingsaykopatt
 
Олександр Хотемський:”Serverless архітектура та її застосування в автоматизац...
Олександр Хотемський:”Serverless архітектура та її застосування в автоматизац...Олександр Хотемський:”Serverless архітектура та її застосування в автоматизац...
Олександр Хотемський:”Serverless архітектура та її застосування в автоматизац...Dakiry
 
Matteo Vaccari - Going Frameworkless in the Backend - Codemotion Milan 2018
Matteo Vaccari - Going Frameworkless in the Backend - Codemotion Milan 2018Matteo Vaccari - Going Frameworkless in the Backend - Codemotion Milan 2018
Matteo Vaccari - Going Frameworkless in the Backend - Codemotion Milan 2018Codemotion
 
Declarative Concurrency with Reactive Programming
Declarative Concurrency with Reactive ProgrammingDeclarative Concurrency with Reactive Programming
Declarative Concurrency with Reactive ProgrammingFlorian Stefan
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programmingAhmed Kamel Taha
 
Reactive programming and RxJS
Reactive programming and RxJSReactive programming and RxJS
Reactive programming and RxJSRavi Mone
 
A pitfall when writing an asynchronous web application with Spring and Tomcat
A pitfall when writing an asynchronous web application with Spring and TomcatA pitfall when writing an asynchronous web application with Spring and Tomcat
A pitfall when writing an asynchronous web application with Spring and TomcatLINE Corporation
 
Lightweight Java EE with MicroProfile
Lightweight Java EE with MicroProfileLightweight Java EE with MicroProfile
Lightweight Java EE with MicroProfileJosh Juneau
 
Managing state in modern React web applications
Managing state in modern React web applicationsManaging state in modern React web applications
Managing state in modern React web applicationsJon Preece
 
Hexagonal architecture message-oriented software design
Hexagonal architecture   message-oriented software designHexagonal architecture   message-oriented software design
Hexagonal architecture message-oriented software designMatthias Noback
 
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)Matthias Noback
 
Hibernate performance tuning
Hibernate performance tuningHibernate performance tuning
Hibernate performance tuningMikalai Alimenkou
 
Clojure 1.8 Direct-Linking WWH
Clojure 1.8  Direct-Linking  WWHClojure 1.8  Direct-Linking  WWH
Clojure 1.8 Direct-Linking WWHdennis zhuang
 
Akka for big data developers
Akka for big data developersAkka for big data developers
Akka for big data developersTaras Fedorov
 
Reactive programming - Observable
Reactive programming - ObservableReactive programming - Observable
Reactive programming - ObservableDragos Ionita
 

Was ist angesagt? (20)

Reactive programming
Reactive programmingReactive programming
Reactive programming
 
Training – Going Async
Training – Going AsyncTraining – Going Async
Training – Going Async
 
Mini training - Reactive Extensions (Rx)
Mini training - Reactive Extensions (Rx)Mini training - Reactive Extensions (Rx)
Mini training - Reactive Extensions (Rx)
 
Олександр Хотемський:”Serverless архітектура та її застосування в автоматизац...
Олександр Хотемський:”Serverless архітектура та її застосування в автоматизац...Олександр Хотемський:”Serverless архітектура та її застосування в автоматизац...
Олександр Хотемський:”Serverless архітектура та її застосування в автоматизац...
 
Matteo Vaccari - Going Frameworkless in the Backend - Codemotion Milan 2018
Matteo Vaccari - Going Frameworkless in the Backend - Codemotion Milan 2018Matteo Vaccari - Going Frameworkless in the Backend - Codemotion Milan 2018
Matteo Vaccari - Going Frameworkless in the Backend - Codemotion Milan 2018
 
Declarative Concurrency with Reactive Programming
Declarative Concurrency with Reactive ProgrammingDeclarative Concurrency with Reactive Programming
Declarative Concurrency with Reactive Programming
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programming
 
Reactive programming and RxJS
Reactive programming and RxJSReactive programming and RxJS
Reactive programming and RxJS
 
A pitfall when writing an asynchronous web application with Spring and Tomcat
A pitfall when writing an asynchronous web application with Spring and TomcatA pitfall when writing an asynchronous web application with Spring and Tomcat
A pitfall when writing an asynchronous web application with Spring and Tomcat
 
Lightweight Java EE with MicroProfile
Lightweight Java EE with MicroProfileLightweight Java EE with MicroProfile
Lightweight Java EE with MicroProfile
 
Project Reactor By Example
Project Reactor By ExampleProject Reactor By Example
Project Reactor By Example
 
Managing state in modern React web applications
Managing state in modern React web applicationsManaging state in modern React web applications
Managing state in modern React web applications
 
React Testing
React TestingReact Testing
React Testing
 
Hexagonal architecture message-oriented software design
Hexagonal architecture   message-oriented software designHexagonal architecture   message-oriented software design
Hexagonal architecture message-oriented software design
 
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)
 
Hibernate performance tuning
Hibernate performance tuningHibernate performance tuning
Hibernate performance tuning
 
Clojure 1.8 Direct-Linking WWH
Clojure 1.8  Direct-Linking  WWHClojure 1.8  Direct-Linking  WWH
Clojure 1.8 Direct-Linking WWH
 
Akka for big data developers
Akka for big data developersAkka for big data developers
Akka for big data developers
 
Reactive programming - Observable
Reactive programming - ObservableReactive programming - Observable
Reactive programming - Observable
 
Async Programming in C# 5
Async Programming in C# 5Async Programming in C# 5
Async Programming in C# 5
 

Ähnlich wie Server side story

Deploy secure, scalable, and highly available web apps with Azure Front Door ...
Deploy secure, scalable, and highly available web apps with Azure Front Door ...Deploy secure, scalable, and highly available web apps with Azure Front Door ...
Deploy secure, scalable, and highly available web apps with Azure Front Door ...Stamo Petkov
 
Realtime traffic analyser
Realtime traffic analyserRealtime traffic analyser
Realtime traffic analyserAlex Moskvin
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - TalkMatthias Noback
 
Azure architecture design patterns - proven solutions to common challenges
Azure architecture design patterns - proven solutions to common challengesAzure architecture design patterns - proven solutions to common challenges
Azure architecture design patterns - proven solutions to common challengesIvo Andreev
 
2015 02 24 lmtv baselining
2015 02 24 lmtv baselining2015 02 24 lmtv baselining
2015 02 24 lmtv baseliningTony Fortunato
 
All about that reactive ui
All about that reactive uiAll about that reactive ui
All about that reactive uiPaul van Zyl
 
Asynchronous Frameworks.pptx
Asynchronous Frameworks.pptxAsynchronous Frameworks.pptx
Asynchronous Frameworks.pptxganeshkarthy
 
Building A Mobile First API When You're Not Mobile First - Tyler Singletary
Building A Mobile First API When You're Not Mobile First - Tyler SingletaryBuilding A Mobile First API When You're Not Mobile First - Tyler Singletary
Building A Mobile First API When You're Not Mobile First - Tyler SingletaryProgrammableWeb
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Steve Pember
 
Microservices: The Best Practices
Microservices: The Best PracticesMicroservices: The Best Practices
Microservices: The Best PracticesPavel Mička
 
Building Awesome APIs with Lumen
Building Awesome APIs with LumenBuilding Awesome APIs with Lumen
Building Awesome APIs with LumenKit Brennan
 
12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQLKonstantin Gredeskoul
 
Reactive Micro Services with Java seminar
Reactive Micro Services with Java seminarReactive Micro Services with Java seminar
Reactive Micro Services with Java seminarGal Marder
 
Natural Laws of Software Performance
Natural Laws of Software PerformanceNatural Laws of Software Performance
Natural Laws of Software PerformanceGibraltar Software
 
Streaming to a New Jakarta EE
Streaming to a New Jakarta EEStreaming to a New Jakarta EE
Streaming to a New Jakarta EEJ On The Beach
 
Streaming to a new Jakarta EE
Streaming to a new Jakarta EEStreaming to a new Jakarta EE
Streaming to a new Jakarta EEMarkus Eisele
 
Your Testing Is Flawed: Introducing A New Open Source Tool For Accurate Kuber...
Your Testing Is Flawed: Introducing A New Open Source Tool For Accurate Kuber...Your Testing Is Flawed: Introducing A New Open Source Tool For Accurate Kuber...
Your Testing Is Flawed: Introducing A New Open Source Tool For Accurate Kuber...StormForge .io
 
Testing for Logic App Solutions | Integration Monday
Testing for Logic App Solutions | Integration MondayTesting for Logic App Solutions | Integration Monday
Testing for Logic App Solutions | Integration MondayBizTalk360
 

Ähnlich wie Server side story (20)

Deploy secure, scalable, and highly available web apps with Azure Front Door ...
Deploy secure, scalable, and highly available web apps with Azure Front Door ...Deploy secure, scalable, and highly available web apps with Azure Front Door ...
Deploy secure, scalable, and highly available web apps with Azure Front Door ...
 
Realtime traffic analyser
Realtime traffic analyserRealtime traffic analyser
Realtime traffic analyser
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - Talk
 
Azure architecture design patterns - proven solutions to common challenges
Azure architecture design patterns - proven solutions to common challengesAzure architecture design patterns - proven solutions to common challenges
Azure architecture design patterns - proven solutions to common challenges
 
2015 02 24 lmtv baselining
2015 02 24 lmtv baselining2015 02 24 lmtv baselining
2015 02 24 lmtv baselining
 
All about that reactive ui
All about that reactive uiAll about that reactive ui
All about that reactive ui
 
Asynchronous Frameworks.pptx
Asynchronous Frameworks.pptxAsynchronous Frameworks.pptx
Asynchronous Frameworks.pptx
 
Building A Mobile First API When You're Not Mobile First - Tyler Singletary
Building A Mobile First API When You're Not Mobile First - Tyler SingletaryBuilding A Mobile First API When You're Not Mobile First - Tyler Singletary
Building A Mobile First API When You're Not Mobile First - Tyler Singletary
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
 
Microservices: The Best Practices
Microservices: The Best PracticesMicroservices: The Best Practices
Microservices: The Best Practices
 
Building Awesome APIs with Lumen
Building Awesome APIs with LumenBuilding Awesome APIs with Lumen
Building Awesome APIs with Lumen
 
12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL
 
Websocket 101 in Python
Websocket 101 in PythonWebsocket 101 in Python
Websocket 101 in Python
 
Fastest Servlets in the West
Fastest Servlets in the WestFastest Servlets in the West
Fastest Servlets in the West
 
Reactive Micro Services with Java seminar
Reactive Micro Services with Java seminarReactive Micro Services with Java seminar
Reactive Micro Services with Java seminar
 
Natural Laws of Software Performance
Natural Laws of Software PerformanceNatural Laws of Software Performance
Natural Laws of Software Performance
 
Streaming to a New Jakarta EE
Streaming to a New Jakarta EEStreaming to a New Jakarta EE
Streaming to a New Jakarta EE
 
Streaming to a new Jakarta EE
Streaming to a new Jakarta EEStreaming to a new Jakarta EE
Streaming to a new Jakarta EE
 
Your Testing Is Flawed: Introducing A New Open Source Tool For Accurate Kuber...
Your Testing Is Flawed: Introducing A New Open Source Tool For Accurate Kuber...Your Testing Is Flawed: Introducing A New Open Source Tool For Accurate Kuber...
Your Testing Is Flawed: Introducing A New Open Source Tool For Accurate Kuber...
 
Testing for Logic App Solutions | Integration Monday
Testing for Logic App Solutions | Integration MondayTesting for Logic App Solutions | Integration Monday
Testing for Logic App Solutions | Integration Monday
 

Kürzlich hochgeladen

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 DevelopmentsTrustArc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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
 

Kürzlich hochgeladen (20)

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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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...
 

Server side story

  • 1. Server Side Story An asynchronous ballet Simone Deponti - simone.deponti@abstract.itEuroPython 2013
  • 2. Who am I Python web developer since 2006 Work at Abstract as web developer Plone contributor Do more Javascript than I'm willing to admit Abstract @ EuroPython 2013
  • 3. Am I in the wrong room? This talk will focus on: • Where web development comes from • Challenges of real-time applications • Patterns and tools to deal with that Abstract @ EuroPython 2013 CODE SAMPLE FREE! (ALMOST)
  • 4. A LITTLE BIT OF HISTORY
  • 5. Let there be <a> link The web was born as: • Simple document retrieval • Interlinking of documents Abstract @ EuroPython 2013
  • 6. Have you seen? Next step: • Searching documents • Query parameters • POST and Forms • CGI • We start having stuff that's not documents Abstract @ EuroPython 2013
  • 7. Statefulness HTTP is stateless • stateless isn't good for applications • cookies add statefulness Abstract @ EuroPython 2013
  • 8. Javascript Executing code on the client was needed: • provisions for scripting were there • we lacked a language and a way to interact with the document • Javascript and the DOM came Abstract @ EuroPython 2013
  • 9. AJAX Javascript was limited to mangling the DOM • AJAX added the ability to make requests "on the side" • One-page applications • State lives on the client, too! Abstract @ EuroPython 2013
  • 11. Web applications So far: • the server is the master • all data lives there • the client requests stuff and gets a reply Abstract @ EuroPython 2013
  • 12. Web applications (server side) Every "classic" web app does this on every request: • pull up the state • process the request • assemble a response • save the new state and return it back Abstract @ EuroPython 2013
  • 13. I've got something to say! The server can speak only when asked. This maps poorly on these cases: • Notifications • Chat systems • Real time applications Abstract @ EuroPython 2013
  • 15. Polling Polling is the simplest solution, and the worst • You keep annoying the server • Wasting memory, CPU, bandwidth on both sides just to annoy a component of your stack • Logarithmic polling isn't a solution Abstract @ EuroPython 2013
  • 16. COMET Also called long polling • Still based on request-reply • The server replies very slowly, allowing time to elapse and hoping that something happens Abstract @ EuroPython 2013
  • 17. BOSH The formal way to do COMET, as done by XMPP: • Client starts a long-polling connection • If something happens on the client side, client sends a second request, server replies on the first and closes, second remains open • Before expiration time, server sends empty message and closes, client reopens connection. Abstract @ EuroPython 2013 http://xmpp.org/extensions/xep-0124.html#technique
  • 18. You might not be able to deal with this If your execution model calls for one thread/process per request, you're out of luck. You must use an asynchronous server. Abstract @ EuroPython 2013
  • 19. Websockets A new protocol • a bidirectional connection tunneled through HTTP (similar to a raw TCP connection) • HTTP 1.1 has provisions for this • Sadly, it's the part of the protocol where many implementors got bored Abstract @ EuroPython 2013 http://tools.ietf.org/html/rfc6455
  • 20. Websockets in Python from geventwebsocket.handler import WebSocketHandler from gevent.pywsgi import WSGIServer [...] @app.route('/api') def api(): if request.environ.get('wsgi.websocket'): ws = request.environ['wsgi.websocket'] while True: message = ws.wait() ws.send(message) return if __name__ == '__main__': server = WSGIServer([...],handler_class=WebSocketHandler) [...] Abstract @ EuroPython 2013 https://gist.github.com/lrvick/1185629
  • 21. Asyncronous I/O Is hard. • Processes and traditional threads don't scale for real-time apps • Callback based systems are one solution • Green threads are another one In Python, there is no clean and easy solution. Abstract @ EuroPython 2013 http://stackoverflow.com/a/3325985/967274
  • 22. Tulip (PEP 3156) Tries to provide a common groud for all frameworks targeting asyncronous I/O • Has a pluggable event loop interface • Uses futures to abstract callbacks • Allows using callbacks or coroutines (via yield from) • Uses the concept of transports and protocols Abstract @ EuroPython 2013
  • 23. Tulip (PEP 3156) Pros and cons • Tulip isn't simple or straightforward • Because of its constraints • Reinventing the whole Python ecosystem ain't an option • Tulip is a library, frameworks can build on top of it • Planned to land in 3.4 • Conveniently wraps parts of the standard library Abstract @ EuroPython 2013
  • 24. Tulip and websockets Tulip supports websockets • Has an example in the source, solving the broadcaster use case • The example is fairly complete (and complex) Abstract @ EuroPython 2013 http://code.google.com/p/tulip/source/browse/examples/wssrv.py
  • 25. Architectural considerations Most of the quick fixes you're used to won't work • Caching can't be layered over the frontend to mask problems • Code flow must receive extra care • You still need to deal with an awful lot of synchronous calls, and orchestrate them with asynchronous calls Abstract @ EuroPython 2013 http://python-notes.boredomandlaziness.org/en/latest/pep_ideas/async_programming.html
  • 26. Shar(d)ed state Real time applications behave like clusters • State is sharded between nodes • You must orchestrate and deal with inconsistencies • People doing clusters (or cloud systems) have already some theoretical work done Abstract @ EuroPython 2013
  • 27. Scaling Once you're able to manage the shared state, scaling becomes easier and linear. However, due to the nature of the control flow, it will cost more than with non- realtime web applications. Abstract @ EuroPython 2013
  • 28. Security considerations Websockets have security provisions to avoid blatant abuses. However: • Authentication and authorization are delegated to the application • Statefulness is a double-edged sword • The protocol itself is fairly new and underdeployed Abstract @ EuroPython 2013
  • 29. Security considerations (2) Websockets use the origin model • These provisions are relevant for browsers only • Intended to impede browser hijacking • RFC clearly states that validation of data should always be performed on both sides • Resist the urge to allow for arbitrary objects to be passed between server and client Abstract @ EuroPython 2013
  • 30. Conclusions • Real time applications require a fundamental change of paradigm • This paradigm change spawned a new protocol on the client side • The server side should abandon the standard model and embrace event based asynchronous systems • In python we already have tools to deal with these challenges, but the landscape is fragmented Abstract @ EuroPython 2013
  • 31. Conclusions (2) • Python 3.4 will (hopefully) lay a common layer to address these architectural problems • There are fundamental architectural changes that the paradigm brings to web applications, making it almost equal to native applications • The area still needs to mature to fully expose challenges especially in the area of security Abstract @ EuroPython 2013