SlideShare uma empresa Scribd logo
1 de 52
Baixar para ler offline
Pronk like you mean it!

       A few years of gadding about in Haskell

       Bryan O’Sullivan, MailRank, Inc.




Monday, October 3, 2011
pronk |prô ng k; prä ng k|

             verb [ intrans. ]
             (of a springbok or other antelope) leap in the air with an arched back and
             stiff legs, typically as a form of display or when threatened.

             ORIGIN late 19th cent.: from Afrikaans, literally ‘show off,’ from Dutch
             pronken ‘to strut.’




Monday, October 3, 2011
Pronking as it is practiced in the wild.


Monday, October 3, 2011
“Someone ought to do something!”

       • I re-entered the Haskell world in the mid-2000s



       • At the time, I noticed the lack of “the kind of book I want to read”



       • After several months of concentrated wishful thinking... still no book!



       • So... I found some collaborators and wrote the book I wished I had:



            • Real World Haskell, http://realworldhaskell.org/




Monday, October 3, 2011
2.5 years of free online access

       • Nearing a million visits, and still growing!
         book.realworldhaskell.org                                                                Mar 31, 2009 - Sep 30, 2011
         Visitors Overview                                                                                          Comparing to: Site
                                                                                                                                     Visitors

        6,000                                                                                                                              6,000



        3,000                                                                                                                              3,000



        0                                                                                                                                  0



            Mar 31 - Apr 4             Aug 30 - Sep 5           Jan 31 - Feb 6   Jul 4 - Jul 10    Dec 5 - Dec 11   May 8 - May 14



         299,443 people visited this site

                             940,409 Visits

                             299,443 Absolute Unique Visitors

                             1,981,816 Pageviews

                             2.11 Average Pageviews

                             00:02:27 Time on Site
Monday, October 3, 2011
Reader involvement is a big win

       • We didn’t pioneer comments from readers


       • But we were the first to do it well

                          100




                          75




                          50




                          25




                            0
                           2009-W13 2009-W24 2009-W35 2009-W46 2010-W05 2010-W16 2010-W27 2010-W38 2010-W49 2011-W07 2011-W18 2011-W29 2011-W40

                                                            realworldhaskell.org comments per week




Monday, October 3, 2011
Burnout

       • “Real World Haskell” was a huge effort



       • 1,328 commits by 3 people over 15 months



       • Tons of online comments to read



       • By the end, I was exhausted



       • I barely touched a computer for several months



Monday, October 3, 2011
From burnout to fusion

       • Once I recovered from the RWH burnout effect, I felt a keen irony


            • Haskell was still not especially “real world” for lots of uses


       • The most glaring hole (to me): no modern text handling




       • Coutts and Stewart’s bytestring library was wonderful, but binary-only




       • They’d since moved on from primitive, fragile fusion to stream fusion


Monday, October 3, 2011
Stream fusion and text

       • Harper’s MSc thesis took stream fusion and applied it to text processing


       • I took his MSc work and turned it into the standard Haskell text library


            • http://hackage.haskell.org/package/text


       • Now distributed as part of the Haskell platform




Monday, October 3, 2011
From thesis to bedrock

       • Harper’s MSc tarball:


            • 1,699 LOC


            • No tests (and yes, numerous bugs)


       • Today:


            • 9,532 LOC


            • 330 QuickCheck tests, coverage above 90%


            • Only 3 bugs ever reported “in the wild”


Monday, October 3, 2011
When text isn’t enough

       • The text API is a small superset of the Haskell list/string API (+10%)


       • It’s missing a lot of important real-world functionality


       • So I wrote another package, text-icu, to fill the gaps


       • Based on idiomatic FFI wrappers around the venerable ICU library




Monday, October 3, 2011
What’s in text-icu?

       • Unicode normalization (è vs. `+e)


       • Collation: in some locales, lexicographic ordering differs from simple numeric
         ordering of code points


       • Character set support: Big5, Shift-JIS, KOI-8, etc.


       • Perl-compatible regular expressions




          (and more besides)




Monday, October 3, 2011
Two data types for different use cases

          Strict                               Lazy


       • An entire string is a single chunk   • A string is a list of 64KB chunks

       • Good for small strings, whole-       • Good for single-pass streaming
         document manipulation
                                              • Chunk boundaries are a prolific
                                               source of bugs


                                              • Nearly twice as much code to
                                               maintain




Monday, October 3, 2011
Was this enough?

       • 6 months into the project, the API was nearing completion


       • I wanted to start benchmarking, to see whether the code was “good”


       • Looked on Hackage for a decent benchmarking library




       • Found nothing :-(




Monday, October 3, 2011
What’s in a benchmarking tool?

       • A typical benchmarking harness:


       • Run a function a few times (often configurable)


       • Print a few statistics (min, max, mean)




Monday, October 3, 2011
Pitfalls for the unwary

       • Supposing your benchmark harness does something like this:


            1.Record the start time


            2.Run the thingumbob


            3.Record the end time


       • Looks fine, right?


       • So... what can go wrong?




Monday, October 3, 2011
Clock resolution and cost

       • On my Mac, getPOSIXTime has a resolution of 2.15μs (±80ns)


       • Suppose we can tolerate a 1% error


            ‣ We cannot naïvely measure anything that runs in less than 200μs




       • On my system, a call to getPOSIXTime costs 60.5ns


            ‣ Failure to account for this introduces a further 5% of inaccuracy in the limit




Monday, October 3, 2011
Advice for the 1990s



       • Longstanding benchmarking advice:


            • Run on a “quiet” system


       • This is no longer remotely achievable, so ... forget it?




Monday, October 3, 2011
The impossibility of silence



       • All modern CPUs vary their performance in response to demand


       • Contention from input devices, networking gear, that web browser you forgot
          to quit, you name it


       • Virtualization introduces interference from invisible co-tenants




Monday, October 3, 2011
That O’Sullivan seems awfully gloomy



       • Does this mean we should abandon the ideal of a quiet system?


            • No, but understand that there’s only so much you’ll achieve




       • What is now very important is to


            • Measure the perturbation




Monday, October 3, 2011
(Re)introducing the criterion library

       • The library I wrote to benchmark the text package


            • Can measure pure functions (strict and lazy) and IO actions




       • Automates much of the pain of benchmarking


            • “How many samples do I need for a good result?”


            • “Can I trust my numbers?”


            • “What’s the shape of my distribution?”


Monday, October 3, 2011
Sampling safely

       • We measure clock resolution and cost, then compute the number of samples
         needed to provide a low measurement error


       • Samples are corrected for clock cost


       • A warmup run sets code and data up for reproducible measurements


       • We can force the garbage collector to run between samples for more stable
         measurements


       • We measure wall clock time, not “CPU time consumed by this process”


            • This lets us handle I/O-bound, networked, and multi-process code



Monday, October 3, 2011
Outliers and the inflated mean

       • Suppose you launch Call of Duty 3 while benchmarking


       • This will eat a lot of CPU and memory, and intermittently slow down the
         benchmarked code


       • Slower code will show up as outliers (spikes) in time measurements




       • Enough outliers, and the sample statistics will be inflated, perhaps drastically




Monday, October 3, 2011
Reporting dodgy measurements

       • Our goal is to identify outliers, but only when they have a significant effect


            • Outliers that don’t inflate our measurements are not really a problem


       • We use the boxplot technique to categorize outliers


       • We report outliers that are perturbing our measurements, along with the
         extent of the problem (mild, moderate or severe)




Monday, October 3, 2011
Trustworthy numbers



       • It’s exceptionally rare for measurements of performance to resemble an
         idealized statistical distribution


       • The bootstrap is a resampling method for estimating parameters of a
         statistical sample without knowledge of the underlying distribution


       • Following Boyer, we use the bootstrap to give confidence intervals on our
         measurements of the mean and standard deviation




Monday, October 3, 2011
What do measurements look like?	



       • Some sample output from a criterion benchmark of the Builder type:


            • mean: 4.855 ms (lb 4.846 ms, ub 4.870 ms)


            • std dev: 57.9 μs (lb 39.6 μs, ub 93.5 μs)




       • Builder is a type we provide to support efficient concatenation of many
         strings (for formatting, rendering, and such)




Monday, October 3, 2011
Resampling revisited

       • The bootstrap requires repeated pseudo-random resampling with
         replacement


            • Resampling: given a number of measurements, choose a subset at
              random


            • Replacement: okay to choose the same measurement more than once in a
              single resample


       • Since we resample a collection of measurements many times, PRNG
         performance becomes a bottleneck




Monday, October 3, 2011
Fast pseudo-random number generation



       • The venerable random package is not very fast


       • So I wrote an implementation of Marsaglia’s MWC8222 algorithm


       • mwc-random is up to 60x faster than random


            • mwc-random: 19.96ns per 64-bit Int (about 50,000,000 per second)


            • random: 1227.51ns per 64-bit Int




Monday, October 3, 2011
Truth in advertising

       • The benchmark for understanding performance measurements is the
         histogram


            • “Do I have a unimodal distribution?”


            • “What are those outliers doing!?”


       • Histograms are finicky beasts


            • Choose a good bin size by hand, or else the data will mislead


            • I know of no good tools for quickly and efficiently fiddling with histograms




Monday, October 3, 2011
Is there something better we can do?

       • Kernel density estimation is a convolution-based method that gives
         histogram-like output without the need for hand-tuning


       • KDEs provide a non-parametric way to estimate the probability density
         function of a sample


       • We convolve over a range of points from the sample vector


            • The size of the convolution window is called the bandwidth




Monday, October 3, 2011
What does a KDE look like?




Monday, October 3, 2011
No hand tuning?

       • There are long-established methods for automatic choice of bandwidth that
         will give a quality KDE


       • Unfortunately, the best known methods smooth multimodal samples too
         aggressively


       • But wait, didn’t we just see a KDE with 3+ modes (peaks)?


       • Soon to come: an implementation of Raykar & Duraiswami’s Fast optimal
         bandwidth selection for kernel density estimation


            • Much more robust in the face of non-unimodal empirical distributions;
              doesn’t oversmooth



Monday, October 3, 2011
For want of a nail

       • To answer the question of “is the text library fast?”, I built...


            • ...a benchmarking package, which needed...


            • ...a statistics library, which needed...


            • ...a PRNG




       • After disappearing down that long tunnel, was the library fast?


            • Not especially - at first


Monday, October 3, 2011
Stream fusion - how did it work out?

       • Didn’t perform well until SimonPJ rewrote the GHC inliner for 7.0


       • Performance is now pretty good


            • But the model seems to force too much heap allocation


       • Hand-written code still beats stream fusion


       • One fair-sized win comes with reusability


            • We can often share code between the two text representations


       • The programming model is somewhat awkward


Monday, October 3, 2011
General-purpose statistics wrangling

       • Since I needed to write other statistical code while working on criterion, I
         ended up developing the statistics package


       • Provides a bunch of useful capabilities:


            • Working with widely used discrete and continuous probability distributions


            • Computing with sample data: quantile & KDE estimation, bootstrap
              methods, significance testing, autocorrelation analysis, ...


            • Random variate generation under several different distributions


            • Common statistical tests for significant differences between samples



Monday, October 3, 2011
Numerical pitfalls

       • There are plenty of traps for the unwary in a statistics library


            • Catastrophic cancellation of small values


            • Ballooning error margins outside a small range


            • PRNGs that exhibit unexpected autocorrelation




       • Example: the popular ziggurat algorithm for normally distributed Double
         values has subtle autocorrelation problems




Monday, October 3, 2011
What does criterion focus on?

       • Ease of use: writing and running a benchmark must be as easy as possible


       • Automation: figure out good run times and sample sizes that lead to quality
          results without human intervention


       • Understanding: KDE gives an at-a-glance view of performance without
          manual histogram tweaking


       • Trust: criterion inspects its own measurements, and warns you if they’re
          dubious




Monday, October 3, 2011
What has criterion made possible?

       • In just a few projects of mine:


            • At least 28 commits to the text library since Sep 2009 consist of speed
              improvements measured with criterion


            • 10 commits to statistics and mwc-random yield measured performance
              improvements (i.e. using criterion to help speed itself!)




       • Most importantly to me, the text library now smokes both
         bytestring and built-in lists at almost everything :-)



Monday, October 3, 2011
Putting the “real” into “real world”

       • In December of 2010, I started a small company in San Francisco, MailRank


       • We use machine learning techniques to help people deal with email overload


            • “Show me my email that matters.”




       • We put our money where my mouth is:


            • Our cloud services are written in Haskell




Monday, October 3, 2011
Haskell in the real world

       • The Haskell community is very lucky to have a fantastic central repository of
         code in the form of Hackage


            • It’s a bit of a victim of its own success by now, mind




       • For commercial users, our community’s widespread use of BSD licensing is
         very reassuring


       • Our core library alone depends on 25 open source Haskell libraries


            • Of these, we developed and open sourced about a dozen



Monday, October 3, 2011
Third party libraries I love

       • The Snap team’s snap web framework: fast and elegant

            • The yesod web framework deserves a shout-out for its awesomeness too



       • Snoyman’s http-enumerator: a HTTP client done right


       • Tibell’s unordered-containers: blazingly fast hash maps


       • Van der Jeugt and Meier’s blaze-builder: fast network buffer construction


       • Hinze and Paterson’s fingertee: the Swiss army knife of purely functional data
         structures




Monday, October 3, 2011
A few other libraries I’ve written

       • attoparsec: incremental parsing of bytestrings


       • aeson: handling of JSON data


       • mysql-simple: a pleasant client library for MySQL


       • configurator: app configuration for the harried ops engineer




       • I tend to focus on ease of use and good performance


       • By open sourcing, I get a stream of improvements and bug reports


Monday, October 3, 2011
Performance: the inliner

       • The performance of modern Haskell code is a marvel


       • But we have become reliant on inlining to achieve much of this


            • e.g. stream fusion depends critically on inlining



       • Widespread inlining is troubling


            • Makes reading Core (to grok performance) vastly harder


            • Slows GHC down enormously - building just a few fusion-heavy packages
              can take 20+ minutes


Monday, October 3, 2011
Achieving good performance isn’t always easy

       • e.g. my attoparsec parsing library is CPS-heavy and GHC generates worse
         code for it than I’d like... but I don’t know why


       • Core is not a very friendly language to read, but it’s gotten scary lately with so
         many type annotations — we need -ddump-hacker-core




       • Outside of a smallish core of people, lazy and strict evaluation, and their
         respective advantages and pitfalls, are not well understood


            • We’ve all seen code splattered with panicky uses of seq and strictness
              annotations



Monday, October 3, 2011
“Well-typed programs can’t be blamed”? Uh huh?

       • Let me misappropriate Wadler’s nice turn of phrase


       • I often can’t figure out where to blame my well-typed program because all I
         see upon a fatal error is this:




          *** Exception: Prelude.head: empty list


       • This is a disaster for debugging



Monday, October 3, 2011
Our biggest weakness

       • The fact that it’s almost impossible to get automated assistance to debug a
         Haskell program, after 20 years of effort, remains painful


            • No post-mortem crash dump analysis


            • No equivalent to a stack trace, to tell us “this is the context in which we
              were executing when the Bad Thing happened”




       • This is truly a grievous problem; it’s the only thing that keeps me awake at
         night when I think about deploying production Haskell code




Monday, October 3, 2011
What’s worked well for MailRank?

       • Number of service crashes in 2+ months of closed beta: zero


       • The server component accepts a pummeling under load without breaking a
         sweat


       • Our batch number crunching code is fast and cheap


       • Builds and deployments are easy thanks to Cabal, native codegen, and static
         linking




Monday, October 3, 2011
A little bit about education

       • In spite of recent curriculum changes, FP in general is still getting short shrift
         for teaching


       • David Mazières and I have started using Haskell as a language for teaching
         systems programming at Stanford (tradionally not an FP place)


       • Instead of teaching just Haskell, we’re teaching both Haskell and systems


       • As far as I can tell, our emphases on practicality and performance are unique




Monday, October 3, 2011
There’s demand for this stuff!

       • We’re targeting upper division undergrads and grad students


       • So far, our class is standing room only


       • We have several outsiders auditing the class




       • If you’re in a position to teach this stuff, and to do so with a practical focus,
         now’s a good time to be doing it!




Monday, October 3, 2011
What’s next?

       • I’m taking the analytics from criterion and applying them to HTTP load testing


       • Existing tools (apachebench, httperf) are limited


            • Difficult to use


            • Limited SSL support


            • Little statistical oomph


       • Thanks to GHC’s scalable I/O manager and http-enumerator, the equivalent in
         Haskell is easy




Monday, October 3, 2011
Work in progress

       • My HTTP load tester is named “pronk”


            • github.com/mailrank/pronk




       • It’s still under development, but already pretty good


       • Because it’s open source, I’m already getting bug reports on the unreleased
         code!




Monday, October 3, 2011
Thank you!




Monday, October 3, 2011

Mais conteúdo relacionado

Destaque

The impact of social media on innovation culture
The impact of social media on innovation cultureThe impact of social media on innovation culture
The impact of social media on innovation cultureandrew_tan7
 
Eportafolis i tic a la formacio docent inicial
Eportafolis i tic a la formacio docent inicialEportafolis i tic a la formacio docent inicial
Eportafolis i tic a la formacio docent inicialGemma Tur
 
Nissan + CM Mobile Strategy, Mobile University 2011
Nissan + CM Mobile Strategy, Mobile University 2011Nissan + CM Mobile Strategy, Mobile University 2011
Nissan + CM Mobile Strategy, Mobile University 2011Critical Mass
 
BayFP: Concurrent and Multicore Haskell
BayFP: Concurrent and Multicore HaskellBayFP: Concurrent and Multicore Haskell
BayFP: Concurrent and Multicore HaskellBryan O'Sullivan
 
香港六合彩
香港六合彩香港六合彩
香港六合彩couai
 
Slide Share Thin
Slide Share ThinSlide Share Thin
Slide Share Thinnoo0002
 
TM Research vol 1-5
TM Research vol 1-5TM Research vol 1-5
TM Research vol 1-5AMTR
 
Free Culture! Public Domain Photography on the Web
Free Culture! Public Domain Photography on the WebFree Culture! Public Domain Photography on the Web
Free Culture! Public Domain Photography on the WebIan McDermott
 
Tm For Ptsd
Tm For PtsdTm For Ptsd
Tm For PtsdAMTR
 
香港六合彩
香港六合彩香港六合彩
香港六合彩aakine
 
[2009] Fisl10 T Learning
[2009] Fisl10 T Learning[2009] Fisl10 T Learning
[2009] Fisl10 T LearningUFPE
 
Metropolia Marketing Talks 19.11.2009
Metropolia Marketing Talks 19.11.2009Metropolia Marketing Talks 19.11.2009
Metropolia Marketing Talks 19.11.2009tonnitommi
 
Chapter two forms of government activity
Chapter two forms of government activityChapter two forms of government activity
Chapter two forms of government activitynlmrhistory
 
Wedgeofmisery V1b
Wedgeofmisery V1bWedgeofmisery V1b
Wedgeofmisery V1bguest4cea8c
 

Destaque (19)

Learning analytics surf310811
Learning analytics surf310811Learning analytics surf310811
Learning analytics surf310811
 
The impact of social media on innovation culture
The impact of social media on innovation cultureThe impact of social media on innovation culture
The impact of social media on innovation culture
 
Eportafolis i tic a la formacio docent inicial
Eportafolis i tic a la formacio docent inicialEportafolis i tic a la formacio docent inicial
Eportafolis i tic a la formacio docent inicial
 
Mjedi101109
Mjedi101109Mjedi101109
Mjedi101109
 
Nissan + CM Mobile Strategy, Mobile University 2011
Nissan + CM Mobile Strategy, Mobile University 2011Nissan + CM Mobile Strategy, Mobile University 2011
Nissan + CM Mobile Strategy, Mobile University 2011
 
BayFP: Concurrent and Multicore Haskell
BayFP: Concurrent and Multicore HaskellBayFP: Concurrent and Multicore Haskell
BayFP: Concurrent and Multicore Haskell
 
El sexenni democràtic
El sexenni democràticEl sexenni democràtic
El sexenni democràtic
 
香港六合彩
香港六合彩香港六合彩
香港六合彩
 
Slide Share Thin
Slide Share ThinSlide Share Thin
Slide Share Thin
 
TM Research vol 1-5
TM Research vol 1-5TM Research vol 1-5
TM Research vol 1-5
 
Free Culture! Public Domain Photography on the Web
Free Culture! Public Domain Photography on the WebFree Culture! Public Domain Photography on the Web
Free Culture! Public Domain Photography on the Web
 
Boutelle Family Recipes
Boutelle Family RecipesBoutelle Family Recipes
Boutelle Family Recipes
 
Concept Aim
Concept AimConcept Aim
Concept Aim
 
Tm For Ptsd
Tm For PtsdTm For Ptsd
Tm For Ptsd
 
香港六合彩
香港六合彩香港六合彩
香港六合彩
 
[2009] Fisl10 T Learning
[2009] Fisl10 T Learning[2009] Fisl10 T Learning
[2009] Fisl10 T Learning
 
Metropolia Marketing Talks 19.11.2009
Metropolia Marketing Talks 19.11.2009Metropolia Marketing Talks 19.11.2009
Metropolia Marketing Talks 19.11.2009
 
Chapter two forms of government activity
Chapter two forms of government activityChapter two forms of government activity
Chapter two forms of government activity
 
Wedgeofmisery V1b
Wedgeofmisery V1bWedgeofmisery V1b
Wedgeofmisery V1b
 

Semelhante a Pronk like you mean it

The Social Web - Creating an Interactive Digital Experience
The Social Web - Creating an Interactive Digital ExperienceThe Social Web - Creating an Interactive Digital Experience
The Social Web - Creating an Interactive Digital ExperienceJessKupferman
 
A importância dos dados em sua arquitetura... uma visão muito além do SQL Ser...
A importância dos dados em sua arquitetura... uma visão muito além do SQL Ser...A importância dos dados em sua arquitetura... uma visão muito além do SQL Ser...
A importância dos dados em sua arquitetura... uma visão muito além do SQL Ser...Alexandre Porcelli
 
Data Designed for Discovery
Data Designed for DiscoveryData Designed for Discovery
Data Designed for DiscoveryOCLC
 
Making the Impossible Possible, by Kelli Getz, Jeannie Castro, and Nancy Lind...
Making the Impossible Possible, by Kelli Getz, Jeannie Castro, and Nancy Lind...Making the Impossible Possible, by Kelli Getz, Jeannie Castro, and Nancy Lind...
Making the Impossible Possible, by Kelli Getz, Jeannie Castro, and Nancy Lind...Charleston Conference
 
ReEnvisioning E-Resource Holdings Management
ReEnvisioning E-Resource Holdings ManagementReEnvisioning E-Resource Holdings Management
ReEnvisioning E-Resource Holdings ManagementNASIG
 
Preparing for ePub 3
Preparing for ePub 3Preparing for ePub 3
Preparing for ePub 3Ron Severdia
 
Message:Passing - lpw 2012
Message:Passing - lpw 2012Message:Passing - lpw 2012
Message:Passing - lpw 2012Tomas Doran
 
lecture1-intro.ppt
lecture1-intro.pptlecture1-intro.ppt
lecture1-intro.pptIshaXogaha
 
Introducing S.O.P.H.I.E. A Libraries-centered Plan Against Skeuomorphism-indu...
Introducing S.O.P.H.I.E.A Libraries-centered Plan Against Skeuomorphism-indu...Introducing S.O.P.H.I.E.A Libraries-centered Plan Against Skeuomorphism-indu...
Introducing S.O.P.H.I.E. A Libraries-centered Plan Against Skeuomorphism-indu...Steven MacCall
 

Semelhante a Pronk like you mean it (20)

High Availability Server Apps
High Availability Server AppsHigh Availability Server Apps
High Availability Server Apps
 
The Social Web - Creating an Interactive Digital Experience
The Social Web - Creating an Interactive Digital ExperienceThe Social Web - Creating an Interactive Digital Experience
The Social Web - Creating an Interactive Digital Experience
 
Coming Clean About Dirty OCR
Coming Clean About Dirty OCRComing Clean About Dirty OCR
Coming Clean About Dirty OCR
 
A importância dos dados em sua arquitetura... uma visão muito além do SQL Ser...
A importância dos dados em sua arquitetura... uma visão muito além do SQL Ser...A importância dos dados em sua arquitetura... uma visão muito além do SQL Ser...
A importância dos dados em sua arquitetura... uma visão muito além do SQL Ser...
 
Soup to Nuts Retailing
Soup to Nuts RetailingSoup to Nuts Retailing
Soup to Nuts Retailing
 
Data Designed for Discovery
Data Designed for DiscoveryData Designed for Discovery
Data Designed for Discovery
 
Making the Impossible Possible, by Kelli Getz, Jeannie Castro, and Nancy Lind...
Making the Impossible Possible, by Kelli Getz, Jeannie Castro, and Nancy Lind...Making the Impossible Possible, by Kelli Getz, Jeannie Castro, and Nancy Lind...
Making the Impossible Possible, by Kelli Getz, Jeannie Castro, and Nancy Lind...
 
Metro pdf version
Metro pdf versionMetro pdf version
Metro pdf version
 
JavaScript Secrets
JavaScript SecretsJavaScript Secrets
JavaScript Secrets
 
Data Mining Lecture_2.pptx
Data Mining Lecture_2.pptxData Mining Lecture_2.pptx
Data Mining Lecture_2.pptx
 
NCLA Presentation
NCLA PresentationNCLA Presentation
NCLA Presentation
 
Enterprise Drupal
Enterprise DrupalEnterprise Drupal
Enterprise Drupal
 
ReEnvisioning E-Resource Holdings Management
ReEnvisioning E-Resource Holdings ManagementReEnvisioning E-Resource Holdings Management
ReEnvisioning E-Resource Holdings Management
 
ReEnvisioning E-Resource Holdings Management
ReEnvisioning E-Resource Holdings ManagementReEnvisioning E-Resource Holdings Management
ReEnvisioning E-Resource Holdings Management
 
Preparing for ePub 3
Preparing for ePub 3Preparing for ePub 3
Preparing for ePub 3
 
Message:Passing - lpw 2012
Message:Passing - lpw 2012Message:Passing - lpw 2012
Message:Passing - lpw 2012
 
Physics4999
Physics4999 Physics4999
Physics4999
 
lecture1-intro.ppt
lecture1-intro.pptlecture1-intro.ppt
lecture1-intro.ppt
 
lecture1-intro.ppt
lecture1-intro.pptlecture1-intro.ppt
lecture1-intro.ppt
 
Introducing S.O.P.H.I.E. A Libraries-centered Plan Against Skeuomorphism-indu...
Introducing S.O.P.H.I.E.A Libraries-centered Plan Against Skeuomorphism-indu...Introducing S.O.P.H.I.E.A Libraries-centered Plan Against Skeuomorphism-indu...
Introducing S.O.P.H.I.E. A Libraries-centered Plan Against Skeuomorphism-indu...
 

Mais de Bryan O'Sullivan

Real World Haskell: Lecture 7
Real World Haskell: Lecture 7Real World Haskell: Lecture 7
Real World Haskell: Lecture 7Bryan O'Sullivan
 
Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Bryan O'Sullivan
 
Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Bryan O'Sullivan
 
Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Bryan O'Sullivan
 
Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Bryan O'Sullivan
 
CUFP 2009 Keynote - Real World Haskell
CUFP 2009 Keynote - Real World HaskellCUFP 2009 Keynote - Real World Haskell
CUFP 2009 Keynote - Real World HaskellBryan O'Sullivan
 
The other side of functional programming: Haskell for Erlang people
The other side of functional programming: Haskell for Erlang peopleThe other side of functional programming: Haskell for Erlang people
The other side of functional programming: Haskell for Erlang peopleBryan O'Sullivan
 
DEFUN 2008 - Real World Haskell
DEFUN 2008 - Real World HaskellDEFUN 2008 - Real World Haskell
DEFUN 2008 - Real World HaskellBryan O'Sullivan
 
Haskell for the Real World
Haskell for the Real WorldHaskell for the Real World
Haskell for the Real WorldBryan O'Sullivan
 

Mais de Bryan O'Sullivan (9)

Real World Haskell: Lecture 7
Real World Haskell: Lecture 7Real World Haskell: Lecture 7
Real World Haskell: Lecture 7
 
Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Real World Haskell: Lecture 5
Real World Haskell: Lecture 5
 
Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Real World Haskell: Lecture 4
Real World Haskell: Lecture 4
 
Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2
 
Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Real World Haskell: Lecture 1
Real World Haskell: Lecture 1
 
CUFP 2009 Keynote - Real World Haskell
CUFP 2009 Keynote - Real World HaskellCUFP 2009 Keynote - Real World Haskell
CUFP 2009 Keynote - Real World Haskell
 
The other side of functional programming: Haskell for Erlang people
The other side of functional programming: Haskell for Erlang peopleThe other side of functional programming: Haskell for Erlang people
The other side of functional programming: Haskell for Erlang people
 
DEFUN 2008 - Real World Haskell
DEFUN 2008 - Real World HaskellDEFUN 2008 - Real World Haskell
DEFUN 2008 - Real World Haskell
 
Haskell for the Real World
Haskell for the Real WorldHaskell for the Real World
Haskell for the Real World
 

Último

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 

Pronk like you mean it

  • 1. Pronk like you mean it! A few years of gadding about in Haskell Bryan O’Sullivan, MailRank, Inc. Monday, October 3, 2011
  • 2. pronk |prô ng k; prä ng k| verb [ intrans. ] (of a springbok or other antelope) leap in the air with an arched back and stiff legs, typically as a form of display or when threatened. ORIGIN late 19th cent.: from Afrikaans, literally ‘show off,’ from Dutch pronken ‘to strut.’ Monday, October 3, 2011
  • 3. Pronking as it is practiced in the wild. Monday, October 3, 2011
  • 4. “Someone ought to do something!” • I re-entered the Haskell world in the mid-2000s • At the time, I noticed the lack of “the kind of book I want to read” • After several months of concentrated wishful thinking... still no book! • So... I found some collaborators and wrote the book I wished I had: • Real World Haskell, http://realworldhaskell.org/ Monday, October 3, 2011
  • 5. 2.5 years of free online access • Nearing a million visits, and still growing! book.realworldhaskell.org Mar 31, 2009 - Sep 30, 2011 Visitors Overview Comparing to: Site Visitors 6,000 6,000 3,000 3,000 0 0 Mar 31 - Apr 4 Aug 30 - Sep 5 Jan 31 - Feb 6 Jul 4 - Jul 10 Dec 5 - Dec 11 May 8 - May 14 299,443 people visited this site 940,409 Visits 299,443 Absolute Unique Visitors 1,981,816 Pageviews 2.11 Average Pageviews 00:02:27 Time on Site Monday, October 3, 2011
  • 6. Reader involvement is a big win • We didn’t pioneer comments from readers • But we were the first to do it well 100 75 50 25 0 2009-W13 2009-W24 2009-W35 2009-W46 2010-W05 2010-W16 2010-W27 2010-W38 2010-W49 2011-W07 2011-W18 2011-W29 2011-W40 realworldhaskell.org comments per week Monday, October 3, 2011
  • 7. Burnout • “Real World Haskell” was a huge effort • 1,328 commits by 3 people over 15 months • Tons of online comments to read • By the end, I was exhausted • I barely touched a computer for several months Monday, October 3, 2011
  • 8. From burnout to fusion • Once I recovered from the RWH burnout effect, I felt a keen irony • Haskell was still not especially “real world” for lots of uses • The most glaring hole (to me): no modern text handling • Coutts and Stewart’s bytestring library was wonderful, but binary-only • They’d since moved on from primitive, fragile fusion to stream fusion Monday, October 3, 2011
  • 9. Stream fusion and text • Harper’s MSc thesis took stream fusion and applied it to text processing • I took his MSc work and turned it into the standard Haskell text library • http://hackage.haskell.org/package/text • Now distributed as part of the Haskell platform Monday, October 3, 2011
  • 10. From thesis to bedrock • Harper’s MSc tarball: • 1,699 LOC • No tests (and yes, numerous bugs) • Today: • 9,532 LOC • 330 QuickCheck tests, coverage above 90% • Only 3 bugs ever reported “in the wild” Monday, October 3, 2011
  • 11. When text isn’t enough • The text API is a small superset of the Haskell list/string API (+10%) • It’s missing a lot of important real-world functionality • So I wrote another package, text-icu, to fill the gaps • Based on idiomatic FFI wrappers around the venerable ICU library Monday, October 3, 2011
  • 12. What’s in text-icu? • Unicode normalization (è vs. `+e) • Collation: in some locales, lexicographic ordering differs from simple numeric ordering of code points • Character set support: Big5, Shift-JIS, KOI-8, etc. • Perl-compatible regular expressions (and more besides) Monday, October 3, 2011
  • 13. Two data types for different use cases Strict Lazy • An entire string is a single chunk • A string is a list of 64KB chunks • Good for small strings, whole- • Good for single-pass streaming document manipulation • Chunk boundaries are a prolific source of bugs • Nearly twice as much code to maintain Monday, October 3, 2011
  • 14. Was this enough? • 6 months into the project, the API was nearing completion • I wanted to start benchmarking, to see whether the code was “good” • Looked on Hackage for a decent benchmarking library • Found nothing :-( Monday, October 3, 2011
  • 15. What’s in a benchmarking tool? • A typical benchmarking harness: • Run a function a few times (often configurable) • Print a few statistics (min, max, mean) Monday, October 3, 2011
  • 16. Pitfalls for the unwary • Supposing your benchmark harness does something like this: 1.Record the start time 2.Run the thingumbob 3.Record the end time • Looks fine, right? • So... what can go wrong? Monday, October 3, 2011
  • 17. Clock resolution and cost • On my Mac, getPOSIXTime has a resolution of 2.15μs (±80ns) • Suppose we can tolerate a 1% error ‣ We cannot naïvely measure anything that runs in less than 200μs • On my system, a call to getPOSIXTime costs 60.5ns ‣ Failure to account for this introduces a further 5% of inaccuracy in the limit Monday, October 3, 2011
  • 18. Advice for the 1990s • Longstanding benchmarking advice: • Run on a “quiet” system • This is no longer remotely achievable, so ... forget it? Monday, October 3, 2011
  • 19. The impossibility of silence • All modern CPUs vary their performance in response to demand • Contention from input devices, networking gear, that web browser you forgot to quit, you name it • Virtualization introduces interference from invisible co-tenants Monday, October 3, 2011
  • 20. That O’Sullivan seems awfully gloomy • Does this mean we should abandon the ideal of a quiet system? • No, but understand that there’s only so much you’ll achieve • What is now very important is to • Measure the perturbation Monday, October 3, 2011
  • 21. (Re)introducing the criterion library • The library I wrote to benchmark the text package • Can measure pure functions (strict and lazy) and IO actions • Automates much of the pain of benchmarking • “How many samples do I need for a good result?” • “Can I trust my numbers?” • “What’s the shape of my distribution?” Monday, October 3, 2011
  • 22. Sampling safely • We measure clock resolution and cost, then compute the number of samples needed to provide a low measurement error • Samples are corrected for clock cost • A warmup run sets code and data up for reproducible measurements • We can force the garbage collector to run between samples for more stable measurements • We measure wall clock time, not “CPU time consumed by this process” • This lets us handle I/O-bound, networked, and multi-process code Monday, October 3, 2011
  • 23. Outliers and the inflated mean • Suppose you launch Call of Duty 3 while benchmarking • This will eat a lot of CPU and memory, and intermittently slow down the benchmarked code • Slower code will show up as outliers (spikes) in time measurements • Enough outliers, and the sample statistics will be inflated, perhaps drastically Monday, October 3, 2011
  • 24. Reporting dodgy measurements • Our goal is to identify outliers, but only when they have a significant effect • Outliers that don’t inflate our measurements are not really a problem • We use the boxplot technique to categorize outliers • We report outliers that are perturbing our measurements, along with the extent of the problem (mild, moderate or severe) Monday, October 3, 2011
  • 25. Trustworthy numbers • It’s exceptionally rare for measurements of performance to resemble an idealized statistical distribution • The bootstrap is a resampling method for estimating parameters of a statistical sample without knowledge of the underlying distribution • Following Boyer, we use the bootstrap to give confidence intervals on our measurements of the mean and standard deviation Monday, October 3, 2011
  • 26. What do measurements look like? • Some sample output from a criterion benchmark of the Builder type: • mean: 4.855 ms (lb 4.846 ms, ub 4.870 ms) • std dev: 57.9 μs (lb 39.6 μs, ub 93.5 μs) • Builder is a type we provide to support efficient concatenation of many strings (for formatting, rendering, and such) Monday, October 3, 2011
  • 27. Resampling revisited • The bootstrap requires repeated pseudo-random resampling with replacement • Resampling: given a number of measurements, choose a subset at random • Replacement: okay to choose the same measurement more than once in a single resample • Since we resample a collection of measurements many times, PRNG performance becomes a bottleneck Monday, October 3, 2011
  • 28. Fast pseudo-random number generation • The venerable random package is not very fast • So I wrote an implementation of Marsaglia’s MWC8222 algorithm • mwc-random is up to 60x faster than random • mwc-random: 19.96ns per 64-bit Int (about 50,000,000 per second) • random: 1227.51ns per 64-bit Int Monday, October 3, 2011
  • 29. Truth in advertising • The benchmark for understanding performance measurements is the histogram • “Do I have a unimodal distribution?” • “What are those outliers doing!?” • Histograms are finicky beasts • Choose a good bin size by hand, or else the data will mislead • I know of no good tools for quickly and efficiently fiddling with histograms Monday, October 3, 2011
  • 30. Is there something better we can do? • Kernel density estimation is a convolution-based method that gives histogram-like output without the need for hand-tuning • KDEs provide a non-parametric way to estimate the probability density function of a sample • We convolve over a range of points from the sample vector • The size of the convolution window is called the bandwidth Monday, October 3, 2011
  • 31. What does a KDE look like? Monday, October 3, 2011
  • 32. No hand tuning? • There are long-established methods for automatic choice of bandwidth that will give a quality KDE • Unfortunately, the best known methods smooth multimodal samples too aggressively • But wait, didn’t we just see a KDE with 3+ modes (peaks)? • Soon to come: an implementation of Raykar & Duraiswami’s Fast optimal bandwidth selection for kernel density estimation • Much more robust in the face of non-unimodal empirical distributions; doesn’t oversmooth Monday, October 3, 2011
  • 33. For want of a nail • To answer the question of “is the text library fast?”, I built... • ...a benchmarking package, which needed... • ...a statistics library, which needed... • ...a PRNG • After disappearing down that long tunnel, was the library fast? • Not especially - at first Monday, October 3, 2011
  • 34. Stream fusion - how did it work out? • Didn’t perform well until SimonPJ rewrote the GHC inliner for 7.0 • Performance is now pretty good • But the model seems to force too much heap allocation • Hand-written code still beats stream fusion • One fair-sized win comes with reusability • We can often share code between the two text representations • The programming model is somewhat awkward Monday, October 3, 2011
  • 35. General-purpose statistics wrangling • Since I needed to write other statistical code while working on criterion, I ended up developing the statistics package • Provides a bunch of useful capabilities: • Working with widely used discrete and continuous probability distributions • Computing with sample data: quantile & KDE estimation, bootstrap methods, significance testing, autocorrelation analysis, ... • Random variate generation under several different distributions • Common statistical tests for significant differences between samples Monday, October 3, 2011
  • 36. Numerical pitfalls • There are plenty of traps for the unwary in a statistics library • Catastrophic cancellation of small values • Ballooning error margins outside a small range • PRNGs that exhibit unexpected autocorrelation • Example: the popular ziggurat algorithm for normally distributed Double values has subtle autocorrelation problems Monday, October 3, 2011
  • 37. What does criterion focus on? • Ease of use: writing and running a benchmark must be as easy as possible • Automation: figure out good run times and sample sizes that lead to quality results without human intervention • Understanding: KDE gives an at-a-glance view of performance without manual histogram tweaking • Trust: criterion inspects its own measurements, and warns you if they’re dubious Monday, October 3, 2011
  • 38. What has criterion made possible? • In just a few projects of mine: • At least 28 commits to the text library since Sep 2009 consist of speed improvements measured with criterion • 10 commits to statistics and mwc-random yield measured performance improvements (i.e. using criterion to help speed itself!) • Most importantly to me, the text library now smokes both bytestring and built-in lists at almost everything :-) Monday, October 3, 2011
  • 39. Putting the “real” into “real world” • In December of 2010, I started a small company in San Francisco, MailRank • We use machine learning techniques to help people deal with email overload • “Show me my email that matters.” • We put our money where my mouth is: • Our cloud services are written in Haskell Monday, October 3, 2011
  • 40. Haskell in the real world • The Haskell community is very lucky to have a fantastic central repository of code in the form of Hackage • It’s a bit of a victim of its own success by now, mind • For commercial users, our community’s widespread use of BSD licensing is very reassuring • Our core library alone depends on 25 open source Haskell libraries • Of these, we developed and open sourced about a dozen Monday, October 3, 2011
  • 41. Third party libraries I love • The Snap team’s snap web framework: fast and elegant • The yesod web framework deserves a shout-out for its awesomeness too • Snoyman’s http-enumerator: a HTTP client done right • Tibell’s unordered-containers: blazingly fast hash maps • Van der Jeugt and Meier’s blaze-builder: fast network buffer construction • Hinze and Paterson’s fingertee: the Swiss army knife of purely functional data structures Monday, October 3, 2011
  • 42. A few other libraries I’ve written • attoparsec: incremental parsing of bytestrings • aeson: handling of JSON data • mysql-simple: a pleasant client library for MySQL • configurator: app configuration for the harried ops engineer • I tend to focus on ease of use and good performance • By open sourcing, I get a stream of improvements and bug reports Monday, October 3, 2011
  • 43. Performance: the inliner • The performance of modern Haskell code is a marvel • But we have become reliant on inlining to achieve much of this • e.g. stream fusion depends critically on inlining • Widespread inlining is troubling • Makes reading Core (to grok performance) vastly harder • Slows GHC down enormously - building just a few fusion-heavy packages can take 20+ minutes Monday, October 3, 2011
  • 44. Achieving good performance isn’t always easy • e.g. my attoparsec parsing library is CPS-heavy and GHC generates worse code for it than I’d like... but I don’t know why • Core is not a very friendly language to read, but it’s gotten scary lately with so many type annotations — we need -ddump-hacker-core • Outside of a smallish core of people, lazy and strict evaluation, and their respective advantages and pitfalls, are not well understood • We’ve all seen code splattered with panicky uses of seq and strictness annotations Monday, October 3, 2011
  • 45. “Well-typed programs can’t be blamed”? Uh huh? • Let me misappropriate Wadler’s nice turn of phrase • I often can’t figure out where to blame my well-typed program because all I see upon a fatal error is this: *** Exception: Prelude.head: empty list • This is a disaster for debugging Monday, October 3, 2011
  • 46. Our biggest weakness • The fact that it’s almost impossible to get automated assistance to debug a Haskell program, after 20 years of effort, remains painful • No post-mortem crash dump analysis • No equivalent to a stack trace, to tell us “this is the context in which we were executing when the Bad Thing happened” • This is truly a grievous problem; it’s the only thing that keeps me awake at night when I think about deploying production Haskell code Monday, October 3, 2011
  • 47. What’s worked well for MailRank? • Number of service crashes in 2+ months of closed beta: zero • The server component accepts a pummeling under load without breaking a sweat • Our batch number crunching code is fast and cheap • Builds and deployments are easy thanks to Cabal, native codegen, and static linking Monday, October 3, 2011
  • 48. A little bit about education • In spite of recent curriculum changes, FP in general is still getting short shrift for teaching • David Mazières and I have started using Haskell as a language for teaching systems programming at Stanford (tradionally not an FP place) • Instead of teaching just Haskell, we’re teaching both Haskell and systems • As far as I can tell, our emphases on practicality and performance are unique Monday, October 3, 2011
  • 49. There’s demand for this stuff! • We’re targeting upper division undergrads and grad students • So far, our class is standing room only • We have several outsiders auditing the class • If you’re in a position to teach this stuff, and to do so with a practical focus, now’s a good time to be doing it! Monday, October 3, 2011
  • 50. What’s next? • I’m taking the analytics from criterion and applying them to HTTP load testing • Existing tools (apachebench, httperf) are limited • Difficult to use • Limited SSL support • Little statistical oomph • Thanks to GHC’s scalable I/O manager and http-enumerator, the equivalent in Haskell is easy Monday, October 3, 2011
  • 51. Work in progress • My HTTP load tester is named “pronk” • github.com/mailrank/pronk • It’s still under development, but already pretty good • Because it’s open source, I’m already getting bug reports on the unreleased code! Monday, October 3, 2011