Scala High Performance Programming
scala 高效编程,scale作为spark默认开发语言, 能够在jvm中运行, 函数化编程比java8更加灵活,是大数据分析的必备知识Scala High Performance ProgrammingCopyright o 2016 Packt PublishingAll rights reserved no part of this book may be reproduced stored in a retrieval system, ortransmitted in any form or by any means, without the prior written permission of thepublisher, except in the case of brief quotations embedded in critical articles or reviewsEvery effort has been made in the preparation of this book to ensure the accuracy of theinformation presented However, the information contained in this book is sold withoutwarranty either express or implied. Neither the authors nor packt publishing and itsdealers and distributors will be held liable for any damages caused or alleged to be causeddirectly or indirectly by this bookPackt Publishing has endeavored to provide trademark information about all of thecompanies and products mentioned in this book by the appropriate use of capitalsHowever, Packt Publishing cannot guarantee the accuracy of this informationFirst published: May 2016Production reference: 1250516Published by Packt Publishing Ltdiversace35 Livery streetBirmingham b3 2PB UKISBN978-1-78646-604-4www.packtpub.comCreditsAuthorsCopy EditorVincent theronPriyanka raviMichael diamantReviewerProject CoordinatorNermin SerifovicFrancina pintoCommissioning editorProofreaderEdward gordonSafis EditingAcquisition editorIndexerChaitanya nairRekha nairContent Development editorProduction coordinatorNikhil borkarManu josepTechnical editorCover workMadhunikita Sunil Chindarkar Manu josephAbout the authorsVincent Theron is a professional software engineer with 9 years of experience. Hediscovered scala 6 years ago and uses it to build highly scalable and reliable applicationsHe designs software to solve business problems in various industries including onlinegambling, financial trading, and, most recently, advertising. He earned a master's degree incomputer science and engineering from Universite Paris-Est Marne-la-Vallee. vincent livesin the boston area with his wife his son and two furry catsTo everybody at Packt Publishing, thanks for working so hard to make this book a reality. ToChaitanya Nair, thanks for reaching out to me with this project. To Nikhil borkar, thanks forproviding us with guidance along the way. To Michael diamant, my coauthor, coworker, and friend,thanks for the knowledge you have brought to this book and for being an inspiration every day. To myparents, thanks for your love and support and for buying me my first computer. And finally, to mywife, Julie, thanks for your constant encouragement and for giving me such a wonderful sonenthusiast. He began his career in 2009 focused on Java and the object-orientedMichael Diamant is a professional software engineer and functional programmingprogramming paradigm. After learning about Scala in 2011, he has focused on using Scalaand the functional programming paradigm to build software systems in the financialtrading and advertising domains. Michael is a graduate of Worcester Polytechnic Instituteand lives in the boston areaThe knowledge i am able to share in this book is the result of a lifetime of support and teaching fromothers. I want to recognize my coauthor, Vincent, for pushing me to take on this effort and for all thehours spent together developing the thoughts contained in our book. All of my current and formercolleagues have helped me sharpen my engineering skills, and without their generosity of sharingtheir learning i would not have been able to write this book. In addition to Vincent, i want to call outseveral colleagues that I feel particularly indebted to Dave Stevens, Gary Malouf, eugene Rolnick,and Johnny everson. Thank you to my parents and my brother for supporting me and shaping meinto the individual i am today. I am deeply appreciative of the support my girlfriend, Anna, gave methroughout the writing process. And last but not least, thank you to Packt Publishing for helping uswrite our first bookabout the reviewerNermin Serifovic has been a Scala enthusiast since 2009, practicing it professionally since2011. For most of his career, he has focused on building backend platforms using JVtechnologies. Most recently, as VP Engineering at Pingup, he has been leading thedevelopment efforts of a local services booking systemNermin is an instructor at harvard Extension School, where he co-teaches the concurrentProgramming in Scala course and has also given talks at various conferencesAn active Scala community member, Nermin organized the boston Area Scala enthusiastsuser group and was part of the northeast Scala Symposium founding team. He is a coauthor of the scala puzzlers book and co-creator of the scala puzzlers websiteNermin holds an m. eng in computer science from Cornell University and his areas ofinterest include distributed systems, along with concurrent, reactive, and functionalprogramminWww.pacKtpub.comForsupportfilesanddownloadsrelatedtoyourbookpleasevisitwww.packtpub.come Books discount offers and moreDid you know that packt offers eBook versions of every book published, with PDF andepubfilesavailableYoucanupgradetotheebookversionatwww.Packtpub.comandasaprint book customer, you are entitled to a discount on the eBook copy. Get in touch with usat customercare@packtpub com for more detailsAtwww.packtpub.comyoucanalsoreadacollectionoffreetechnicalarticlessignupforarange of free newsletters and receive exclusive discounts and offers on packt books andebooksPACKTLIB°https://www2.packtpub.com/books/subscription/packtlibDo you need instant solutions to your It questions? PacktLib is Packt's online digital booklibrary. Here, you can search access and read packt' s entire library of booksWhy subscribe?Fully searchable across every book published by PacktCopy and paste, print, and bookmark contente On demand and accessible via a web browserFree access for packt account holdersGet notified! Find out when new books are published by following @PacktEnterprise onTwitter or the packt Enterprise facebook pageTable of contentsPrefaceChapter 1: The Road to PerformanceDefining performancePerformant softwareHardware resourcesLatency and throughput677890BottlenecksSummarizing performance11The problem with averagesPercentiles to the rescue15Collecting measurements15Using benchmarks to measure performanceProfiling to locate bottlenecks17Pairing benchmarks and profiling7A case study18Tooling18Summary19Chapter 2: Measuring Performance on the JVM20A peek into the financial domain20Unexpected volatility crushes profits23Reproducing the problem24Throughput benchmark25Latency benchmark27The first latency benchmark27The coordinated omission problem29The second latency benchmark30The final latency benchmark30Locating bottlenecks32Did I test with the expected set of resources?34as the system environment clean during the profiling36Are the JVM's internal resources performing to expectations?38Where are the cpu bottlenecks?41What are the memory allocation patterns?47Trying to save the day51a word of caution53A profiling checklist53Taking big steps with microbenchmarks53Microbenchmarking the order book55Summary61Chapter 3: Unleashing Scala Performance62Value classes63Bytecode representation63Performance considerations65Tagged types -an alternative to value classes66Specialization68Bytecode representation69Performance considerations71Tuples76Bytecode representation76Performance considerations76Pattern matchingBytecode representation79Performance considerations80Tail recursion86Bytecode representation88Performance considerations89The Option data type92Bytecode representation93Performance considerations94Case study -a more performant option95Summary100Chapter 4: Exploring the collection APl101High-throughput systems- improving the order book102Understanding historical trade-offs- list implementation102List103ReemA106Adding limit orders07Canceling orders110The current order book-queue implementation111Queue111Improved cancellation performance through lazy evaluationSet114Benchmarking Lazy CancelOrderBook119Lessons learned123Historical data analysis124Lagged time series returns124128Data clean up129Handling multiple return series132Array133Looping with the spire cfor macro135Summary137Chapter 5: Lazy Collections and Event Sourcing138Improving the client report generation speed138Diving into the reporting code139Using views to speed up report generation time142Constructing a custom view144Applying views to improve report generation performance147Vⅰ ew caveats150Seaview extends Seq150Views are not memoizers151Zipping up report generation154Rethinking reporting architecture155An overview of stream158Transforming events161Building the event sourcing pipeline166Streaming markov chains170Stream caveats174Streams are memoizers74Stream can be infinite176Summary177Chapter 6: Concurrency in Scala178Parallelizing backtesting strategies178Exploring Future180Future and crazy ideas184Future usage considerations186Performing side-effects86Blocking execution187Handling failures189Hampering performance through executor submissions192Handling blocking calls and callbacks197Execution Context and blocking calls197Asynchronous versus nonblocking198Using a dedicated execution Context to block calls198
用户评论