Book Image

Clojure High Performance Programming

By : Shantanu Kumar
Book Image

Clojure High Performance Programming

By: Shantanu Kumar

Overview of this book

<p>Clojure is a young, dynamic, functional programming language that runs on the Java Virtual Machine. It is built with performance, pragmatism, and simplicity in mind. Like most general purpose languages, Clojure’s features have different performance characteristics that one should know in order to write high performance code.<br /><br />Clojure High Performance Programming is a practical, to-the-point guide that shows you how to evaluate the performance implications of different Clojure abstractions, learn about their underpinnings, and apply the right approach for optimum performance in real-world programs.<br /><br />This book discusses the Clojure language in the light of performance factors that you can exploit in your own code.</p> <p>You will also learn about hardware and JVM internals that also impact Clojure’s performance. Key features include performance vocabulary, performance analysis, optimization techniques, and how to apply these to your programs. You will also find detailed information on Clojure's concurrency, state-management, and parallelization primitives.</p> <p>This book is your key to writing high performance Clojure code using the right abstraction, in the right place, using the right technique.</p>
Table of Contents (15 chapters)
Clojure High Performance Programming
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

I/O batching and throttling


It is well known that chatty I/O calls generally lead to poor performance. The solution is to batch together several messages and send them in one payload. In databases and network calls, batching is a common useful technique to improve throughput. On the other hand, large batch sizes may actually harm throughput as they tend to incur memory overhead and components may not be ready to handle a large batch at once. Hence, sizing the batches and throttling are just as important as batching. I would strongly advise conducting your own tests to determine the optimum batch size under representative load.

JDBC batch operations

JDBC has batch-update support in its API, which includes the INSERT, UPDATE, and DELETE statements. The Clojure Contrib library java.jdbc supports JDBC batch operations via its own API as shown in the following code snippet:

(require '[clojure.java.jdbc :as jdbc])

;; multiple SQL statements
(db-do-commands
  db true
  ["INSERT INTO emp (name, countrycode...