SlideShare une entreprise Scribd logo
1  sur  70
PythonIn Large Companies? SébastienTandel sebastien.tandel@corp.terra.com.br sebastien.tandel@gmail.com
Plan About Terra The 7 steps Prototype Define the Goals Integration Some Libs Prove It Works Evangelize Next Steps Conclusions
About Terra : Web Portal Largest Latin American web portal Located in 18 countries 1000s of servers Brazil : ~7M unique visitors / day ~70M pageviews / day
About Terra Source: Nielsen NetView (June 2009)
About Terra : Email Plaftorm I’m part of the email team. Some stats :  +10M mailboxes +30M inbound emails per day +30M outbound emails per day avg : 300 mail/s, peak : 600 mail/s Systems Main systems : SMTP, LMTP, POP, IMAP, Webmail Total of +30 systems to design/develop/maintain Main languages used C / C++
About Terra ,[object Object],PHP, C, C++, Java, C#, Erlang ,[object Object]
No official “scripting” language (Python, Perl or other)Why? From what I hear Performance Integration with others systems (& legacy) Costs / benefits? Buzzword fear Labor market
Flash Python Overview Python is … Interpreted Dynamically Typed Really Concise Multi-paradigm : procedural, OO, functional Exceptions : helpful for robustness, debug (no strace ;)) Garbage Collector : don’t worry about allocation/free
Step 1 : Prototype
Step 1 : Prototype Buggy system re-written as prototype in Python Surprise! Worked a lot better than its C cousin Prototype is now in production! Spread the word about this rewrite around me Some technical people liked the idea One has not been so enthusiast … my manager Cons:  no integration with homemade systems Just one example
Step 1 : Prototype Introducing new ideas is a long and though way
Step 2 : Define the Goals Performance critical systems :  postfix, lmtp, imap / pop
Step 2 : Define the Goals ,[object Object],Web-based systems Webmail, ECP
Step 2 : Define the Goals ,[object Object]
Web-based systemsBackend systems : spamreporter, cleaner, clx trainer, base trainer, mfsbuilder, migrador, nnentrega, smigol, …
Step 2 : Define the Goals ,[object Object]
Web-based systems
Backend systemsAlmost inexistent systems (though interesting ones) : Mailboxes stats, logs analysis (stats and user behavior characterization)
Step 2 : Define the Goals ,[object Object]
Web-based systems
Backend systems
Stats / User behavior characterization, …System / Integration tests scripts
Step 2 : Define the Goals ,[object Object]
Web-based systems
Backend systems
Stats / User behavior characterization, …
System / Integration tests scriptsThe Grail : ,[object Object],[object Object]
Step 3 : Integration Python could be used with every systems but how can I interface with the homemade systems (legacy) ? 
Step 3 : Integration Various way to create Python Bindings : Python C API: the “hard” way
Step 3 : Integration Various way to create Python Bindings : Python C API: the “hard” way swig : the lazy way  won’t create a Pythonic API for you
Step 3 : Integration Various way to create Python Bindings : Python C API : the “hard” way swig : the lazy way ctypes: the stupidly easy way from ctypes import cdll l = cdll.LoadLibrary(“libc.so.6”) l.mkdir(“python-mkdir-test”)
Step 3 : Integration Various way to create Python Bindings : Python C API : the “hard” way swig : the lazy way  ctypes : the stupidly easy way Cython : write python, compile with gcc
Step 3 : Integration Wrote bindings to interface with all major internal systems (thanks to ctypes) With pythonic API! 
Step 3 : Integration   from trrauth import TrrAuth auth = TrrAuth(“IMAP”)auth.open_userpass(“standel”, “1q2w3e”, “terra”) auth.attributes = [ “short_name”, “id_perm”, “antispam” ]
Step 3 : Integration   from trrauth import TrrAuth auth = TrrAuth(“IMAP”)auth.open_userpass(“standel”, “1q2w3e”, “terra”) auth.attributes = [ “short_name”, “id_perm”, “antispam” ] 	print auth.short_name, “:”, auth.id_perm
Step 3 : Integration   from trrauth import TrrAuth auth= TrrAuth(“IMAP”)auth.open_userpass(“standel”, “1q2w3e”, “terra”) auth.attributes = [ “short_name”, “id_perm”, “antispam” ] for attr, value in auth:  print attr, “:”, value
Step 4 : Some Libs
Step 4 : Some LibsMaster / Slave Master responsible for : Forking the slaves Reading a “list” of tasks Distribution of the tasks to the slaves Slave responsible for : Execution of the task Return execution status to the master Key characteristics : Slave death detection Handle unhandled exceptions(+ hook) Master <-> slave protocol allows temporary error code Timeout of the tasks
Step 4 : Some LibsMaster / Slave One neat characteristic : System might got bug in prod w/ minimal impact If unhandled exception occurs Only one slave dies It is detected and master will fork a new one (if needed) The lib handles the exception : Default behavior : prints to console User defined (callback) : e.g. write the stack trace to a file! Cherry on the cake : getting specific production data about faulty task
from robustpools.process_pool import master_task_list from robustpools.process_pool import slave_task_list m_config = { 'INFINITE_LOOP' : 0 } class list_task(object):   def __init__(self, list, num, timeout_validity=600): self.__num = num   def _id(self):     return self.__num   id = property(_id)  class list_slave(slave_task_list):   def __init__(self): super(list_slave, self).__init__(list_task)   def run(self, task):     print task.id     return 0, "ok” list = xrange(10) m = master_task_list(list, num_slave=5, slave_class=list_slave, config=m_config) m.start()
Step 4 : Some LibsTCP Sockets Pool Manage connections to a pool of servers send in a round-robin/priority way to each server Detect connection errors Retry to connect Number of retries limited => after mark as dead Retry again later with exponential backoff
Step 5 : Prove It Works
Step 5 : Prove It Works Prove = collect data … How? Write integrated systems using bindings and libs of previous steps. Show it works  Performance Productivity
Step 5 : Prove It Works Performance, one obvious thought : C/C++ PINCS Performance is not C, Stupid!
Step 5 : Prove It WorksPerformance Some of the rewrites works faster than C/C++ cousins Why? OS / Systems limits Libs (legacy) Algorithms Software Architecture Infrastructure
Step 5 : Prove It WorksProductivity BTW, pure performance so important? Time to Market much more important Adopt Lean Thinking and eliminate every possible waste ,[object Object],Loose time when writing Increase # bugs More time to maintain More time to know code base (think to new employees) ,[object Object],[object Object]
Step 5 : Prove It WorksProductivity http://page.mi.fu-berlin.de/prechelt/Biblio/jccpprt2_advances2003.pdf
Step 5 : Prove It WorksProductivity http://www.ohloh.net
Step 5 : Prove It WorksProductivity http://www.ohloh.net
Step 5 : Prove It WorksProductivity http://www.ohloh.net
Step 5 : Prove It WorksProductivity
Step 5 : Prove It WorksProductivity Some existing C/C++ systems re-written in Python Original C/C++ versions total of ~20.000 LOC  In Python, 4-6x less code ! The previous numbers do not seem to lie 
Step 5 : Prove It WorksProductivity Oh, parsing an email? Any idea in C/C++?
Step 5 : Prove It WorksProductivity ,[object Object],from email import message_from_file fh = open(filename, “r”) mail = message_from_file(fh) fh.close()
Step 5 : Prove It WorksProductivity ,[object Object],content types of parts? Any idea in C/C++ ? from email import message_from_file def get_mail(filename): fh = open(filename, “r”) mail = message_from_file(fh) fh.close() return mail mail = get_mail(filename)
Step 5 : Prove It WorksProductivity ,[object Object]
content types of partsfrom email import message_from_file def get_mail(filename): fh = open(filename, “r”) mail = message_from_file(fh) fh.close() return mail mail = get_mail(filename) for part in mail.walk(): 	print part.get_content_type()
Step 5 : Prove It WorksProductivity ,[object Object]
content types of parts
getting headers?
Any idea in C/C++?from email import message_from_file def get_mail(filename): fh = open(filename, “r”) mail = message_from_file(fh) fh.close() return mail mail = get_mail(filename) for part in mail.walk(): 	print part.get_content_type()
Step 5 : Prove It WorksProductivity ,[object Object]
content types of parts
getting headers
Python libs are just that simple!… and there are a lot! from email import message_from_file def get_mail(filename): fh = open(filename, “r”) mail = message_from_file(fh) fh.close() return mail mail = get_mail(filename) for part in mail.walk(): 	print part.get_content_type() print mail[“From”] print mail[“Subject”]
Step 5 : Prove It WorksPerformance (Again?) For equivalent architecture  (libs, algorithm, infrastructure) C is a best performer than Python!  Python Is Not C, Stupid!
Step 5 : Prove It WorksPerformance (Again?) Bottleneck discovered! PINCS! : think first to architecture!
Step 5 : Prove It WorksPerformance (Again?) Bottleneck discovered! ,[object Object],Ctypes/ Swig : python bindings Write your bottleneck in C / C++, use it in your python app
Step 5 : Prove It WorksPerformance (Again?) Bottleneck discovered! ,[object Object]
Ctypes : absurdly easy python bindingsCython: write python, obtain a gcc compiled lib

Contenu connexe

Tendances

Being Dangerous with Twig
Being Dangerous with TwigBeing Dangerous with Twig
Being Dangerous with TwigRyan Weaver
 
Flask RESTful Flask HTTPAuth
Flask RESTful Flask HTTPAuthFlask RESTful Flask HTTPAuth
Flask RESTful Flask HTTPAuthEueung Mulyana
 
Hands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkHands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkRyan Weaver
 
Flask Introduction - Python Meetup
Flask Introduction - Python MeetupFlask Introduction - Python Meetup
Flask Introduction - Python MeetupAreski Belaid
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Stephan Schmidt
 
Component and Event-Driven Architectures in PHP
Component and Event-Driven Architectures in PHPComponent and Event-Driven Architectures in PHP
Component and Event-Driven Architectures in PHPStephan Schmidt
 
Enjoying the Journey from Puppet 3.x to Puppet 4.x (PuppetConf 2016)
Enjoying the Journey from Puppet 3.x to Puppet 4.x (PuppetConf 2016)Enjoying the Journey from Puppet 3.x to Puppet 4.x (PuppetConf 2016)
Enjoying the Journey from Puppet 3.x to Puppet 4.x (PuppetConf 2016)Robert Nelson
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...Guillaume Laforge
 

Tendances (15)

Being Dangerous with Twig
Being Dangerous with TwigBeing Dangerous with Twig
Being Dangerous with Twig
 
Ruby
RubyRuby
Ruby
 
Flask RESTful Flask HTTPAuth
Flask RESTful Flask HTTPAuthFlask RESTful Flask HTTPAuth
Flask RESTful Flask HTTPAuth
 
Hands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkHands-on with the Symfony2 Framework
Hands-on with the Symfony2 Framework
 
Flask Introduction - Python Meetup
Flask Introduction - Python MeetupFlask Introduction - Python Meetup
Flask Introduction - Python Meetup
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
 
Flask Basics
Flask BasicsFlask Basics
Flask Basics
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
Component and Event-Driven Architectures in PHP
Component and Event-Driven Architectures in PHPComponent and Event-Driven Architectures in PHP
Component and Event-Driven Architectures in PHP
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
 
Enjoying the Journey from Puppet 3.x to Puppet 4.x (PuppetConf 2016)
Enjoying the Journey from Puppet 3.x to Puppet 4.x (PuppetConf 2016)Enjoying the Journey from Puppet 3.x to Puppet 4.x (PuppetConf 2016)
Enjoying the Journey from Puppet 3.x to Puppet 4.x (PuppetConf 2016)
 
FirePHP
FirePHPFirePHP
FirePHP
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
 

Similaire à Python For Large Company?

Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanizecoreygoldberg
 
Intro to the Salesforce Command Line Interface for Admins
Intro to the Salesforce Command Line Interface for AdminsIntro to the Salesforce Command Line Interface for Admins
Intro to the Salesforce Command Line Interface for AdminsSalesforce Admins
 
TDC 2015 - POA - Trilha PHP - Shit Happens
TDC 2015 - POA - Trilha PHP - Shit HappensTDC 2015 - POA - Trilha PHP - Shit Happens
TDC 2015 - POA - Trilha PHP - Shit HappensJackson F. de A. Mafra
 
Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Scott Keck-Warren
 
Software Project Management
Software Project ManagementSoftware Project Management
Software Project ManagementWidoyo PH
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfonyFrancois Zaninotto
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php PresentationAlan Pinstein
 
Scaling python webapps from 0 to 50 million users - A top-down approach
Scaling python webapps from 0 to 50 million users - A top-down approachScaling python webapps from 0 to 50 million users - A top-down approach
Scaling python webapps from 0 to 50 million users - A top-down approachJinal Jhaveri
 
OSMC 2021 | Robotmk: You don’t run IT – you deliver services!
OSMC 2021 | Robotmk: You don’t run IT – you deliver services!OSMC 2021 | Robotmk: You don’t run IT – you deliver services!
OSMC 2021 | Robotmk: You don’t run IT – you deliver services!NETWAYS
 
Easy Web Project Development & Management with Django & Mercurial
Easy Web Project Development & Management with Django & MercurialEasy Web Project Development & Management with Django & Mercurial
Easy Web Project Development & Management with Django & MercurialWidoyo PH
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 
The why and how of moving to php 8
The why and how of moving to php 8The why and how of moving to php 8
The why and how of moving to php 8Wim Godden
 
Claim Academy Intro to Programming
Claim Academy Intro to ProgrammingClaim Academy Intro to Programming
Claim Academy Intro to ProgrammingAlex Pearson
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsGraham Dumpleton
 
Monitoring your Python with Prometheus (Python Ireland April 2015)
Monitoring your Python with Prometheus (Python Ireland April 2015)Monitoring your Python with Prometheus (Python Ireland April 2015)
Monitoring your Python with Prometheus (Python Ireland April 2015)Brian Brazil
 
Back-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NETBack-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NETDavid McCarter
 
Back-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NETBack-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NETDavid McCarter
 
Designing the Call of Cthulhu app with Google App Engine
Designing the Call of Cthulhu app with Google App EngineDesigning the Call of Cthulhu app with Google App Engine
Designing the Call of Cthulhu app with Google App EngineChris Bunch
 
BSidesDC 2016 Beyond Automated Testing
BSidesDC 2016 Beyond Automated TestingBSidesDC 2016 Beyond Automated Testing
BSidesDC 2016 Beyond Automated TestingAndrew McNicol
 

Similaire à Python For Large Company? (20)

Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanize
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Intro to the Salesforce Command Line Interface for Admins
Intro to the Salesforce Command Line Interface for AdminsIntro to the Salesforce Command Line Interface for Admins
Intro to the Salesforce Command Line Interface for Admins
 
TDC 2015 - POA - Trilha PHP - Shit Happens
TDC 2015 - POA - Trilha PHP - Shit HappensTDC 2015 - POA - Trilha PHP - Shit Happens
TDC 2015 - POA - Trilha PHP - Shit Happens
 
Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023
 
Software Project Management
Software Project ManagementSoftware Project Management
Software Project Management
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Scaling python webapps from 0 to 50 million users - A top-down approach
Scaling python webapps from 0 to 50 million users - A top-down approachScaling python webapps from 0 to 50 million users - A top-down approach
Scaling python webapps from 0 to 50 million users - A top-down approach
 
OSMC 2021 | Robotmk: You don’t run IT – you deliver services!
OSMC 2021 | Robotmk: You don’t run IT – you deliver services!OSMC 2021 | Robotmk: You don’t run IT – you deliver services!
OSMC 2021 | Robotmk: You don’t run IT – you deliver services!
 
Easy Web Project Development & Management with Django & Mercurial
Easy Web Project Development & Management with Django & MercurialEasy Web Project Development & Management with Django & Mercurial
Easy Web Project Development & Management with Django & Mercurial
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
The why and how of moving to php 8
The why and how of moving to php 8The why and how of moving to php 8
The why and how of moving to php 8
 
Claim Academy Intro to Programming
Claim Academy Intro to ProgrammingClaim Academy Intro to Programming
Claim Academy Intro to Programming
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
 
Monitoring your Python with Prometheus (Python Ireland April 2015)
Monitoring your Python with Prometheus (Python Ireland April 2015)Monitoring your Python with Prometheus (Python Ireland April 2015)
Monitoring your Python with Prometheus (Python Ireland April 2015)
 
Back-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NETBack-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NET
 
Back-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NETBack-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NET
 
Designing the Call of Cthulhu app with Google App Engine
Designing the Call of Cthulhu app with Google App EngineDesigning the Call of Cthulhu app with Google App Engine
Designing the Call of Cthulhu app with Google App Engine
 
BSidesDC 2016 Beyond Automated Testing
BSidesDC 2016 Beyond Automated TestingBSidesDC 2016 Beyond Automated Testing
BSidesDC 2016 Beyond Automated Testing
 

Dernier

Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Dernier (20)

Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Python For Large Company?

  • 1. PythonIn Large Companies? SébastienTandel sebastien.tandel@corp.terra.com.br sebastien.tandel@gmail.com
  • 2. Plan About Terra The 7 steps Prototype Define the Goals Integration Some Libs Prove It Works Evangelize Next Steps Conclusions
  • 3. About Terra : Web Portal Largest Latin American web portal Located in 18 countries 1000s of servers Brazil : ~7M unique visitors / day ~70M pageviews / day
  • 4. About Terra Source: Nielsen NetView (June 2009)
  • 5. About Terra : Email Plaftorm I’m part of the email team. Some stats : +10M mailboxes +30M inbound emails per day +30M outbound emails per day avg : 300 mail/s, peak : 600 mail/s Systems Main systems : SMTP, LMTP, POP, IMAP, Webmail Total of +30 systems to design/develop/maintain Main languages used C / C++
  • 6.
  • 7. No official “scripting” language (Python, Perl or other)Why? From what I hear Performance Integration with others systems (& legacy) Costs / benefits? Buzzword fear Labor market
  • 8. Flash Python Overview Python is … Interpreted Dynamically Typed Really Concise Multi-paradigm : procedural, OO, functional Exceptions : helpful for robustness, debug (no strace ;)) Garbage Collector : don’t worry about allocation/free
  • 9. Step 1 : Prototype
  • 10. Step 1 : Prototype Buggy system re-written as prototype in Python Surprise! Worked a lot better than its C cousin Prototype is now in production! Spread the word about this rewrite around me Some technical people liked the idea One has not been so enthusiast … my manager Cons: no integration with homemade systems Just one example
  • 11. Step 1 : Prototype Introducing new ideas is a long and though way
  • 12. Step 2 : Define the Goals Performance critical systems : postfix, lmtp, imap / pop
  • 13.
  • 14.
  • 15. Web-based systemsBackend systems : spamreporter, cleaner, clx trainer, base trainer, mfsbuilder, migrador, nnentrega, smigol, …
  • 16.
  • 18. Backend systemsAlmost inexistent systems (though interesting ones) : Mailboxes stats, logs analysis (stats and user behavior characterization)
  • 19.
  • 22. Stats / User behavior characterization, …System / Integration tests scripts
  • 23.
  • 26. Stats / User behavior characterization, …
  • 27.
  • 28. Step 3 : Integration Python could be used with every systems but how can I interface with the homemade systems (legacy) ? 
  • 29. Step 3 : Integration Various way to create Python Bindings : Python C API: the “hard” way
  • 30. Step 3 : Integration Various way to create Python Bindings : Python C API: the “hard” way swig : the lazy way won’t create a Pythonic API for you
  • 31. Step 3 : Integration Various way to create Python Bindings : Python C API : the “hard” way swig : the lazy way ctypes: the stupidly easy way from ctypes import cdll l = cdll.LoadLibrary(“libc.so.6”) l.mkdir(“python-mkdir-test”)
  • 32. Step 3 : Integration Various way to create Python Bindings : Python C API : the “hard” way swig : the lazy way ctypes : the stupidly easy way Cython : write python, compile with gcc
  • 33. Step 3 : Integration Wrote bindings to interface with all major internal systems (thanks to ctypes) With pythonic API! 
  • 34. Step 3 : Integration from trrauth import TrrAuth auth = TrrAuth(“IMAP”)auth.open_userpass(“standel”, “1q2w3e”, “terra”) auth.attributes = [ “short_name”, “id_perm”, “antispam” ]
  • 35. Step 3 : Integration from trrauth import TrrAuth auth = TrrAuth(“IMAP”)auth.open_userpass(“standel”, “1q2w3e”, “terra”) auth.attributes = [ “short_name”, “id_perm”, “antispam” ] print auth.short_name, “:”, auth.id_perm
  • 36. Step 3 : Integration from trrauth import TrrAuth auth= TrrAuth(“IMAP”)auth.open_userpass(“standel”, “1q2w3e”, “terra”) auth.attributes = [ “short_name”, “id_perm”, “antispam” ] for attr, value in auth:  print attr, “:”, value
  • 37. Step 4 : Some Libs
  • 38. Step 4 : Some LibsMaster / Slave Master responsible for : Forking the slaves Reading a “list” of tasks Distribution of the tasks to the slaves Slave responsible for : Execution of the task Return execution status to the master Key characteristics : Slave death detection Handle unhandled exceptions(+ hook) Master <-> slave protocol allows temporary error code Timeout of the tasks
  • 39. Step 4 : Some LibsMaster / Slave One neat characteristic : System might got bug in prod w/ minimal impact If unhandled exception occurs Only one slave dies It is detected and master will fork a new one (if needed) The lib handles the exception : Default behavior : prints to console User defined (callback) : e.g. write the stack trace to a file! Cherry on the cake : getting specific production data about faulty task
  • 40. from robustpools.process_pool import master_task_list from robustpools.process_pool import slave_task_list m_config = { 'INFINITE_LOOP' : 0 } class list_task(object): def __init__(self, list, num, timeout_validity=600): self.__num = num def _id(self): return self.__num id = property(_id) class list_slave(slave_task_list): def __init__(self): super(list_slave, self).__init__(list_task) def run(self, task): print task.id return 0, "ok” list = xrange(10) m = master_task_list(list, num_slave=5, slave_class=list_slave, config=m_config) m.start()
  • 41. Step 4 : Some LibsTCP Sockets Pool Manage connections to a pool of servers send in a round-robin/priority way to each server Detect connection errors Retry to connect Number of retries limited => after mark as dead Retry again later with exponential backoff
  • 42. Step 5 : Prove It Works
  • 43. Step 5 : Prove It Works Prove = collect data … How? Write integrated systems using bindings and libs of previous steps. Show it works  Performance Productivity
  • 44. Step 5 : Prove It Works Performance, one obvious thought : C/C++ PINCS Performance is not C, Stupid!
  • 45. Step 5 : Prove It WorksPerformance Some of the rewrites works faster than C/C++ cousins Why? OS / Systems limits Libs (legacy) Algorithms Software Architecture Infrastructure
  • 46.
  • 47. Step 5 : Prove It WorksProductivity http://page.mi.fu-berlin.de/prechelt/Biblio/jccpprt2_advances2003.pdf
  • 48. Step 5 : Prove It WorksProductivity http://www.ohloh.net
  • 49. Step 5 : Prove It WorksProductivity http://www.ohloh.net
  • 50. Step 5 : Prove It WorksProductivity http://www.ohloh.net
  • 51. Step 5 : Prove It WorksProductivity
  • 52. Step 5 : Prove It WorksProductivity Some existing C/C++ systems re-written in Python Original C/C++ versions total of ~20.000 LOC In Python, 4-6x less code ! The previous numbers do not seem to lie 
  • 53. Step 5 : Prove It WorksProductivity Oh, parsing an email? Any idea in C/C++?
  • 54.
  • 55.
  • 56.
  • 57. content types of partsfrom email import message_from_file def get_mail(filename): fh = open(filename, “r”) mail = message_from_file(fh) fh.close() return mail mail = get_mail(filename) for part in mail.walk(): print part.get_content_type()
  • 58.
  • 61. Any idea in C/C++?from email import message_from_file def get_mail(filename): fh = open(filename, “r”) mail = message_from_file(fh) fh.close() return mail mail = get_mail(filename) for part in mail.walk(): print part.get_content_type()
  • 62.
  • 65. Python libs are just that simple!… and there are a lot! from email import message_from_file def get_mail(filename): fh = open(filename, “r”) mail = message_from_file(fh) fh.close() return mail mail = get_mail(filename) for part in mail.walk(): print part.get_content_type() print mail[“From”] print mail[“Subject”]
  • 66. Step 5 : Prove It WorksPerformance (Again?) For equivalent architecture (libs, algorithm, infrastructure) C is a best performer than Python!  Python Is Not C, Stupid!
  • 67. Step 5 : Prove It WorksPerformance (Again?) Bottleneck discovered! PINCS! : think first to architecture!
  • 68.
  • 69.
  • 70. Ctypes : absurdly easy python bindingsCython: write python, obtain a gcc compiled lib
  • 71.
  • 72. Ctypes : absurdly easy python bindings
  • 73. Cython: write python, obtain a gcc compiled libPsyco: JIT for python Just an additional module import in your code 2 – 100x times faster than normal Python Requires a bit more memory
  • 74.
  • 75. Ctypes : absurdly easy python bindings
  • 76. Cython: write python, obtain a gcc compiled lib
  • 77. Psyco: JIT for python
  • 78. Unladden Swallow : Google Project
  • 79. Produce a version of Python at least 5x faster
  • 80.
  • 81. Step 6 : Evangelize Once having stopped and look at what have been accomplished … Show it, Evangelize!
  • 82. Step 6 : Evangelize Because introducing a “new technology” is not just about teaching something to users. You’ve got to play the role of evangelist! Innovators (3.5%) New stuffs? they’re in!
  • 83.
  • 84.
  • 85. Early-adopters (12.5%)Early majority (35%) First, they must see the idea working
  • 86.
  • 88. Early majority (35%)Late majority (35%) Accept after lot of pressure, or imposed
  • 89.
  • 92. Late majority (35%)Laggard (14%) Never accept (why would I want to change?)
  • 93. Step 6 : Evangelize During work, I constantly spoke (a lot) to others Presentation on Python made for all Present to a large audience what has been done Open discussion Poster resuming what has been done Wiki page documenting Python stuffs Specific mailing-list related to Python
  • 94. Step 6 : Evangelize lot of work and slow process but I won some allies Some technical people are convinced that Python is useful Some managers are convinced that Python could be a good thing for Terra Starting evaluation in some specific cases
  • 95. Step 7 : Next Steps
  • 96. Step 7 : Next Steps Proven that Python could be useful in some cases. Don’t forget my Grail! The way has not ended … I’m lobbying to start using Python for web development. And again, I made a prototype
  • 97.
  • 98. Step 7 : Next Steps Login : Module auth already exists. Easy to tell django that authentication is required @login_required def list_abook(request, username): … login_requiredis a python decorator
  • 99. Step 7 : Next Steps Caching information (memcache, bd, file, …) 4 levels : Per site : one config line Per view : one python decorator @cache_page(60 * 15) def list_abook(request, username): … In templates : maybe better to let this one out!  Low-level cache access : cache.get(id) cache.set(id, value, timeout)
  • 100. Step 7 : Next Steps Address book Web Service Retrieve address book of one user, Add an account, Add an entry to the address book of a user, View all the address book entries, Output in HTML, JSON and CSV < 100 LOC 2 hours (w/o knowing the framework) Not one line of SQL just usefulcode
  • 101. Conclusions One year and a half … and Evangelization is not done yet! Email Team : Several systems have been written in Python and works really fine … even with the Terra high load! Web project should start right now People are starting using/learning it inside the company Some teams are starting evaluating Python Some Terra employees here at this conference!

Notes de l'éditeur

  1. C / C++ / Java a lot of projects … definitely references languagesC# going up but yet a few projectsRuby is not well established .. Yet? Only for web???Python has already a lot of projects and has the lowest LOC per project