Maximizing NET Performance 1st Edition Nick Wienholt (Auth.) - Get the ebook instantly with just one click
Maximizing NET Performance 1st Edition Nick Wienholt (Auth.) - Get the ebook instantly with just one click
https://ebookultra.com/download/5-conversations-how-to-transform-
trust-engagement-and-performance-at-work-2nd-edition-nick-cowley/
https://ebookultra.com/download/network-performance-open-source-
toolkit-using-netperf-tcptrace-nist-net-and-ssfnet-1st-edition-
richard-blum/
Pharmanomics 1st Edition Nick Dearden
https://ebookultra.com/download/pharmanomics-1st-edition-nick-dearden/
https://ebookultra.com/download/maximizing-return-on-investment-using-
erp-applications-1st-edition-weirich/
https://ebookultra.com/download/introducing-semantics-1st-edition-
riemer-nick/
https://ebookultra.com/download/advances-in-insect-physiology-
vol-29-1st-edition-peter-evans/
https://ebookultra.com/download/evil-inventions-nick-arnold/
Maximizing NET Performance 1st Edition Nick Wienholt
(Auth.) Digital Instant Download
Author(s): Nick Wienholt (auth.)
ISBN(s): 9781590591413, 1590591410
Edition: 1
File Details: PDF, 7.07 MB
Year: 2004
Language: english
Maximizing .NET
Performance
NICK WIENHOLT
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
means, electronic or mechanical, including photocopying, recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and the
publisher.
ISBN 978-1-59059-141-3 ISBN 978-1-4302-0784-9 (eBook)
DOI 10.1007/978-1-4302-0784-9
Trademarked names may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, we use the names only in an editorial fashion and to the
benefit of the trademark owner, with no intention of infringement of the trademark.
Technical Reviewer: Simon Robinson
Editorial Board: Dan Appleman, Craig Berry, Gary Comell, Tony Davis, Steven Rycroft, Julian
Skinner, Martin Streicher, Jim Sumser, Karen Watterson, Gavin Wray, John Zukowski
Assistant Publisher: Grace Wong
Copy Editor: Ami Knox
Production Manager: Kari Brooks
Proofreader: linda Seifert
Compositor: Gina Rexrode
Indexer: Michael Brinkman
Cover Designer: Kurt Krames
Manufacturing Manager: Tom Debolski
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219,
Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, email info@apress .com, or visit
http: I lwww. apress. com.
The information in this book is distributed on an "as is" basis, without warranty. Although
every precaution has been taken in the preparation of this work, neither the author(s) nor
Apress shall have any liability to any person or entity with respect to any loss or damage
caused or alleged to be caused directly or indirectly by the information contained in this work.
The source code for this bookis available to readers at http: I /1<11WW.apress.com in the
Downloads section.
To my wonderful wife, child, and family-
thank you for your love and support
Contents at a Glance
Foreward ..................................................... ..... .xiii
About the Author .................................................. .xv
About the Technical Reviewer ................................... .xvii
Acknowledgments .................................................. .xix
Introduction ..................................................... .xxi
Chapter 1 Introduction ....................................... .1
Chapter 2 Investigating Performance .......................... 9
Chapter 3 Type Design and Implementation .................. .25
Chapter 4 Strings, Text, and Regular Expressions ......... .47
Chapter 5 Collections ....................................... .63
Chapter 6 Language Specifies ............................... .85
Chapter 7 Garbage Collection and Object
Lifetime Management ............................. .101
Chapter 8 Exceptions ........................................ .121
Chapter 9 Security .......................................... .131
Chapter 10 Threading ......................................... .143
Chapter 11 10 and Serialization ............................ .163
Chapter 12 Remoting .......................................... .179
Chapter 13 Unmanaged Code Interoperability ................ .195
Chapter 14 The Common Language Runtime .................... .213
Chapter 15 Solving Performance Problems ................... .235
Appendix Benchmark Test Harness for • NET ............... .249
Index ..................................................... ....... .263
V
Contents
Foreword ..................................................... .... xiii
vili
Contents
ix
Contents
X
Contents
xi
Foreword
"Managed code is too slow. We've got to do this in C++."
-Anonymous
xili
Foreward
But knowing about the common language runtime's internals is still not
enough, as lots of performance issues actually turn up during application design
and not just during the coding stage. Collections, remoting, interoperability with
unmanaged code, and COM components are not the only things that come to
my mind in this regard.
It is the aim of Nick's book to enable you to understand the design issues as
well as the underlying CLR mechanisms in order to create the programs that run
on the better side ofthe 30-times performance d.ifference quoted in theACM
study. Nick really managed to create a book that addresses these issues, which
will otherwise turn up when carelessly coding to a managed environment. This
book will allow you to get into the details without being overwhelmed by the
underlying complexity of the common language runtime.
The only thing you have to resist after reading the book is the urge to
overoptimize your code. I was delighted to see that Nick begins with a discussion
of identifying an application's performance-critical sections and only later tums
towards isolating and resolving these real performance bottlenecks. This is, in
my opinion, one of the most important tasks-and also one of the most complex
ones-when working with large-scale applications.
And now read on and enjoy the ride to the better side of a 30-fold perfor-
mance difference.
xiv
About the Author
Nick Wienholt is a Wmdows and .NET consultant based in Sydney. Nick has
worked on a variety of IT projects over the last decade, ranging from numerical
modeling of beach erosion to financial and payroll systems, with the highly suc-
cessful Passenger Information Display System (PIDS) project that he worked on
as a consultant for Rail Services Australia being a career highlight. PIDS was
developed and installed prior to the Sydney 2000 Olympics and was a key com-
ponent in State Rail's success in moving hundreds of thousands of spectators
during the perlad the Olympic games were held.
Nickis a keen and active participant in the .NET community. He is the
cofounder of the Sydney Deep .NET User group; writes technical articles for
Pinnacle Publishing, Australian Developer Journal, and the Microsoft Developer
Network; is a keen participant in .NET-related newsgroups; and is a regular pre-
senter at technical conferences. An archive of Nick's SDNUG presentations and
articles is available at http: I /WtiW. dotnetperformance. com. In recognition of his
work in the .NET area, he was awarded the Microsoft Most Valued Professional
Award in 2002.
Nick can be contacted at [email protected].
XV
About the
Technical Reviewer
Slmon Robinson is a well-known author specializing in .NET programming,
and is editor of ASP Today, the leading ASP and ASP.NET-related Web site.
Simon's first experience with commercial computer programming was in the
early 1980s wben a computer project be was working on at college became the
college's student timetabling program, running on the BBC Micro. Later on be
studied for a Pb.D. in pbysics, and subsequently spent a couple of years
working as a university pbysics researcber-a large part of this time was spent
writing programs to do mathematical modeling of certain properties of super-
conductors. Somewbere around this time, be realized there was more money
to be bad in straight computer programming, and ended up at Lucent
Technologies doing mostlyWindows COM programming before finally becoming
self-employed, combining writing and freelance software development.
He bas extremely broad experience in programming on Windows. These
days bis core specialism is .NET programming, and be is comfortable coding in
C++, C#, VB, and IL; bis skills range from graphics and Wmdows Forms to
ASP.NET, to directories and data access, to Windows services and the native
WmdowsAPI.
Sirnon lives in Lancaster, U.K. His outside interests include theatre, dance,
performing arts, and politics.
You can visit Simon's personal Web site at http: I IWv~W. SirnonRobinson. com, or
the ASP Today site at http: I IWv~W. asptoday. com.
xvii
Acknowledgments
WRITING A BOOK CAN BE a long and lonely task, and without the constant support
of my wife, this book would never have made it out the door. I am etemally
indebted to her.
To my friends and colleagues in Sydney-Derek, Dan, Sam, Kristie, Troy,
Adam, Helen, and Chuck-many thanks for the conversation, criticisms, and
suggestions. The real-world sounding board that you provided was invaluable.
And finally, to the crew at Apress-Grace, Ami, and Kari on the production
side, Sirnon on technical review, and Dan and Gary on the management side.
Your assistance and support has made this book an immeasurably better
product.
xix
Introduction
LIKE OTHER AREAS OF nonfunetional software produetion, performanee is often
an afterthought to the eonstruetion proeess, and needs to be taeked onto an
existing eode base. With a new platform like .NET, the negative eonsequenees of
this produetion praetiee is more pronouneed, as developers and arehiteets do
not have the same depth of experienee that they did in the unmanaged world. In
the Internet age, produeing software with adequate performanee eharaeteristies
is more important than ever, and in a climate of shrinking IT budgets, throwing
hardware at poorly performing systems is no Ionger an option.
This book aims to arm developers and arehiteets with the knowledge they
need to design and implement software solutions that have great performanee
eharaeteristies on the .NET platform. A familiarity with the .NET Framework is
assumed, and if a reader is new to .NET, there are many wonderful titles from
Apress that ean provide a great introduetion to the platform. For readers who
know .NET and are seeking more advaneed material on the best way to build
performant software, this book has been written for you.
The book ean be read eover-to-eover, or a reader may ehoose to eonsume a
partiewar ehapter in isolation. When eonsuming ehapters in isolation, the reader
is eneouraged to read Chapters 1 and 2, whieh introduee the materials eovered
and lay the groundwork that the following ehapters build upon. Chapters 3
through 14 foeus on performanee issues specifie to a partiewar area of the .NET
Framework, and the material in these ehapters that relies on information in
other ehapters is deliberately highlighted for the reader who ehooses to
approaeh the material nonlinearly.
Chapter 15 presents a troubleshooting guide that aims to provide a system-
atie roadmap for diagnosing and solving performanee problems in .NET
applieations. The ehapter eovers the tools and teehniques that ean be used to
reliably work out why a program is running slowly or eonsuming too mueh
memory, and how the problern ean be solved.
The Appendix eovers the benehmark test harness that was used to eonduet
the benehmarks diseussed throughout the book. For those with an interest in
extending and adding to the benehmarks presented, this material will prove of
great interest.
The souree eode for this book is available from the Apress Web site
(http:/ /www.apress.com), and the reader is eneouraged to download and analyze
this material. The benehmark test harness has been written to allow easy repro-
duetion of the benehmarks refereneed in the book, and experimenting with
these benehmarks is a valuable learning aid. Curiosity is an essential prerequi-
site for understanding performanee, and the souree eode will hopefully provide
the starting point for many new performanee investigations for the reader.
xxi
CHAPTER 1
Introduction
SOFTWARE PERFORMANCE IS A topic rife with paradoxes, confusion, and mystery.
To provide a few examples:
This book attempts to peel back some of the mystery surrounding the per-
formance of code that targets the .NET Framework. The book has two main
goals-to present a detailed discussion on the performance of various .NET
Framework technologies, and to illustrate practices for conducting reliable per-
formance assessment on techniques and methodologies that are not covered in
the book. To address both these goals, every benchmark discussed in this book is
available for download from the publisher's Web site (http: I !WN. apress. com),
and each test is clearly numbered for quick location in the code samples. This
allows for an easy reproduction of the test runs on the reader's own systems, and
also for analysis of the code that makes up the test. Chapter 2 contains a detailed
discussion on conducting performance assessments, and the benchmark har-
ness used to conduct the benchmark results presented is fully documented in
the appendix.
The reader is encouraged to critically analyze the results presented. Service
packs and new versions of the .NET Framework and operatingsystemwill mean
that some of the results presented in this book may differ from those the reader
obtains. In other cases, small changes in a test case can significantly change the
performance of a method, and a test case on a partiewar technology may not
be relevant to other uses ofthe same technology. Subtle changes can bring sig-
nificant performance improvements, and a keen eye for detail is critical.
1
Chapter 1
Material Covered
The focus of this book is .NET Framework performance. The book concentrates
on Framework performance from the ground up, and does not include discus-
sions of higher-level technologies like Wmdows Forms, ASP.NET, and ADO.NET.
These technologies are important, and future volumes may weil be written that
focus on them, but it is critical to appreciate that all.NET code is built on a com-
mon base, which is the focus oftbis book. System-level developers will get the
most out of this book, but every attempt has been made to ensure that the mate-
rial is accessible and relevant to application developers who use higher-level
technologies. By developing a strong understanding of Framework performance,
application developers are in a much better position to identify and avoid per-
formance mistakes in both their own code and high-level application libraries.
Key areas of coverage include the following:
Comparison between .NET and competing platforms like J2EE is not covered.
While this information may be of interest to some, cross-technology performance
comparisons are prone to much controversy and conflicting results, as the recent
Pet Shop war between Java vendors and Microsoft demonstrated. At the end of the
day, most cross-technology comparisons are motivated by commercial considera-
tions, and do not assist developers in writing faster and more efficient code on
2
Introduction
either platform. This book is focused on gi.ving developers the information and
tools they need to write high-performance code using the .NET Framework, and
cross-platform sniping wowd only detract from that goal.
For readers interested in independently verified benchmark comparisons
between the afferings of various vendors, the Transaction Processing
Performance Council reswts, available at http: I /www. tpc. org, are an excellent
resource.
3
Chapter 1
Performance Priorities
It is important that some general performance goals are communicated to the
development team before development begins. A development task can fall into
three broad categories of performance priority.
Performance Insensitive
In this mode, performance really does not matter at all. The software can end up
quite slow with no real adverse consequences, and even naive performance mis-
takes are acceptable. Software that fits into this category is typically single- or
special-use, such as a program that will perform a once-off data migration task.
If the software ends up slow, the task can be run on a weekend or on a spare
machine; in this case development time and quality issues are much more
important than speed.
There is nothing inherently wrong with this development mode-in a num-
ber of project types, it is much better for a dient or manager when the software
comes in twice as cheap but ten times as slow. It is important that developers
can swallow their pride in this mode, and appreciate the pressures and priorities
under which the software is being developed.
Performance Sensitive
This is the normal development mode for most applications. In this mode, pro-
ducing software that is "not too slow" is the goal, though other development
priorities may be more important than performance. Producing detailed metrics
that describe how fast "not too slow" is can be hard to achieve, but a few simple
goals can be defined to allow a common understanding of the performance tar-
gets for the application. Forend-user applications, response time and memory
usage are two criteria that are easy for all Stakeholders to understand, and can
be defined as they relate to a target hardware environment. There will usually be
application actions that fall outside the response time goals, and the remedies
required in terms of both the product (for example, adding a progress bar) and
the project (for example, noting the issue in a project manual) should be
defined.
4
Other documents randomly have
different content
is removed. It requires an experienced hand to knead bread without
making it too heavy with flour.
Place the flour on the hot shelf to get thoroughly warm. Let it be
warm to the hand. Dissolve the yeast in a tablespoonful of water,
and add it, with the salt, to a quart of warm water. Turn the liquid
into the flour, reserving enough flour to use on the molding-board.
Mix it thoroughly. Turn it on to the board and form it into well-
shaped loaves. This quantity of material will make three loaves. Let
it rise in the pans to double in size, which will take about one and a
half hours. Bake for one hour.
This bread is made in about three hours. It is the most simple
receipt possible, and gives excellent results. Some judgment must be
used about the quantity of flour, as it takes a little more or less
according to its dryness.
WHOLE WHEAT BREAD
2½ quarts of whole wheat flour,
1 teaspoonful of salt,
½ cupful of molasses or of sugar,
½ cake of compressed yeast,
About 1 quart of water.
Add the salt to the water. Mix the molasses with part of the water
and with the yeast, which has been dissolved in a little water. Stir
the liquid into the flour, and add enough more water to make a thick
batter. Beat it for some time, or until it is well mixed and the batter
is smooth. Let it rise overnight. Early in the morning stir it down, and
turn it into the pans. Let it rise in the pans to double in size, and
bake for one hour. The above quantities will make two loaves.
NO. 186. BREAD-PAN WITH CLOSE-FITTING COVER.
The cover excludes the air from the dough, so no crust forms while it is rising.
Cut white and any kind of brown bread into slices from three
eighths to half an inch in thickness. Spread each slice generously
with butter which is soft enough to spread easily. Lay the slices
together in alternating colors, two buttered sides coming together in
each layer. When the pile of buttered slices is three and a half to
four inches high, cut it into good shape, removing the crusts. Place
the bread between two plates under a light weight and set it into the
ice-box to harden the butter. When ready to serve, cut it into slices
about as thick as the original slices, and then into strips.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com