PHP Or Other Scripting Languages - and Scale Them to Compete with Established "Store Bought" Enterprise Web Technologies

Total Page:16

File Type:pdf, Size:1020Kb

PHP Or Other Scripting Languages - and Scale Them to Compete with Established Building Scalable Web Sites By Cal Henderson ............................................... Publisher: O'Reilly Pub Date: May 2006 Print ISBN-10: 0-596-10235-6 Print ISBN-13: 978-0-59-610235-7 Pages: 348 Table of Contents | Index Slow websites infuriate users. Lots of people can visit your web site or use your web application - but you have to be prepared for those visitors, or they won't come back. Your sites need to be built to withstand the problems success creates. Building Scalable Web Sites looks at a variety of techniques for creating sites that can keep users cheerful even when there are thousands or millions of them. Flickr.com developer, Cal Henderson, explains how to build sites so that large numbers of visitors can enjoy them. Henderson examines techniques that go beyond sheer speed, exploring how to coordinate developers, support international users, and integrate with other services from email to SOAP to RSS to the APIs exposed by many Ajax-based web applications. This book uncovers the secrets that you need to know for back-end scaling, architecture and failover so your websites can handle countless requests. You'll learn how to take the "poor man's web technologies" - Linux, Apache, MySQL and PHP or other scripting languages - and scale them to compete with established "store bought" enterprise web technologies. Toward the end of the book, you'll discover techniques for keeping web applications running with event monitoring and long- term statistical tracking for capacity planning. If you're about to build your first dynamic website, then Building Scalable Web Sites isn't for you. But if you're an advanced developer who's ready to realize the cost and performance benefits of a comprehensive approach to scalable applications, then let your fingers do the walking through this convenient guide. Building Scalable Web Sites By Cal Henderson ............................................... Publisher: O'Reilly Pub Date: May 2006 Print ISBN-10: 0-596-10235-6 Print ISBN-13: 978-0-59-610235-7 Pages: 348 Table of Contents | Index Copyright Preface Chapter 1. Introduction Section 1.1. What Is a Web Application? Section 1.2. How Do You Build Web Applications? Section 1.3. What Is Architecture? Section 1.4. How Do I Get Started? Chapter 2. Web Application Architecture Section 2.1. Layered Software Architecture Section 2.2. Layered Technologies Section 2.3. Software Interface Design Section 2.4. Getting from A to B Section 2.5. The Software/Hardware Divide Section 2.6. Hardware Platforms Section 2.7. Hardware Platform Growth Section 2.8. Hardware Redundancy Section 2.9. Networking Section 2.10. Languages, Technologies, and Databases Chapter 3. Development Environments Section 3.1. The Three Rules Section 3.2. Use Source Control Section 3.3. One-Step Build Section 3.4. Issue Tracking Section 3.5. Scaling the Development Model Section 3.6. Coding Standards Section 3.7. Testing Chapter 4. i18n, L10n, and Unicode Section 4.1. Internationalization and Localization Section 4.2. Unicode in a Nutshell Section 4.3. Unicode Encodings Section 4.4. The UTF-8 Encoding Section 4.5. UTF-8 Web Applications Section 4.6. Using UTF-8 with PHP Section 4.7. Using UTF-8 with Other Languages Section 4.8. Using UTF-8 with MySQL Section 4.9. Using UTF-8 with Email Section 4.10. Using UTF-8 with JavaScript Section 4.11. Using UTF-8 with APIs Chapter 5. Data Integrity and Security Section 5.1. Data Integrity Policies Section 5.2. Good, Valid, and Invalid Section 5.3. Filtering UTF-8 Section 5.4. Filtering Control Characters Section 5.5. Filtering HTML Section 5.6. Cross-Site Scripting (XSS) Section 5.7. SQL Injection Attacks Chapter 6. Email Section 6.1. Receiving Email Section 6.2. Injecting Email into Your Application Section 6.3. The MIME Format Section 6.4. Parsing Simple MIME Emails Section 6.5. Parsing UU Encoded Attachments Section 6.6. TNEF Attachments Section 6.7. Wireless Carriers Hate You Section 6.8. Character Sets and Encodings Section 6.9. Recognizing Your Users Section 6.10. Unit Testing Chapter 7. Remote Services Section 7.1. Remote Services Club Section 7.2. Sockets Section 7.3. Using HTTP Section 7.4. Remote Services Redundancy Section 7.5. Asynchronous Systems Section 7.6. Exchanging XML Section 7.7. Lightweight Protocols Chapter 8. Bottlenecks Section 8.1. Identifying Bottlenecks Section 8.2. External Services and Black Boxes Chapter 9. Scaling Web Applications Section 9.1. The Scaling Myth Section 9.2. Scaling the Network Section 9.3. Load Balancing Section 9.4. Scaling MySQL Section 9.5. MyISAM Section 9.6. MySQL Replication Section 9.7. Database Partitioning Section 9.8. Scaling Large Database Section 9.9. Scaling Storage Chapter 10. Statistics, Monitoring, and Alerting Section 10.1. Tracking Web Statistics Section 10.2. Application Monitoring Section 10.3. Alerting Chapter 11. APIs Section 11.1. Data Feeds Section 11.2. Mobile Content Section 11.3. Web Services Section 11.4. API Transports Section 11.5. API Abuse Section 11.6. Authentication Section 11.7. The Future About the Author Colophon Colophon Index Building Scalable Web Sites by Cal Henderson Copyright © 2006 O'Reilly Media, Inc. All rights reserved. Printed in the United States of America. Published by O'Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O'Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (safari.oreilly.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 [email protected] . Editor: Simon St.Laurent Production Editor: Adam Witwer Copyeditor: Adam Witwer Proofreader: Colleen Gorman Indexer: John Bickelhaupt Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrators: Robert Romano and Jessamyn Read Printing History: May 2006: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly Media, Inc. Building Scalable Web Sites, the image of a carp, and related trade dress are trademarks of O'Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O'Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN: 0-596-10235-6 [M] Preface The first web application I built was called Terrania. A visitor could come to the web site, create a virtual creature with some customizations, and then track that creature's progress through a virtual world. Creatures would wander about, eat plants (or other creatures), fight battles, and mate with other players' creatures. This activity would then be reported back to players by twice-daily emails summarizing the day's events. Calling it a web application is a bit of a stretch; at the time I certainly wouldn't have categorized it as such. The core of the game was a program written in C++ that ran on a single machine, loading game data from a single flat file, processing everything for the game "tick," and storing it all again in a single flat file. When I started building the game, the runtime was destined to become the server component of a client-server game architecture. Programming network data-exchange at the time was a difficult process that tended to involve writing a lot of rote code just to exchange strings between a server and client (we had no .NET in those days). The Web gave application developers a ready-to-use platform for content delivery across a network, cutting out the trickier parts of client-server applications. We were free to build the server that did the interesting parts while building a client in simple HTML that was trivial in comparison. What would have traditionally been the client component of Terrania resided on the server, simply accessing the same flat file that the game server used. For most pages in the "client" application, I simply loaded the file into memory, parsed out the creatures that the player cared about, and displayed back some static information in HTML. To create a new creature, I appended a block of data to the end of a second file, which the server would then pick up and process each time it ran, integrating the new creatures into the game. All game processing, including the sending of progress emails, was done by the server component. The web server "client" interface was a simple C++ CGI application that could parse the game datafile in a couple of hundred lines of source. This system was pretty satisfactory; perhaps I didn't see the limitations at the time because I didn't come up against any of them. The lack of interactivity through the web interface wasn't a big deal as that was part of the game design. The only write operation performed by a player was the initial creation of the creature, leaving the rest of the game as a read-only process. Another issue that didn't come up was concurrency. Since Terrania was largely read-only, any number of players could generate pages simultaneously. All of the writes were simple file appends that were fast enough to avoid spinning for locks. Besides, there weren't enough players for there to be a reasonable chance of two people reading or writing at once. A few years would pass before I got around to working with something more closely resembling a web application.
Recommended publications
  • Radare2 Book
    Table of Contents introduction 1.1 Introduction 1.2 History 1.2.1 Overview 1.2.2 Getting radare2 1.2.3 Compilation and Portability 1.2.4 Compilation on Windows 1.2.5 Command-line Flags 1.2.6 Basic Usage 1.2.7 Command Format 1.2.8 Expressions 1.2.9 Rax2 1.2.10 Basic Debugger Session 1.2.11 Contributing to radare2 1.2.12 Configuration 1.3 Colors 1.3.1 Common Configuration Variables 1.3.2 Basic Commands 1.4 Seeking 1.4.1 Block Size 1.4.2 Sections 1.4.3 Mapping Files 1.4.4 Print Modes 1.4.5 Flags 1.4.6 Write 1.4.7 Zoom 1.4.8 Yank/Paste 1.4.9 Comparing Bytes 1.4.10 Visual mode 1.5 Visual Disassembly 1.5.1 2 Searching bytes 1.6 Basic Searches 1.6.1 Configurating the Search 1.6.2 Pattern Search 1.6.3 Automation 1.6.4 Backward Search 1.6.5 Search in Assembly 1.6.6 Searching for AES Keys 1.6.7 Disassembling 1.7 Adding Metadata 1.7.1 ESIL 1.7.2 Scripting 1.8 Loops 1.8.1 Macros 1.8.2 R2pipe 1.8.3 Rabin2 1.9 File Identification 1.9.1 Entrypoint 1.9.2 Imports 1.9.3 Symbols (exports) 1.9.4 Libraries 1.9.5 Strings 1.9.6 Program Sections 1.9.7 Radiff2 1.10 Binary Diffing 1.10.1 Rasm2 1.11 Assemble 1.11.1 Disassemble 1.11.2 Ragg2 1.12 Analysis 1.13 Code Analysis 1.13.1 Rahash2 1.14 Rahash Tool 1.14.1 Debugger 1.15 3 Getting Started 1.15.1 Registers 1.15.2 Remote Access Capabilities 1.16 Remoting Capabilities 1.16.1 Plugins 1.17 Plugins 1.17.1 Crackmes 1.18 IOLI 1.18.1 IOLI 0x00 1.18.1.1 IOLI 0x01 1.18.1.2 Avatao 1.18.2 R3v3rs3 4 1.18.2.1 .intro 1.18.2.1.1 .radare2 1.18.2.1.2 .first_steps 1.18.2.1.3 .main 1.18.2.1.4 .vmloop 1.18.2.1.5 .instructionset 1.18.2.1.6
    [Show full text]
  • Bitrix Site Manager
    Bitrix Site Manager Recommendations on configuring web systems for proper operation with Bitrix Site Manager Contents Contents..........................................................................................................................2 Introduction......................................................................................................................3 Configuring the Apache web server.................................................................................3 Reduction of memory consumed by the web server................................................................4 Creation of two-level configuration: Front-end plus Back-end.................................................4 Additional recommendations for the two-level configuration....................................................5 Configuring PHP..............................................................................................................7 Customizing the MySQL database..................................................................................8 Customizing the Oracle database..................................................................................10 Conclusions...................................................................................................................11 2 Introduction This document is intended for use by technicians and system administrators. The current document contains recommendations on how to customize the server software settings. These operations are executed by the Bitrix experts for
    [Show full text]
  • Kumpulan Tutorial AJAX – PHP
    Kumpulan Tutorial AJAX – PHP Table of Contents 1. Tips Optimasi skrip PHP()..........................................................................................................................4 2. Pengenalan Codeigniter............................................................................................................................6 3. Belajar jQuery mudah...............................................................................................................................9 4. Coding Best Practise................................................................................................................................14 5. Create, Update dan Delete Data Master Dengan Ajax.........................................................................17 6. Tips Merancang User Interface Form Pencarian Data..........................................................................24 7. Membuat Menu Tree Dengan PHP dan JQuery....................................................................................28 8. Skrip/Hal yang sering dibuat/digunakan oleh web-developer()..........................................................31 9. Belajar Ajax dengan prototype.js...........................................................................................................32 10. Submit Form Dengan Ajax Menggunakan jQuery.................................................................................34 11. AJAX – Asynchronous JavaScript And XML (PART 1) ............................................................................36
    [Show full text]
  • Phpmyadmin Documentation Release 5.1.2-Dev
    phpMyAdmin Documentation Release 5.1.2-dev The phpMyAdmin devel team Sep 29, 2021 Contents 1 Introduction 3 1.1 Supported features............................................3 1.2 Shortcut keys...............................................4 1.3 A word about users............................................4 2 Requirements 5 2.1 Web server................................................5 2.2 PHP....................................................5 2.3 Database.................................................6 2.4 Web browser...............................................6 3 Installation 7 3.1 Linux distributions............................................7 3.2 Installing on Windows..........................................8 3.3 Installing from Git............................................8 3.4 Installing using Composer........................................9 3.5 Installing using Docker..........................................9 3.6 IBM Cloud................................................ 14 3.7 Quick Install............................................... 14 3.8 Verifying phpMyAdmin releases..................................... 16 3.9 phpMyAdmin configuration storage................................... 17 3.10 Upgrading from an older version..................................... 19 3.11 Using authentication modes....................................... 19 3.12 Securing your phpMyAdmin installation................................ 26 3.13 Using SSL for connection to database server.............................. 27 3.14 Known issues..............................................
    [Show full text]
  • การเข้ารหัสภาษาสคริปต์ไฟล์ PHP ด้วย Turck Mmcache บนระบ
    การเขารหสภาษาสคร ปตไ ฟล PHP ดวย Turck MMCache บนระบบปฏบต การล)น*กซ ภษ ต รงโรจน หนวยปฏ บ ต การเทคโนโลย เคร อข าย ศนย เทคโนโลย อ เล !กทรอนกส และคอมพ วเตอร แห งชาต 1. บทน/า การเขย นภาษาสครปต บ นระบบปฏบ ตก ารลน กซ จะดาเนน การเขย นในลกษณะของ Plain text เป) นลกษณะของการเขย นใหท+ างานทล ะบรรทด แตส. าหรบโครงการขนาดใหญ. หรอ1 งานทต2 อ+ งการความ ปลอดภยสง5 ยกตวอย.างเชน. งานท2เกย2 วกบระบบเคร1อข.ายอนประกอบดว+ ยหมายเลขไอพ หรอ1 งานท2ม ความจาเป) นตอง+ ระบรหส การเขา+ ใชง+ านและรหสผา. นอยใ5. นสครปต ใ นลกษณะของการฝงในสครปต (Hard code) ลกษณะงานเหล.านBเมอ12 เผยแพร.ออกไปจะทาใหผ+ 5ท+ ม2 ค วามร5 + หรอ1 สามารถอา. นภาษาสครปต เข า+ ใจ สามารถทจ2 ะนาขอม+ ล5 บางสว. นเหลาน. นB ไปทาการทอ2 าจจะเป) นอนตราย หรอส1 ง. ผลกระทบในเชง การคา+ ได + การเขา+ รหสภาษาสครปต จ งD เป) นอก ทางเลอ1 กหนงทD2 ส2 ามารถนามาใชเพ+ อป12 +องกนปญหาเหล.านBไดใ+ นเบอ1B ง ตน+ ผลตภณฑ ยอดน ยมท น2 กพฒนานยมใช ม+ หลายตวด วยกน+ ตวอยางกรณศ. กษD า เชน. Zend encoder (www.zend.com) ผลตภณฑ เหล าน. ทB าออกมาในลกษณะเชงพาณ ชย ผท5 + ใช2 งานม+ ความจ าเป) น ตองซ+ อล1B ขส ทธ ซอฟตN แวร มาด วยราคาท+ ค2 อนข. างส+ ง5 และอกกรณหน งเมD2 อผล12 ตภณฑ ได ร+ บความนยมมา ก ก) จะมผ ท5 + ท2 าซอฟตแวร เพ อ12 ถอดรหสออกมาดวยเช+ นกน. ยกตวอยางเช. น. เมอเราพ12 มพ keyword คาวา. Zend decoder ลงในเวบไซด www.google.com ก)จะปรากฏผลลพธของเวบไซด ท ม2 Keyword เหลาน. จB านวน ถงD 508,000 เวบไซด สาหรบผลตภณฑ ซอฟต แวร ส าหรบการเขา+ รหสจากคายอ. น12 สามารถด5 ไดท+ http://2 www.patrickz.eu.org/content/Articles/PHP%20Script%20Encoder%20Compare.htm การแกป+ ญหาเรองล12 ขส ทธ ซอN ฟตแวร และการหาซอฟตแวร ท ใช2 ถ+ อดรหสไดง+ ายจากเวบไซด. ท 2วๆ ไป เราจงมD ความจ าเป) นตองหาทางเล+ อกใ1 นการใชซอฟต+ แวร ท ม2 ข อจ+ ากดดงนB 1. ฟร (Open source software) 2. ตดต งงB า.
    [Show full text]
  • Ask Bjørn Hansen Develooper LLC
    If this text is too small to read, move closer! http://groups.google.com/group/scalable Real World Web: Performance & Scalability Ask Bjørn Hansen Develooper LLC http://develooper.com/talks/ April 14, 2008 – r17 Hello. • I’m Ask Bjørn Hansen perl.org, ~10 years of mod_perl app development, mysql and scalability consulting YellowBot • I hate tutorials! • Let’s do 3 hours of 5 minute° lightning talks! ° Actual number of minutes may vary Construction Ahead! • Conflicting advice ahead • Not everything here is applicable to everything • Ways to “think scalable” rather than be-all-end-all solutions • Don’t prematurely optimize! (just don’t be too stupid with the “we’ll fix it later” stuff) Questions ... • How many ... • ... are using PHP? Python? Python? Java? Ruby? C? • 3.23? 4.0? 4.1? 5.0? 5.1? 6.x? • MyISAM? InnoDB? Other? • Are primarily “programmers” vs “DBAs” • Replication? Cluster? Partitioning? • Enterprise? Community? • PostgreSQL? Oracle? SQL Server? Other? Seen this talk before? Slide count 200 No, you haven’t. • 150 • :-) 100 • ~266 people * 3 hours = half a work year! 50 0 2001 2004 2006 2007 2008 Question Policy! http://groups.google.com/group/scalable • Do we have time for Slides per minute questions? 1.75 • Yes! (probably) • Quick questions anytime • Long questions after 1.00 • or on the list! • (answer to anything is likely “it depends” or “let’s talk about it 0.25 after / send me an email”) 2001 2002 2004 2005 2006 2007 2008 • The first, last and only lesson: • Think Horizontal! • Everything in your architecture, not just the front end web servers • Micro optimizations and other implementation details –– Bzzzzt! Boring! (blah blah blah, we’ll get to the cool stuff in a moment!) Benchmarking techniques • Scalability isn't the same as processing time • Not “how fast” but “how many” • Test “force”, not speed.
    [Show full text]
  • Minimal Perl for UNIX and Linux People
    Minimal Perl For UNIX and Linux People BY TIM MAHER MANNING Greenwich (74° w. long.) For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact: Special Sales Department Manning Publications Co. Cherokee Station PO Box 20386 Fax: (609) 877-8256 New York, NY 10021 email: [email protected] ©2007 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Manning Publications Co. Copyeditor: Tiffany Taylor 209 Bruce Park Avenue Typesetters: Denis Dalinnik, Dottie Marsico Greenwich, CT 06830 Cover designer: Leslie Haimes ISBN 1-932394-50-8 Printed in the United States of America 12345678910–VHG–1009080706 To Yeshe Dolma Sherpa, whose fortitude, endurance, and many sacrifices made this book possible. To my parents, Gloria Grady Washington and William N. Maher, who indulged my early interests in literature. To my limbic system, with gratitude for all the good times we’ve had together.
    [Show full text]
  • Pipenightdreams Osgcal-Doc Mumudvb Mpg123-Alsa Tbb
    pipenightdreams osgcal-doc mumudvb mpg123-alsa tbb-examples libgammu4-dbg gcc-4.1-doc snort-rules-default davical cutmp3 libevolution5.0-cil aspell-am python-gobject-doc openoffice.org-l10n-mn libc6-xen xserver-xorg trophy-data t38modem pioneers-console libnb-platform10-java libgtkglext1-ruby libboost-wave1.39-dev drgenius bfbtester libchromexvmcpro1 isdnutils-xtools ubuntuone-client openoffice.org2-math openoffice.org-l10n-lt lsb-cxx-ia32 kdeartwork-emoticons-kde4 wmpuzzle trafshow python-plplot lx-gdb link-monitor-applet libscm-dev liblog-agent-logger-perl libccrtp-doc libclass-throwable-perl kde-i18n-csb jack-jconv hamradio-menus coinor-libvol-doc msx-emulator bitbake nabi language-pack-gnome-zh libpaperg popularity-contest xracer-tools xfont-nexus opendrim-lmp-baseserver libvorbisfile-ruby liblinebreak-doc libgfcui-2.0-0c2a-dbg libblacs-mpi-dev dict-freedict-spa-eng blender-ogrexml aspell-da x11-apps openoffice.org-l10n-lv openoffice.org-l10n-nl pnmtopng libodbcinstq1 libhsqldb-java-doc libmono-addins-gui0.2-cil sg3-utils linux-backports-modules-alsa-2.6.31-19-generic yorick-yeti-gsl python-pymssql plasma-widget-cpuload mcpp gpsim-lcd cl-csv libhtml-clean-perl asterisk-dbg apt-dater-dbg libgnome-mag1-dev language-pack-gnome-yo python-crypto svn-autoreleasedeb sugar-terminal-activity mii-diag maria-doc libplexus-component-api-java-doc libhugs-hgl-bundled libchipcard-libgwenhywfar47-plugins libghc6-random-dev freefem3d ezmlm cakephp-scripts aspell-ar ara-byte not+sparc openoffice.org-l10n-nn linux-backports-modules-karmic-generic-pae
    [Show full text]
  • Suse Linux Enterprise Server 10 Mail Scanning Gateway Build Guide
    SuSE Linux Enterprise Server 10 Mail Scanning Gateway Build Guide Written By: Stephen Carter [email protected] Last Modified 9. May. 2007 Page 1 of 96 Table of Contents Due credit.......................................................................................................................................................4 Overview........................................................................................................................................................5 System Requirements.....................................................................................................................................6 SLES10 DVD............................................................................................................................................6 An existing e-mail server..........................................................................................................................6 A Pentium class PC...................................................................................................................................6 Internet Access..........................................................................................................................................6 Internet Firewall Modifications.................................................................................................................7 Installation Summary.....................................................................................................................................8 How
    [Show full text]
  • What Is Perl
    AdvancedAdvanced PerlPerl TechniquesTechniques DayDay 22 Dave Cross Magnum Solutions Ltd [email protected] Schedule 09:45 – Begin 11:15 – Coffee break (15 mins) 13:00 – Lunch (60 mins) 14:00 – Begin 15:30 – Coffee break (15 mins) 17:00 – End FlossUK 24th February 2012 Resources Slides available on-line − http://mag-sol.com/train/public/2012-02/ukuug Also see Slideshare − http://www.slideshare.net/davorg/slideshows Get Satisfaction − http://getsatisfaction.com/magnum FlossUK 24th February 2012 What We Will Cover Modern Core Perl − What's new in Perl 5.10, 5.12 & 5.14 Advanced Testing Database access with DBIx::Class Handling Exceptions FlossUK 24th February 2012 What We Will Cover Profiling and Benchmarking Object oriented programming with Moose MVC Frameworks − Catalyst PSGI and Plack FlossUK 24th February 2012 BenchmarkingBenchmarking && ProfilingProfiling Benchmarking Ensure that your program is fast enough But how fast is fast enough? premature optimization is the root of all evil − Donald Knuth − paraphrasing Tony Hoare Don't optimise until you know what to optimise FlossUK 24th February 2012 Benchmark.pm Standard Perl module for benchmarking Simple usage use Benchmark; my %methods = ( method1 => sub { ... }, method2 => sub { ... }, ); timethese(10_000, \%methods); Times 10,000 iterations of each method FlossUK 24th February 2012 Benchmark.pm Output Benchmark: timing 10000 iterations of method1, method2... method1: 6 wallclock secs \ ( 2.12 usr + 3.47 sys = 5.59 CPU) \ @ 1788.91/s (n=10000) method2: 3 wallclock secs \ ( 0.85 usr + 1.70 sys = 2.55 CPU) \ @ 3921.57/s (n=10000) FlossUK 24th February 2012 Timed Benchmarks Passing timethese a positive number runs each piece of code a certain number of times Passing timethese a negative number runs each piece of code for a certain number of seconds FlossUK 24th February 2012 Timed Benchmarks use Benchmark; my %methods = ( method1 => sub { ..
    [Show full text]
  • Effective Perl Programming
    Effective Perl Programming Second Edition The Effective Software Development Series Scott Meyers, Consulting Editor Visit informit.com/esds for a complete list of available publications. he Effective Software Development Series provides expert advice on Tall aspects of modern software development. Books in the series are well written, technically sound, and of lasting value. Each describes the critical things experts always do—or always avoid—to produce outstanding software. Scott Meyers, author of the best-selling books Effective C++ (now in its third edition), More Effective C++, and Effective STL (all available in both print and electronic versions), conceived of the series and acts as its consulting editor. Authors in the series work with Meyers to create essential reading in a format that is familiar and accessible for software developers of every stripe. Effective Perl Programming Ways to Write Better, More Idiomatic Perl Second Edition Joseph N. Hall Joshua A. McAdams brian d foy Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Capetown • Sydney • Tokyo • Singapore • Mexico City Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
    [Show full text]
  • Compiling Your Own Perl
    APPENDIX A Compiling Your Own Perl Compiling Perl on a Unix-like system is simple. First, obtain the source for Perl from CPAN (dppl6++_l]j*lanh*knc+on_+NA=@IA*dpih). Then input the following sequence of commands: p]nvtrblanh)1*4*4*p]n*cv _`lanh)1*4*4 od?kjbecqna)`ao i]ga i]gapaop oq`ki]gaejop]hh On most Unix systems, this code will result in your lanh being installed into the +qon+ hk_]h+ directory tree. If you want it installed elsewhere—for example, in the local directory in your home directory—then replace od?kjbecqna)`a with the following: od?kjbecqna)`ao)@lnabet9z+hk_]h+ which should enable you to install Perl on your computer without root access. Note that the )`ao flag uses all the default options for compiling Perl. If you know that you want nonstandard configuration, just use the flag )`a instead to be prompted for your requirements. Be aware that the source for Perl 5.10.0 requires a patch to work properly with Catalyst. This is fixed in subsequent versions of Perl 5.10. If you need to test code guaranteed to run on a wide range of systems, you should con- sider using Perl version 5.8.7. Perl versions greater than 5.8.7 contain features that were not available in earlier versions of Perl, so Perl 5.8.7 is feature complete for all versions of Perl that Catalyst will run on (version 5.8.1 and later). Put another way, versions 5.8.8 and later have new features that you can’t rely on in earlier releases.
    [Show full text]