Developing large-scale Applications in Python



Similar documents
Designing Large-Scale Applications in Python

Base One's Rich Client Architecture

Enterprise Application Monitoring with

Improving database development. Recommendations for solving development problems using Red Gate tools

WHITEPAPER. Improving database development

Dynamic Web Programming BUILDING WEB APPLICATIONS USING ASP.NET, AJAX AND JAVASCRIPT

zen Platform technical white paper

Building Applications Using Micro Focus COBOL

Son of SOA Resource-Oriented Computing Event-Driven Architecture

MS 20487A Developing Windows Azure and Web Services

11. Oracle Recovery Manager Overview and Configuration.

HOSTING PYTHON WEB APPLICATIONS. Graham Dumpleton PyCon Australia Sydney 2011

Course MS10975A Introduction to Programming. Length: 5 Days

Scalable Web Programming. CS193S - Jan Jannink - 1/12/10

Operating System Structures

PageScope Enterprise Suite 3.0

ios Cloud Development FOR Neal Goldstein WILEY John Wiley & Sons, Inc.

The Automatic HTTP Requests Logging and Replaying Subsystem for CMS Plone

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

MA-WA1920: Enterprise iphone and ipad Programming

CISC 275: Introduction to Software Engineering. Lab 5: Introduction to Revision Control with. Charlie Greenbacker University of Delaware Fall 2011

Monitoring Infrastructure for Superclusters: Experiences at MareNostrum

PHP on IBM i: What s New with Zend Server 5 for IBM i

WEB APPLICATION DEVELOPMENT. UNIT I J2EE Platform 9

Service Oriented Architecture

Integrity Checking and Monitoring of Files on the CASTOR Disk Servers

ZooKeeper. Table of contents

General principles and architecture of Adlib and Adlib API. Petra Otten Manager Customer Support

Parallel Databases. Parallel Architectures. Parallelism Terminology 1/4/2015. Increase performance by performing operations in parallel

Test Run Analysis Interpretation (AI) Made Easy with OpenLoad

Introducing Apache Pivot. Greg Brown, Todd Volkert 6/10/2010

Getting started with API testing

This course provides students with the knowledge and skills to develop ASP.NET MVC 4 web applications.

This module provides an overview of service and cloud technologies using the Microsoft.NET Framework and the Windows Azure cloud.

Siebel Application Deployment Manager Guide. Siebel Innovation Pack 2013 Version 8.1/8.2 September 2013

An Easier Way for Cross-Platform Data Acquisition Application Development

JMETER - MONITOR TEST PLAN

Service-Oriented Architecture and Software Engineering

BusinessObjects Enterprise XI Release 2 Administrator s Guide

Anwendungsintegration und Workflows mit UNICORE 6

Automate Your Deployment with Bamboo, Drush and Features DrupalCamp Scotland, 9 th 10 th May 2014

Programming in C# with Microsoft Visual Studio 2010

The Recipe for Sarbanes-Oxley Compliance using Microsoft s SharePoint 2010 platform

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

MOC DEVELOPING WINDOWS AZURE AND WEB SERVICES

CHAPTER - 5 CONCLUSIONS / IMP. FINDINGS

HP Operations Orchestration Software

Aspect-Oriented Programming

Pro<DOC/> e-commerce Technology An Introduction

HTML5. Turn this page to see Quick Guide of CTTC

Secure Web Appliance. Reverse Proxy

A Tool for Evaluation and Optimization of Web Application Performance

Liferay Portal User Guide. Joseph Shum Alexander Chow

Product Overview & New Features

Web4thejob. About Web4thejob. ZK x Web4thejob

September 18, Modular development in Magento 2. Igor Miniailo Magento

Continuous Integration

Architecture and Mode of Operation

Uniface Education Directory

Jitterbit Technical Overview : Microsoft Dynamics CRM

Developing Windows Azure and Web Services


SysPatrol - Server Security Monitor

Industrial Ethernet How to Keep Your Network Up and Running A Beginner s Guide to Redundancy Standards

Programmabilty. Programmability in Microsoft Dynamics AX Microsoft Dynamics AX White Paper

Chapter 13: Program Development and Programming Languages

Internet Engineering: Web Application Architecture. Ali Kamandi Sharif University of Technology Fall 2007

Ruby on Rails. a high-productivity web application framework. blog.curthibbs.us/ Curt Hibbs <curt@hibbs.com>

SchoolBooking SSO Integration Guide

Profiling and Testing with Test and Performance Tools Platform (TPTP)

scalability OneBridge

Introduction to Embedded Systems. Software Update Problem

Glassfish, JAVA EE, Servlets, JSP, EJB

TEST AUTOMATION FRAMEWORK

Course Syllabus: RIA Programming for Magic xpa 2.x Developers

Introducing ZENworks 11 SP4. Experience Added Value and Improved Capabilities. Article. Article Reprint. Endpoint Management

RESILIENT PRODUCT LIFECYCLE MANAGEMENT STRATEGIES & SOLUTIONS FOR FUTURE-PROOFING PLM

ProxySG TechBrief Implementing a Reverse Proxy

Chapter 1. Introduction to ios Development. Objectives: Touch on the history of ios and the devices that support this operating system.

aaps algacom Account Provisioning System

Crawl Proxy Installation and Configuration Guide

Understanding Evolution's Architecture A Technical Overview

Why Threads Are A Bad Idea (for most purposes)

How To Write A Windows Operating System (Windows) (For Linux) (Windows 2) (Programming) (Operating System) (Permanent) (Powerbook) (Unix) (Amd64) (Win2) (X

Course Syllabus: RIA Programming for unipaas V1.x Developers

Donky Technical Overview

E-Commerce Installation and Configuration Guide

Internet Information TE Services 5.0. Training Division, NIC New Delhi

Introduction to Service Oriented Architectures (SOA)

SCALABILITY AND AVAILABILITY

Data Sheet VISUAL COBOL WHAT S NEW? COBOL JVM. Java Application Servers. Web Tools Platform PERFORMANCE. Web Services and JSP Tutorials

Enterprise Content Management System Monitor. How to deploy the JMX monitor application in WebSphere ND clustered environments. Revision 1.

Delivery. Continuous. Jez Humble and David Farley. AAddison-Wesley. Upper Saddle River, NJ Boston Indianapolis San Francisco

City of Dublin Education & Training Board. Programme Module for. Mobile Technologies. leading to. Level 6 FETAC. Mobile Technologies 6N0734

Transcription:

Developing large-scale Applications in Python Lessons learned from 10 years of Python Application Design LSM Conference 2005 Dijon, France Marc-André Lemburg EGENIX.COM Software GmbH Germany

Speaker Introduction: Marc-André Lemburg Large-Scale Applications in Python CEO egenix.com and Consultant More than 20 years software experience Diploma in Mathematics Expert in Python, OOP, Web Technologies and Unicode Python Core Developer Python Software Foundation Board Member (2002-04) Contact: mal@egenix.com egenix.com Software GmbH, Germany Founded in 2000 Core business: Consulting: helping companies write successful Python software Product design: professional quality Python/Zope developer tools (mxodbc, mxdatetime, mxtexttools, etc.) International customer base 2

Agenda 1. Introduction 2. Application Design 3. Before you start 4. Discussion 3

Introduction 1. Introduction 2. Application Design 3. Before you start 4. Discussion 4

Designing Python Applications Python makes it very easy to write complex applications with very little code It s easy to create bad designs fast Rewriting code is fast as well Application design becomes the most important factor in Python projects This talk presents a general approach to the problem which is not necessarily specific to Python 5

Large-scale applications What is considered large-scale in Python? Server application: >30 thousand lines of Python code Client application: >10 thousand lines of Python code Third-Party code: >10 thousand lines of code Typically a mix of Python code and C extensions Examples: Zope / Plone egenix Application Server egenix projects: e.g. Web Service Application Server, XML Database, ASP Trading System 6

Why write large-scale applications in Python? Highly efficient small teams can scale up against large companies very competitive turn-around times small investments can result in high gains Very flexible Large-Scale Applications in Python allows rapid design, refactoring and rollout highly adaptive to new requirements and environments no lock-in Time-to-market develop in weeks rather than months 7

Application Design 1. Introduction 2. Application Design 3. Before you start 4. Discussion 8

The Design Concept Structured approach to application design Divide et Impera (divide and conquer) Lots and lots of experience The Zen in application design Keep things as simple as possible, but not simpler (KISS). There s beauty in design. Before doing things twice, think twice. If things start to pile up, management is needed. If management doesn t help, decomposition is needed. 9

Divide et Impera: Steps in the design Large-Scale Applications in Python Goal: Break down complexity as far as possible! Top-down method: 1. Application model 2. Processing model 3. Layer model 4. Components 5. Management objects 6. Data and Task objects 10

Choose a suitable application model Large-Scale Applications in Python Client-Server Client application / Server application Web client / Server application Multi-threaded stand-alone Stand-alone GUI application Single process GUI Client Server Event Handler Business Logic etc. Command-line application Batch job application Input Processor Output 11

Identify the processing model Identify the processing scheme: Single process Multiple processes Multiple threads Asynchronous processing A mix of the above Identify the process/thread boundaries: Which components (need to) share the same object space? Where is state kept? What defines an application instance? Process 1 Interface Logic Process 2 Server Logic Application Interface Logic Logic Process 3 Storage Server Logic Logic Application Interface Logic Logic Storage Server Logic Logic Application Logic Storage Logic 12

Layer model Every application can be divided into layers of functionality defined by the flow of data through the application Top layer: interface to the outside world Intermediate layers: administration and processing Bottom layer: data storage Layers are usually easy to identify given the application model but often hard to design Application Interface Logic Administration Logic Application Logic Storage Logic 13

Examples of layer models GUI / Application Logic / Storage Logic Network / Apache / SCGI / Server Logic / Application Logic / Storage Logic File I/O / Application Logic / Storage Logic Client Web Browser Server Interface Logic Server Logic Application Logic Storage Logic Custom model 14

Example Web Client + Server Application: Problem Situation: Client is a standard web-browser Server needs to take a lot of load and will have to do all the calculation work Server needs to be fail-safe Server is connected to a database 15

Example Web Client + Server Application: Solution Solution: Client Client Client Application model: client-server Processing model: multiple process model Layer model: typical application server layers Web Browser Server Process Interface Logic Server Logic Application Logic Storage Logic Web Browser Apache Web Server Multiple Process Broker SCGI Server Process Interface Logic Server Logic Application Logic Storage Logic Web Browser Server Process Interface Logic Server Logic Application Logic Storage Logic Database 16

Divide et Impera: Layers are still too complex Large-Scale Applications in Python Goal: Break down complexity as far as possible! Top-down approach: 1. Application model 2. Processing model 3. Layer model 4. Components 5. Management objects 6. Data and Task objects 17

Breaking layers into smaller pieces: Components Layers provide a data driven separation of functionality Problem: The level of complexity is usually too high to implement these in one piece of code Solution: build layers using a set of loosely coupled components 18

Component design Components should encapsulate higher level concepts within the application Components provide independent building blocks for the application 19

Component examples Components provide the database interface implement the user management implement the session management provide caching facilities interface to external data sources provide error handling facilities enable logging management etc. 20

Advantages of components: Easily replaceable Large-Scale Applications in Python They should be easily replaceable to adapt the application to new requirements, e.g. porting the application to a new database backend, using a new authentication mechanism, etc. If implemented correctly, they will even allow switching to different processing model should the need arise 21

Advantages of components: Loose coupling Large-Scale Applications in Python Loose coupling of the components makes it possible to refine the overall application design, refactor parts of the layer logic or add new layers without having to rewrite large parts of the application code 22

Component implementation Each component is represented by a component object Component interfaces must be simple and high-level enough to allow for loose coupling Internal parts of the components are never accessed directly, only via the component interface Component objects should never keep state across requests Ideally, they should be thread-safe 23

Special component: The System Object Large-Scale Applications in Python One system component object which represents the application instance All component objects are created and managed by the system object Components can access each other through the system object (circular references!) There can be multiple system objects, e.g. one running in each thread 24

Split the layers into components General approach: Process Boundary (Multiple Process Model) Interface Layer Application Instance Layer One system component that manages the application instance RequestComponent Server Layer SessionComponent Application Layer HandlerComponent ResponseComponent UserComponent PresentationComponent SystemComponent ErrorComponent ImportExportComponent ValidationComponent At least one component per layer Storage Layer DatabaseComponent FilesystemComponent LogComponent DebugComponent 25

Managing data: The Request Context Object Large-Scale Applications in Python Data management: Global data is only used for configuration purposes Components don t store per-request state! Per-request global data is stored and passed around via Request Context Objects Process Boundary (Multiple Process Model) Interface Layer Application Instance Layer RequestComponent ResponseComponent SystemComponent Server Layer SessionComponent UserComponent Request Context Application Layer Object HandlerComponent PresentationComponent ErrorComponent ImportExportComponent ValidationComponent LogComponent Storage Layer DatabaseComponent FilesystemComponent DebugComponent 26

Layers and components: The big picture Large-Scale Applications in Python Process Boundary (Multiple Process Model) Interface Layer Application Instance Layer RequestComponent ResponseComponent SystemComponent Server Layer SessionComponent Application Layer HandlerComponent ImportExportComponent Storage Layer UserComponent PresentationComponent ValidationComponent ErrorComponent LogComponent All Component Objects are connected to the SystemComponent object DatabaseComponent FilesystemComponent DebugComponent 27

Reduce component complexity: Management objects Management objects help simplify component object implementations work on or with groups of low data/task objects The distinction between management objects and component objects is not always clear If in doubt, use a component object that delegates work to a management object 28

Low-level: Data and task objects Data objects encapsulate data (nothing much new here) Task objects interaction with multiple objects I/O on collections of objects delegating work to other management objects interfacing to component objects etc. 29

Example: Management objects at work Large-Scale Applications in Python SystemComponent Application Layer HandlerComponent TaskManager Management Object Object Access Path PresentationComponent ValidationComponent Edit Store Export Data/Task Object ImportExportComponent ImportManager ExportManager CSVImport XMLImport XLSImport CSVExport XMLExport XLSExport 30

Management object or component? Use component objects to represent logical units / concepts within the application without going into too much detail Use management objects to work on collections of data/task objects to simplify component implementations to avoid direct interfacing between the data/task objects Large-Scale Applications in Python Never mix responsibilities 31

Intermezzo: There s beauty in design Large-Scale Applications in Python 32

Before you start... 1. Introduction 2. Application Design 3. Before you start 4. Discussion 33

Structuring your modules First some notes on the import statement: Keep import dependencies low; avoid from import * Always use absolute import paths (defeats pickle problems among other things) Always layout your application modules using Python packages Import loops can be nasty; import on demand can sometimes help 34

Finding the right package structure Use one module per management/component class group of object classes managed by the same management class keep modules small; if in doubt, split at class boundaries Large-Scale Applications in Python Group components and associated management modules in Python packages (directories) Use the application model as basis for the package layout 35

Data, classes and methods Use data objects for data encapsulation instead of simple types (tuples, lists, dictionaries, etc.) Use methods even for simple tasks but don t make them too simple Use method groups for more complex tasks e.g. to implement a storage query interface Use mix-in classes if method groups can be deployed in more than class context If you need to write the same logic twice, think about creating a mix-in class to encapsulate it, or put it on a base class Avoid using mix-in classes if only one class makes use of them 36

Make mistakes and learn from them: Refactoring If an implementation gets too complicated, sit down and reconsider the design often enough a small change in the way objects interact can do wonders Be daring when it comes to rewriting larger parts of code! It sometimes takes more than just a few changes to get a design right It is often faster to implement a good design from scratch, than trying to fix a broken one 37

Often forgotten: Documentation Always document the code that you write! Use doc-strings, inline comments and block logical units using empty lines doc-strings represent your method s contracts with the outside world Document the intent of the methods, classes and logical code units not only their interface Use descriptive identifier names even if they take longer to type 38

Quality Assurance: XP helps! Use extreme programming techniques whenever possible: Always read the code top to bottom after you have made changes or added something new to it Try to follow the flow of information in your mind (before actually running the code) Write unit tests for the code and/or test it until everything works as advertised in the doc-strings 39

Quality Assurance: A few tips Typos can easily go unnoticed in Python: use the editor s auto-completion function as often as possible Use tools like PyChecker to find hidden typos and possibly bugs Always test code before committing it to the software repository 40

Discussion 1. Introduction 2. Application Design 3. Before you start 4. Discussion 41

Conclusion Structured application design can go a long way Divide-et-impera helps keep basic buildings blocks manageable Extreme programming doesn t have to spoil the fun 42

All this sounds familiar Application design is in many ways like structuring a company: Divisions need to be set up (component objects) Responsibilities need to be defined (management vs. data/task objects) Processes need to be defined (component/management object APIs) Applications work in many ways like companies: Customer interaction (user interface) Information flow (application interface) Decision process (business logic) Accounting and data keeping (storage interface) 43

Developing large-scale applications in Python Questions Large-Scale Applications in Python Has anyone worked on large-scale Python applications? What tools / features are (still) missing in the tool chain? Would you be prepared to pay for components or frameworks? 44

And finally... Thank you for your time. 45

Contact egenix.com Software, Skills and Services GmbH Marc-André Lemburg Pastor-Löh-Str. 48 D-40764 Langenfeld Germany email: mal@egenix.com Phone: +49 211 9304112 Fax: +49 211 3005250 Web: http://www.egenix.com/ 46