SlideShare uma empresa Scribd logo
1 de 43
Adam Hitchcock
@NorthIsUp
How DISQUS does ‘it’
when ‘it’ isn’t Django
Tuesday, June 25, 13
Tuesday, June 25, 13
we’re hiring
disqus.com/jobs
If this is
interesting to you...
Tuesday, June 25, 13
what is DISQUS?
Tuesday, June 25, 13
Tuesday, June 25, 13
DISQUS sees a lot of traffic
Google Analytics: Feb 2013 - March 2013
Tuesday, June 25, 13
what makes up Disqus?
Tuesday, June 25, 13
mostly Python
Tuesday, June 25, 13
(and javascript)
Tuesday, June 25, 13
but mostly Python
Tuesday, June 25, 13
and we love it!
Tuesday, June 25, 13
why python?
๏ because it is fast…
๏ to develop in
๏ good community
๏ lots of libraries
๏ so active we can’t keep up with it
๏ is anybody using 3.3 yet?
๏ Disqus has a really good dev loop for it
Tuesday, June 25, 13
how does our dev loop work?
๏ diff code (with phabricator)
๏ get that reviewed
๏ review with phabricator
๏ ci done by jenkins
๏ land it on master (git push)
๏ wait for the daily deploy (ops team)
๏ and we are moving to autodeploy (we’ll revisit
this one)
Tuesday, June 25, 13
break it down.
๏ mostly Django
๏ two years ago 95% Django*
๏ today ~70% Django*
๏ what is in that growing gap?
๏ *totally made up numbers
Tuesday, June 25, 13
how does this actually work at Disqus?
Tuesday, June 25, 13
disqus-web (kinda monolithic)
๏ Django + celery on postgres + rabbit
๏ we roll up commits for a deploy
๏ risk of revert that isn’t your fault
๏ you bring down the whole thing if you
forgot to remove that pdb.settrace()
๏ high scrutiny in code review (see above)
๏ high volume of code review (code review
RTT can be a full day)
๏ lots of legacy code to work around (and
not break)
Tuesday, June 25, 13
problems that don’t fit
๏ high concurrency
๏ isolation
๏ feature
๏ failure
๏ speed (cpu cycles)
๏ speed (dev iteration cycle)
๏ fun
Tuesday, June 25, 13
what did we play with?
Tuesday, June 25, 13
for fun and concurrency!
๏ nginx + nginx-modules
๏ https://speakerdeck.com/northisup/
scaling-realtime-at-disqus?slide=39
๏ nginx + lua
๏ https://github.com/NorthIsUp/nginx-
oauth-on-dotcloud/blob/master/nginx/
access.persona.lua.in
๏ go
๏ http://blog.disqus.com/post/
51155103801/trying-out-this-go-thing
Tuesday, June 25, 13
embedly in nginx + lua
local http = require "resty.http"
local cjson = require "cjson"
local url = "https://api.embed.ly/1/oembed?key=" ..
ngx.var.api_key .. "&url=" .. ngx.var.url
local hc = http:new()
local ok, code, headers, status, body = hc:request {
url = url,
method = "GET"
}
if code ~= 200 then
ngx.exit(code)
end
local thumbnail = cjson.decode(body).thumbnail_url
ngx.var.thumbnail = thumbnail
Tuesday, June 25, 13
python still works too
Tuesday, June 25, 13
isolation and iteration speed
๏ failure should be isolated to a small service
๏ successes should be allowed to occur
quickly
๏ python is still great for these use cases
Tuesday, June 25, 13
when we needed it right now!
๏ if __name__ == ‘__main__’:
๏ from wsgiref.simple_server import make_server
๏ from xmlrpclib import ServerProxy
Tuesday, June 25, 13
it works great!
๏ for one deploy
๏ then you have to update it…
Tuesday, June 25, 13
lessons
๏ consistency is good!
๏ protects you from somebody quitting or
getting hit by a bus
๏ anybody can just pick it up and run
๏ simplicity is good!
๏ modularity is good
๏ the ability to borrow/combine features
from other projects
๏ but copypasta is bad
๏ and not bugging ops for a deploy is the
Tuesday, June 25, 13
enter disqus-service
Tuesday, June 25, 13
disqus-service
๏ the goal is consistent/free access to…
๏ config
๏ switches
๏ logging
๏ stats
๏ other systems
๏ and should be easy to run
Tuesday, June 25, 13
@service
๏ equivalent to if __name__ == ‘__main__’:
๏ that is basically it, you can now run it
Tuesday, June 25, 13
hello.py
from disqus.service.application import
service
@service
def world():
print "hello world"
$ toil run hello.world
hello world
Tuesday, June 25, 13
but you want more power
๏ class Service:
๏ @handler
๏ @pre_config
๏ @post_config
๏ @pre_setup
๏ @post_setup
๏ @pre_update_config
๏ @post_update_config
Tuesday, June 25, 13
hello-v2.0.py
from disqus.service.application import (Service,
handler, post_config)
def World(Service):
@handler
def world(self):
print self.redis.get("hello world")
@post_config
def setup_redis(self)
self.redis = Redis(
host=self.config.REDIS_HOST,
port=self.config.REDIS_PORT
)
world = World()
Tuesday, June 25, 13
mixins!
๏ FlaskService
๏ the service instance is also a wsgi app
๏ GeventService
๏ concurrency helpers
๏ RedisService
๏ KafkaService
๏ DjangoORMService (currently in progress)
Tuesday, June 25, 13
real life Disqus code!
from __future__ import absolute_import
from IPython.frontend.terminal.embed import InteractiveShellEmbed
from disqus.service.application import handler
import tempest
from tempest.services.mixins.data import RedisMixin
class Shell(RedisMixin):
@handler
def shell(self, *args, **kwargs):
"""
runs an ipython shell loaded in the tempest module
"""
ipshell = InteractiveShellEmbed()
ipshell(local_ns=locals(), global_ns=globals(), module=tempest)
shell = Shell()
Tuesday, June 25, 13
I want to talk more about mixins,
because I really like them.
So the following slides are about
mixins, but not about services.
Please use your imagination that
I did not just copypasta them
from my pycon slides
Tuesday, June 25, 13
data pipelines service
class Pipeline(object):
def parse(self, data):
raise NotImplemented('No ParserMixin used')
def compute(self, data, parsed_data):
raise NotImplemented('No ComputeMixin used')
def publish(self, data, parsed_data, computed_data):
raise NotImplemented('No PublisherMixin used')
def handle(self, data):
parsed_data = self.parse(data)
computed_data = self.compute(data, parsed_data)
return self.publish(data, parsed_data, computed_data)
Tuesday, June 25, 13
example mixins
class JSONParserMixin(Pipeline):
def parse(self, data):
return json.loads(data)
class AnnomizeDataMixin(Pipeline):
def compute(self, data, parsed_data):
return {}
class SuperSecureEncryptDataMixin(Pipeline):
def compute(self, data, parsed_data):
return parsed_data.encode('rot13')
class HTTPPublisher(Pipeline):
def publish(self, data, parsed_data, computed_data):
u = urllib2.urlopen(self.dat_url, computed_data)
return u
class FilePublisher(Pipeline):
def publish(self, data, parsed_data, computed_data):
with open(self.output, 'a') as f:
f.write(computed_data)
Tuesday, June 25, 13
final pipeline service
class JSONAnnonHTTPPipeline(
JSONParserMixin,
AnnomizeDataMixin,
HTTPPublisherMixin):
pass
class JSONSecureHTTPPipeline(
JSONParserMixin,
SuperSecureEncyptionMixin,
HTTPPublisherMixin):
pass
class JSONAnnonFilePipeline(
JSONParserMixin,
AnnomizeDataMixin,
FilePublisherMixin):
pass
Tuesday, June 25, 13
what about tests?
class JSONAnnonHTTPPipelineTest(
BasePipelineTest,
JSONParserMixinTest,
AnnomizeDataMixinTest,
HTTPPublisherMixinTest):
pass
Tuesday, June 25, 13
open source as output
๏ we have lots of open source stuff
๏ sentry for errors
๏ nydus (for redis connections)
๏ django-mailviews
๏ gargoyle (and v2.0 renamed to gutter)
๏ and more! https://github.com/disqus/
๏ not yet for disqus-service
๏ but I want your feedback!
๏ would you use actually it?
Tuesday, June 25, 13
psst, we’re hiring
disqus.com/jobs
If this was
interesting to you...
Tuesday, June 25, 13
psst, we’re hiring
disqus.com/jobs
meetup.com/ArchCamp
meetup.com/Disqus
Tuesday, June 25, 13
What did I just talk about?
๏ Lots of python at Disqus!
๏ But not all of it
๏ because sometimes other tools are better
๏ Services are awesome
๏ Mixins make testing super easy
๏ And we don’t have all the answers...
Tuesday, June 25, 13
questions?
๏ How do you run services?
๏ RPC vs HTTP vs Queues (I like queues)
๏ what do you use for highly concurrent
systems?
๏ do you lint for print or pdb.settrace() or
import debug
๏ if yes, can I have it?
๏ dev != prod, or does it?
๏ if you run uwsgi + nginx in prod
๏ why dev with ./manage.py runserver?
@NorthIsUp
Tuesday, June 25, 13

Mais conteúdo relacionado

Destaque

Android security model
Android security modelAndroid security model
Android security modelrrand1
 
Analysis and research of system security based on android
Analysis and research of system security based on androidAnalysis and research of system security based on android
Analysis and research of system security based on androidRavishankar Kumar
 
Clean architecture on Android
Clean architecture on AndroidClean architecture on Android
Clean architecture on AndroidGDG Odessa
 
Android seminar report
Android seminar reportAndroid seminar report
Android seminar reportdgpune
 
Permission in Android Security: Threats and solution
Permission in Android Security: Threats and solutionPermission in Android Security: Threats and solution
Permission in Android Security: Threats and solutionTandhy Simanjuntak
 
Clean architecture: Android
Clean architecture: AndroidClean architecture: Android
Clean architecture: Androidintive
 
Testing Android Security Codemotion Amsterdam edition
Testing Android Security Codemotion Amsterdam editionTesting Android Security Codemotion Amsterdam edition
Testing Android Security Codemotion Amsterdam editionJose Manuel Ortega Candel
 
Android Security
Android SecurityAndroid Security
Android SecurityLars Jacobs
 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in AndroidOpersys inc.
 
Resep jadi rockstar developer
Resep jadi rockstar developerResep jadi rockstar developer
Resep jadi rockstar developerrendra toro
 
Android - Model Architecture
Android - Model ArchitectureAndroid - Model Architecture
Android - Model Architecturerendra toro
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with NougatOpersys inc.
 
Mobile Commerce: A Security Perspective
Mobile Commerce: A Security PerspectiveMobile Commerce: A Security Perspective
Mobile Commerce: A Security PerspectivePragati Rai
 

Destaque (16)

Android security model
Android security modelAndroid security model
Android security model
 
Analysis and research of system security based on android
Analysis and research of system security based on androidAnalysis and research of system security based on android
Analysis and research of system security based on android
 
Clean architecture on Android
Clean architecture on AndroidClean architecture on Android
Clean architecture on Android
 
Android seminar report
Android seminar reportAndroid seminar report
Android seminar report
 
Permission in Android Security: Threats and solution
Permission in Android Security: Threats and solutionPermission in Android Security: Threats and solution
Permission in Android Security: Threats and solution
 
Clean architecture: Android
Clean architecture: AndroidClean architecture: Android
Clean architecture: Android
 
Android sandbox
Android sandboxAndroid sandbox
Android sandbox
 
Testing Android Security Codemotion Amsterdam edition
Testing Android Security Codemotion Amsterdam editionTesting Android Security Codemotion Amsterdam edition
Testing Android Security Codemotion Amsterdam edition
 
Android Security
Android SecurityAndroid Security
Android Security
 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in Android
 
Resep jadi rockstar developer
Resep jadi rockstar developerResep jadi rockstar developer
Resep jadi rockstar developer
 
Android - Model Architecture
Android - Model ArchitectureAndroid - Model Architecture
Android - Model Architecture
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with Nougat
 
Android report
Android reportAndroid report
Android report
 
Mobile Commerce: A Security Perspective
Mobile Commerce: A Security PerspectiveMobile Commerce: A Security Perspective
Mobile Commerce: A Security Perspective
 
Android ppt
Android ppt Android ppt
Android ppt
 

Mais de Marakana Inc.

Android Services Black Magic by Aleksandar Gargenta
Android Services Black Magic by Aleksandar GargentaAndroid Services Black Magic by Aleksandar Gargenta
Android Services Black Magic by Aleksandar GargentaMarakana Inc.
 
Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven DevelopmentMarakana Inc.
 
Martin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMartin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMarakana Inc.
 
Why Java Needs Hierarchical Data
Why Java Needs Hierarchical DataWhy Java Needs Hierarchical Data
Why Java Needs Hierarchical DataMarakana Inc.
 
Pictures from "Learn about RenderScript" meetup at SF Android User Group
Pictures from "Learn about RenderScript" meetup at SF Android User GroupPictures from "Learn about RenderScript" meetup at SF Android User Group
Pictures from "Learn about RenderScript" meetup at SF Android User GroupMarakana Inc.
 
Android UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesAndroid UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesMarakana Inc.
 
2010 07-18.wa.rails tdd-6
2010 07-18.wa.rails tdd-62010 07-18.wa.rails tdd-6
2010 07-18.wa.rails tdd-6Marakana Inc.
 
Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6Marakana Inc.
 
Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)Marakana Inc.
 
What's this jQuery? Where it came from, and how it will drive innovation
What's this jQuery? Where it came from, and how it will drive innovationWhat's this jQuery? Where it came from, and how it will drive innovation
What's this jQuery? Where it came from, and how it will drive innovationMarakana Inc.
 
jQuery State of the Union - Yehuda Katz
jQuery State of the Union - Yehuda KatzjQuery State of the Union - Yehuda Katz
jQuery State of the Union - Yehuda KatzMarakana Inc.
 
Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...
Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...
Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...Marakana Inc.
 
Efficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram ArnoldEfficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram ArnoldMarakana Inc.
 
Efficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram ArnoldEfficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram ArnoldMarakana Inc.
 
Learn about JRuby Internals from one of the JRuby Lead Developers, Thomas Enebo
Learn about JRuby Internals from one of the JRuby Lead Developers, Thomas EneboLearn about JRuby Internals from one of the JRuby Lead Developers, Thomas Enebo
Learn about JRuby Internals from one of the JRuby Lead Developers, Thomas EneboMarakana Inc.
 
Replacing Java Incrementally
Replacing Java IncrementallyReplacing Java Incrementally
Replacing Java IncrementallyMarakana Inc.
 
Learn to Build like you Code with Apache Buildr
Learn to Build like you Code with Apache BuildrLearn to Build like you Code with Apache Buildr
Learn to Build like you Code with Apache BuildrMarakana Inc.
 
Learn How to Unit Test Your Android Application (with Robolectric)
Learn How to Unit Test Your Android Application (with Robolectric)Learn How to Unit Test Your Android Application (with Robolectric)
Learn How to Unit Test Your Android Application (with Robolectric)Marakana Inc.
 
Learn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDBLearn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDBMarakana Inc.
 

Mais de Marakana Inc. (20)

Android Services Black Magic by Aleksandar Gargenta
Android Services Black Magic by Aleksandar GargentaAndroid Services Black Magic by Aleksandar Gargenta
Android Services Black Magic by Aleksandar Gargenta
 
JRuby at Square
JRuby at SquareJRuby at Square
JRuby at Square
 
Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven Development
 
Martin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMartin Odersky: What's next for Scala
Martin Odersky: What's next for Scala
 
Why Java Needs Hierarchical Data
Why Java Needs Hierarchical DataWhy Java Needs Hierarchical Data
Why Java Needs Hierarchical Data
 
Pictures from "Learn about RenderScript" meetup at SF Android User Group
Pictures from "Learn about RenderScript" meetup at SF Android User GroupPictures from "Learn about RenderScript" meetup at SF Android User Group
Pictures from "Learn about RenderScript" meetup at SF Android User Group
 
Android UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesAndroid UI Tips, Tricks and Techniques
Android UI Tips, Tricks and Techniques
 
2010 07-18.wa.rails tdd-6
2010 07-18.wa.rails tdd-62010 07-18.wa.rails tdd-6
2010 07-18.wa.rails tdd-6
 
Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6
 
Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)
 
What's this jQuery? Where it came from, and how it will drive innovation
What's this jQuery? Where it came from, and how it will drive innovationWhat's this jQuery? Where it came from, and how it will drive innovation
What's this jQuery? Where it came from, and how it will drive innovation
 
jQuery State of the Union - Yehuda Katz
jQuery State of the Union - Yehuda KatzjQuery State of the Union - Yehuda Katz
jQuery State of the Union - Yehuda Katz
 
Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...
Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...
Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...
 
Efficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram ArnoldEfficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram Arnold
 
Efficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram ArnoldEfficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram Arnold
 
Learn about JRuby Internals from one of the JRuby Lead Developers, Thomas Enebo
Learn about JRuby Internals from one of the JRuby Lead Developers, Thomas EneboLearn about JRuby Internals from one of the JRuby Lead Developers, Thomas Enebo
Learn about JRuby Internals from one of the JRuby Lead Developers, Thomas Enebo
 
Replacing Java Incrementally
Replacing Java IncrementallyReplacing Java Incrementally
Replacing Java Incrementally
 
Learn to Build like you Code with Apache Buildr
Learn to Build like you Code with Apache BuildrLearn to Build like you Code with Apache Buildr
Learn to Build like you Code with Apache Buildr
 
Learn How to Unit Test Your Android Application (with Robolectric)
Learn How to Unit Test Your Android Application (with Robolectric)Learn How to Unit Test Your Android Application (with Robolectric)
Learn How to Unit Test Your Android Application (with Robolectric)
 
Learn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDBLearn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDB
 

Último

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Último (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

Learn How Disqus Does 'It' When 'It' Isn't Django

  • 1. Adam Hitchcock @NorthIsUp How DISQUS does ‘it’ when ‘it’ isn’t Django Tuesday, June 25, 13
  • 3. we’re hiring disqus.com/jobs If this is interesting to you... Tuesday, June 25, 13
  • 6. DISQUS sees a lot of traffic Google Analytics: Feb 2013 - March 2013 Tuesday, June 25, 13
  • 7. what makes up Disqus? Tuesday, June 25, 13
  • 11. and we love it! Tuesday, June 25, 13
  • 12. why python? ๏ because it is fast… ๏ to develop in ๏ good community ๏ lots of libraries ๏ so active we can’t keep up with it ๏ is anybody using 3.3 yet? ๏ Disqus has a really good dev loop for it Tuesday, June 25, 13
  • 13. how does our dev loop work? ๏ diff code (with phabricator) ๏ get that reviewed ๏ review with phabricator ๏ ci done by jenkins ๏ land it on master (git push) ๏ wait for the daily deploy (ops team) ๏ and we are moving to autodeploy (we’ll revisit this one) Tuesday, June 25, 13
  • 14. break it down. ๏ mostly Django ๏ two years ago 95% Django* ๏ today ~70% Django* ๏ what is in that growing gap? ๏ *totally made up numbers Tuesday, June 25, 13
  • 15. how does this actually work at Disqus? Tuesday, June 25, 13
  • 16. disqus-web (kinda monolithic) ๏ Django + celery on postgres + rabbit ๏ we roll up commits for a deploy ๏ risk of revert that isn’t your fault ๏ you bring down the whole thing if you forgot to remove that pdb.settrace() ๏ high scrutiny in code review (see above) ๏ high volume of code review (code review RTT can be a full day) ๏ lots of legacy code to work around (and not break) Tuesday, June 25, 13
  • 17. problems that don’t fit ๏ high concurrency ๏ isolation ๏ feature ๏ failure ๏ speed (cpu cycles) ๏ speed (dev iteration cycle) ๏ fun Tuesday, June 25, 13
  • 18. what did we play with? Tuesday, June 25, 13
  • 19. for fun and concurrency! ๏ nginx + nginx-modules ๏ https://speakerdeck.com/northisup/ scaling-realtime-at-disqus?slide=39 ๏ nginx + lua ๏ https://github.com/NorthIsUp/nginx- oauth-on-dotcloud/blob/master/nginx/ access.persona.lua.in ๏ go ๏ http://blog.disqus.com/post/ 51155103801/trying-out-this-go-thing Tuesday, June 25, 13
  • 20. embedly in nginx + lua local http = require "resty.http" local cjson = require "cjson" local url = "https://api.embed.ly/1/oembed?key=" .. ngx.var.api_key .. "&url=" .. ngx.var.url local hc = http:new() local ok, code, headers, status, body = hc:request { url = url, method = "GET" } if code ~= 200 then ngx.exit(code) end local thumbnail = cjson.decode(body).thumbnail_url ngx.var.thumbnail = thumbnail Tuesday, June 25, 13
  • 21. python still works too Tuesday, June 25, 13
  • 22. isolation and iteration speed ๏ failure should be isolated to a small service ๏ successes should be allowed to occur quickly ๏ python is still great for these use cases Tuesday, June 25, 13
  • 23. when we needed it right now! ๏ if __name__ == ‘__main__’: ๏ from wsgiref.simple_server import make_server ๏ from xmlrpclib import ServerProxy Tuesday, June 25, 13
  • 24. it works great! ๏ for one deploy ๏ then you have to update it… Tuesday, June 25, 13
  • 25. lessons ๏ consistency is good! ๏ protects you from somebody quitting or getting hit by a bus ๏ anybody can just pick it up and run ๏ simplicity is good! ๏ modularity is good ๏ the ability to borrow/combine features from other projects ๏ but copypasta is bad ๏ and not bugging ops for a deploy is the Tuesday, June 25, 13
  • 27. disqus-service ๏ the goal is consistent/free access to… ๏ config ๏ switches ๏ logging ๏ stats ๏ other systems ๏ and should be easy to run Tuesday, June 25, 13
  • 28. @service ๏ equivalent to if __name__ == ‘__main__’: ๏ that is basically it, you can now run it Tuesday, June 25, 13
  • 29. hello.py from disqus.service.application import service @service def world(): print "hello world" $ toil run hello.world hello world Tuesday, June 25, 13
  • 30. but you want more power ๏ class Service: ๏ @handler ๏ @pre_config ๏ @post_config ๏ @pre_setup ๏ @post_setup ๏ @pre_update_config ๏ @post_update_config Tuesday, June 25, 13
  • 31. hello-v2.0.py from disqus.service.application import (Service, handler, post_config) def World(Service): @handler def world(self): print self.redis.get("hello world") @post_config def setup_redis(self) self.redis = Redis( host=self.config.REDIS_HOST, port=self.config.REDIS_PORT ) world = World() Tuesday, June 25, 13
  • 32. mixins! ๏ FlaskService ๏ the service instance is also a wsgi app ๏ GeventService ๏ concurrency helpers ๏ RedisService ๏ KafkaService ๏ DjangoORMService (currently in progress) Tuesday, June 25, 13
  • 33. real life Disqus code! from __future__ import absolute_import from IPython.frontend.terminal.embed import InteractiveShellEmbed from disqus.service.application import handler import tempest from tempest.services.mixins.data import RedisMixin class Shell(RedisMixin): @handler def shell(self, *args, **kwargs): """ runs an ipython shell loaded in the tempest module """ ipshell = InteractiveShellEmbed() ipshell(local_ns=locals(), global_ns=globals(), module=tempest) shell = Shell() Tuesday, June 25, 13
  • 34. I want to talk more about mixins, because I really like them. So the following slides are about mixins, but not about services. Please use your imagination that I did not just copypasta them from my pycon slides Tuesday, June 25, 13
  • 35. data pipelines service class Pipeline(object): def parse(self, data): raise NotImplemented('No ParserMixin used') def compute(self, data, parsed_data): raise NotImplemented('No ComputeMixin used') def publish(self, data, parsed_data, computed_data): raise NotImplemented('No PublisherMixin used') def handle(self, data): parsed_data = self.parse(data) computed_data = self.compute(data, parsed_data) return self.publish(data, parsed_data, computed_data) Tuesday, June 25, 13
  • 36. example mixins class JSONParserMixin(Pipeline): def parse(self, data): return json.loads(data) class AnnomizeDataMixin(Pipeline): def compute(self, data, parsed_data): return {} class SuperSecureEncryptDataMixin(Pipeline): def compute(self, data, parsed_data): return parsed_data.encode('rot13') class HTTPPublisher(Pipeline): def publish(self, data, parsed_data, computed_data): u = urllib2.urlopen(self.dat_url, computed_data) return u class FilePublisher(Pipeline): def publish(self, data, parsed_data, computed_data): with open(self.output, 'a') as f: f.write(computed_data) Tuesday, June 25, 13
  • 37. final pipeline service class JSONAnnonHTTPPipeline( JSONParserMixin, AnnomizeDataMixin, HTTPPublisherMixin): pass class JSONSecureHTTPPipeline( JSONParserMixin, SuperSecureEncyptionMixin, HTTPPublisherMixin): pass class JSONAnnonFilePipeline( JSONParserMixin, AnnomizeDataMixin, FilePublisherMixin): pass Tuesday, June 25, 13
  • 38. what about tests? class JSONAnnonHTTPPipelineTest( BasePipelineTest, JSONParserMixinTest, AnnomizeDataMixinTest, HTTPPublisherMixinTest): pass Tuesday, June 25, 13
  • 39. open source as output ๏ we have lots of open source stuff ๏ sentry for errors ๏ nydus (for redis connections) ๏ django-mailviews ๏ gargoyle (and v2.0 renamed to gutter) ๏ and more! https://github.com/disqus/ ๏ not yet for disqus-service ๏ but I want your feedback! ๏ would you use actually it? Tuesday, June 25, 13
  • 40. psst, we’re hiring disqus.com/jobs If this was interesting to you... Tuesday, June 25, 13
  • 42. What did I just talk about? ๏ Lots of python at Disqus! ๏ But not all of it ๏ because sometimes other tools are better ๏ Services are awesome ๏ Mixins make testing super easy ๏ And we don’t have all the answers... Tuesday, June 25, 13
  • 43. questions? ๏ How do you run services? ๏ RPC vs HTTP vs Queues (I like queues) ๏ what do you use for highly concurrent systems? ๏ do you lint for print or pdb.settrace() or import debug ๏ if yes, can I have it? ๏ dev != prod, or does it? ๏ if you run uwsgi + nginx in prod ๏ why dev with ./manage.py runserver? @NorthIsUp Tuesday, June 25, 13