Clojure High Performance Programming Shantanu Kumar download
Clojure High Performance Programming Shantanu Kumar download
Kumar download
https://ebookbell.com/product/clojure-high-performance-
programming-shantanu-kumar-4680374
https://ebookbell.com/product/clojure-high-performance-programming-
shantanu-kumar-55873594
https://ebookbell.com/product/clojure-high-performance-
programming-2nd-shantanu-kumar-6808932
https://ebookbell.com/product/clojure-high-performance-jvm-
programming-1st-edition-eduardo-daz-38196700
https://ebookbell.com/product/clojure-high-performance-jvm-
programming-eduardo-diaz-shantanu-kumar-akhil-wali-232074192
Clojure High Performance Jvm Programming Diaz Eduardo Kumar
https://ebookbell.com/product/clojure-high-performance-jvm-
programming-diaz-eduardo-kumar-153706882
https://ebookbell.com/product/clojure-applied-from-practice-to-
practitioner-1st-edition-ben-vandgrift-47032926
https://ebookbell.com/product/clojure-for-the-brave-and-true-daniel-
higginbotham-48065160
https://ebookbell.com/product/clojure-1st-edition-
karthikeyanak-50298880
Clojure For The Brave And True Learn The Ultimate Language And Become
A Better Programmer Daniel Higginbotham
https://ebookbell.com/product/clojure-for-the-brave-and-true-learn-
the-ultimate-language-and-become-a-better-programmer-daniel-
higginbotham-55873596
Clojure High Performance
Programming
Shantanu Kumar
BIRMINGHAM - MUMBAI
Clojure High Performance Programming
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-78216-560-6
www.packtpub.com
Reviewers Proofreader
Jan Borgelin Paul Hindle
Mimmo Cosenza aka Magomimmo
Paul Stadig Indexers
Hemangini Bari
Miki Tebeka
Mehreen Deshmukh
Acquisition Editors
Sam Birch Graphics
Ronak Dhruv
Andrew Duckworth
Yuvraj Mannari
Commissioning Editors
Priyanka Shah Production Coordinator
Kyle Albuquerque
Meeta Rajani
Llewellyn Rozario
Cover Work
Kyle Albuquerque
Technical Editors
Jalasha D'costa
Monica John
Copy Editors
Alisha Aranha
Roshni Banerjee
Tanvi Gaitonde
Alfida Paiva
Lavina Pereira
About the Author
In recent years, Shantanu has worked on high performance and distributed systems.
Having used Java for a long time, he discovered Clojure in early 2009 and has been
a fan ever since. Clojure's pragmatism and fine-grained orthogonality continues to
amaze him, and he believes he is a better developer because of this.
While I was working at the Bangalore office of Runa (now Staples Lab) earlier,
several colleagues shared valuable input about Clojure performance. Most notably,
Zach Tellman shared his insight about Clojure and JVM performance, Isaac Praveen
and Abhijith Gopal shared a great deal of information about Clojure application
behavior under load, and Philippe Hanrigou shared his ideas about high performance
API design and queue systems. I want to thank all of them.
This book would not have become a reality without the fine people at Packt
Publishing. I would like to thank Ashvini Sharma for contacting me and
convincing me to take up writing this book, Anish Ramchandani and Amey
Sawant for coordinating the writing process, and the Commissioning
Editors Meeta Rajani, Llewellyn Rozario, and Priyanka Shah for shaping
up this book as I engaged in my debut writing. Technical Editors Jalasha
D'costa and Monica John helped me disambiguate and refine the language
in this book. I also owe my gratitude to the technical reviewers Jan Borgelin,
Mimmo Cosenza, Paul Stadig, and Miki Tebeka – their feedback made the
content so much better. Any errors or omissions, however, are only due to me.
Writing this book has been an arduous task. I want to thank my wife Binita for putting
up with me while I was immersed far too many days, nights, and weekends into the
book. If not for her support, I would not have been able to do justice to this book.
About the Reviewers
Jan Borgelin is the co-founder and CTO of BA Group Ltd., a Finnish IT consultancy
providing services for global enterprise clients. With over 10 years of professional
software development experience, Jan has had the chance to work with different
technologies and programming languages in international projects where performance
requirements have always been critical to the success of the project.
He has been involved in the Clojure community since 2008, he was a reveiwer for
the first edition of Programming Clojure, and he is also a contributor to the language.
Since 2010, he has been employed at Sonian, where he builds cloud-based distributed
systems in Clojure.
Miki Tebeka has been shipping software for more than 10 years. He has developed
a wide variety of products from assemblers and linkers to news trading systems and
cloud infrastructures. Miki currently works on the data pipeline at Demand Media.
In his free time, Miki is active in several open source communities.
www.PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF
and ePub files available? You can upgrade to the eBook version at www.PacktPub.com
and as a print book customer, you are entitled to a discount on the eBook copy. Get in
touch with us at service@packtpub.com for more details.
http://PacktLib.PacktPub.com
Why Subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print and bookmark content
• On demand and accessible via web browser
[ ii ]
Table of Contents
Summary 50
Chapter 4: Host Performance 51
The hardware 51
Processors 52
Branch prediction 52
Instruction scheduling 52
Threads and cores 53
Memory systems 54
Cache 55
Interconnect 55
Storage and networking 56
The Java Virtual Machine 56
The just-in-time (JIT) compiler 56
Memory organization 58
HotSpot heap and garbage collection 60
Measuring memory (heap/stack) usage 60
Measuring latency with Criterium 62
Criterium and Leiningen 63
Summary 64
Chapter 5: Concurrency 65
Low-level concurrency 65
Hardware memory barrier instructions 66
Java support and its Clojure equivalent 66
Atomic updates and state 68
Atomic updates in Java 68
Clojure's support for atomic updates 69
Asynchronous agents and state 70
Asynchrony, queuing, and error handling 72
Advantages of agents 73
Nesting 74
Coordinated transactional ref and state 74
Ref characteristics 75
Ref history and intransaction deref operations 76
Transaction retries and barging 77
Upping transaction consistency with ensure 77
Fewer transaction retries with commutative operations 78
Agents can participate in transactions 78
Nested transactions 79
Performance considerations 80
Dynamic var binding and state 80
[ iii ]
Table of Contents
[ iv ]
Table of Contents
Profiling 106
OS and CPU-cache-level profiling 108
I/O profiling 108
Performance tuning 108
JVM tuning 109
I/O tuning and backpressure 110
Summary 110
Chapter 7: Application Performance 111
Data sizing 111
Reduced serialization 112
Chunking to reduce memory pressure 113
Sizing for file/network operations 113
Sizing for JDBC query results 114
Resource pooling 115
JDBC resource pooling 116
I/O batching and throttling 116
JDBC batch operations 117
Batch support at API level 118
Throttling requests to services 119
Precomputing and caching 119
Concurrent pipelines 120
Distributed pipelines 121
Applying back pressure 121
Thread pool queues 122
Servlet containers like Tomcat and Jetty 122
HTTP Kit 123
Performance and queuing theory 123
Little's Law 124
Summary 124
Index 125
[v]
Preface
Clojure is a remarkably high-performance language despite its dynamic nature.
What really strikes you though is the fact that it combines performance with
fundamental simplicity and pragmatism, which makes it such a joy to program
in. Over the last six years since its first public release, Clojure has been heavily
tested and deployed in production by many people and organizations across
various domains. Its user base has grown rapidly during this period.
Clojure High Performance Programming is all about Clojure running on the Java Virtual
Machine. The JVM has a reputation of being a robust platform to develop and deploy
applications on. In this book, we take a deeper look at the performance characteristics
of various features of Clojure and the underlying environment. We also explore what it
takes to build well-performing software. We begin with the performance fundamentals
and gradually proceed over to Clojure and other matters you may have to deal with
while writing high-performance applications.
Understanding and achieving performance is both an art and a science, just like
writing good software. Remember the big picture in the back of your mind but
also be prepared to get into the details with measurement tools. More importantly,
know how the software works and keenly study the environment in which it runs.
I hope this book will help you on that path.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
ebookbell.com