Addison wesley java performance and scalability volume 1 server side programming techniques jun 2000 ISBN 0201704293

466 164 0
Addison wesley java performance and scalability volume 1 server side programming techniques jun 2000 ISBN 0201704293

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

• Table of Contents Java™ Performance and Scalability Volume 1: Server-Side Programming Techniques By Dov Bulka Publisher : Addison Wesley Pub Date : June 05, 2000 ISBN : 0-201-70429-3 Pages : 320 This book was written with one goal in mind: to provide Java programmers with the expertise needed to build efficient, scalable Java code The author shares his experience in server-side performance tuning through measured performance assessments, called optimizations Each optimization discusses techniques to improve the performance and scalability of your code Every claim is substantiated with hard numbers and an experience-based evaluation Java(TM) Performance and Scalability, Volume 1, provides invaluable advice that you will, no doubt, find useful in your coding Presented in 48 concise lessons that target the most common and critical performance pitfalls, this book offers a plethora of practical tips and solutions for boosting the performance of your programs These lessons cover performance-critical areas such as memory management, garbage collection, caching, and multithreading Specific lessons include: Reserving StringBuffer capacity Avoiding premature object creation Creating an efficient vector class Designing caching into your API The cost of synchronization Parallel subtasks JNI efficiency Varying the server workload and RMI network plumbing Using ServletOutputStream Caching JDBC(TM) connections In addition to providing hard numbers that quantify the optimizations, the author concludes the book with an application demonstrating the effectiveness of the performance optimizations The exercise takes a typical program and increases its performance fourfold through a series of steps that tie together the lessons learned throughout the book He offers both the means and the proof to better coding b[0] = (byte) '\r'; b[1] = (byte) '\n'; int blen = 2; while ((n = is.read(buf)) > 0) { ps.write(buf, 0, n); // Assuming everything fits in a single buffer System.arraycopy(buf,0,b,blen,n); blen += n; } FileInfo fi = urlCache.get(url); if (fi != null) { byte [] c = new byte[blen]; System.arraycopy(b,0,c,0,blen); fi.setContent(c); } } finally { is.close(); } } // Mapping of file extensions to content types static Hashtable map = new Hashtable(); static { fillMap(); } static void setSuffix(String k, String v) { map.put(k, v); } // Partial list of HTTP content types static void fillMap() { setSuffix(".htm", "text/html"); setSuffix(".html", "text/html"); setSuffix("", "content/unknown"); setSuffix(".zip", "application/zip"); setSuffix(".tar", "application/x-tar"); setSuffix(".gif", "image/gif"); setSuffix(".jpg", "image/jpeg"); setSuffix(".jpeg", "image/jpeg"); setSuffix(".text", "text/plain"); setSuffix(".txt", "text/plain"); } } // Partial list of HTTP status codes interface HttpConstants { public static final int HTTP_OK = 200; public static final int HTTP_BAD_REQUEST = 400; public static final int HTTP_UNAUTHORIZED = 401; public static final int HTTP_NOT_FOUND = 404; public static final int HTTP_BAD_METHOD = 405; } import java.util.*; import java.io.*; class FileInfo { private byte[] headers; private byte[] content; private long lastUpdate; private byte[] logSecondHalf; FileInfo (byte[] h, long lu) { headers = h; content = null; lastUpdate = lu; logSecondHalf = null; } public void setHeaders(byte[] h) { headers = h; } public void setContent(byte[] c) { content = c; } public void setLastUpdate(long t) { lastUpdate = t; } public void setLogSecondHalf(byte[] s) { logSecondHalf = s; } public byte[] getHeaders() { return headers; } public byte[] getContent() { return content; } public long getLastUpdate() { return lastUpdate; } public byte[] getLogSecondHalf() { return logSecondHalf; } } import java.util.*; import java.io.*; import FileInfo; class UrlCache { private Hashtable ht = new Hashtable(); private long cacheRefresh; public UrlCache(long refresh) { cacheRefresh = refresh; } public void put(String url, FileInfo fi) { ht.put(url, fi); } public FileInfo get(String url) { FileInfo fi = (FileInfo) ht.get(url); if (fi == null) { return null; } long now = System.currentTimeMillis(); if ((nowfi.getLastUpdate()) > cacheRefresh ) { ht.remove(url); return null; } return fi; } } import java.util.*; class LazyDate { private long lastCheck = 0; // Never checked before private String today; private long cacheRefresh; public LazyDate(long refresh) { cacheRefresh = refresh; update(); } public String todaysDate() { long now = System.currentTimeMillis(); if ((nowlastCheck) > cacheRefresh) { update(); } return today; } private void update() { lastCheck = System.currentTimeMillis(); today = (new Date()).toString(); } } MyGetBytes.java public class MyGetBytes { public static byte[] asciiGetBytes(String buf) { int size = buf.length(); int i; byte[] bytebuf = new byte[size]; for (i = 0; i < size; i++) { bytebuf[i] = (byte)buf.charAt(i); } return bytebuf; } } server.properties log=server.log timeout=5000 workers=8 Bibliography [AHU74] A Aho, J Hopcroft, and J Ullman, The Design and Analysis of Computer Algorithms, AddisonWesley, Reading, MA (1974) [BEN82] J L Bentley, Writing Efficient Programs, Prentice-Hall, Englewood Cliffs, NJ (1982) [BM97] B Meyer, Object-Oriented Software Construction, Second Edition, Prentice-Hall PTR, Englewood Cliffs, NJ (1997) [BM99] D Bulka and D Mayhew, Efficient C++, Addison Wesley Longman, Reading, MA (1999) [BR95] A Binstock and J Rex, Practical Algorithms for Programmers, Addison Wesley Longman, Reading, MA (1995) [BW97] J Beveridge and R Wiener, Multithreading Applications in Win32, Addison Wesley Longman, Reading, MA (1997) [CAM91] M Campbell et al., "The Parallelization of UNIX System V Release 4.0," Proceedings of the Winter 1991 USENIX Conference [CM98] Chet Murthy, private communication (1988) [DB99] D Brown, "A Simple, Multithreaded Web Server," http://developer.javasoft.com/developer/technicalArticles/Networking/Webserver/index.html [GH95] E Gamma, R Helm, R Johnson, and J Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software, Addison-Wesley, Reading, MA (1994) [GJS96] J Gosling, B Joy, and G Steele, The Java Language Specification, Addison Wesley Longman, Reading, MA (1996) [HP96] J Hennessy and D Patterson, Computer Architecture: A Quantitive Approach, Morgan Kaufmann, San Francisco, CA (1995) [JE99] J Engel, Programming for the Java Virtual Machine, Addison Wesley Longman, Reading, MA (1999) [JH98] J Hunter and W Crawford, Java Servlet Programming, O'Reilly & Associates, Inc., Cambridge, MA (1999) [KNU97a] D E Knuth, The Art of Computer Programming: Fundamental Algorithms, Volume I, Third Edition, Addison Wesley Longman, Reading, MA (1997) [KNU97b] D E Knuth, The Art of Computer Programming: Seminumerical Algorithms, Volume II, Third Edition, Addison Wesley Longman, Reading, MA (1997) [KNU97c] D E Knuth, The Art of Computer Programming: Sorting and Searching, Volume III, Second Edition, Addison Wesley Longman, Reading, MA (1997) [LEA97] D Lea, Concurrent Programming in Java, Addison Wesley Longman, Reading, MA (1997) [LY97] T Lindholm and F Yellin, The Java Virtual Machine Specification, Addison Wesley Longman, Reading, MA (1997) [NBF96] B Nichols, D Buttlar, and J P Farrell, Pthreads Programming: A Posix Standard for Better Understanding, O'Reilly & Associates, Inc., Cambridge, MA (1997) [PFI98] G Pfister, In Search of Clusters, Second Edition, Prentice-Hall PTR, Upper Saddle River, NJ (1998) [PH97] D Patterson and J Hennessy, Computer Organization and Design: The Hardware/Software Interface, Morgan Kaufmann, San Francisco, CA (1998) [SB99] S Ball, Supercharged strings, Java Report, Vol 4, No 2, Feb 1999 [SF99] "SanFrancisco Performance Tips & Techniques Redbook," http://www4.ibm.com/software/ad/sanfrancisco/library.html [SS98] Scott Snyder, private communication (1998) [WB99] A Wirfs-Brock, Complex Java applications—Breaking the speed limit, In Java Report, Vol 4, No 1, Jan 1999 ... connections Figure 10 .10 PingJsp Java Server Pages Figure 10 .11 PingRmi performance relative to other servlets Chapter 11 Figure 11 .1 Comparing the original (version 1) to version 2 Figure 11 .2 Adding version 3 to the mix... offers both the means and the proof to better coding • Table of Contents Java Performance and Scalability Volume 1: Server- Side Programming Techniques By Dov Bulka Publisher : Addison Wesley Pub Date : June 05, 2000. .. Includes bibliographical references and index Contents: v Server- side techniques ISBN 0-2 01- 70429-3 Java (Computer program language) I Title QA76.73.J38 B84 2000 005 .13 '3—dc 21 00-0256 61 Text printed on recycled paper 1 2 3 4 5 6 7 8 9 10 -ML-04 03 02 01 00

Ngày đăng: 26/03/2019, 17:11

Từ khóa liên quan

Mục lục

  • Main Page

  • Table of content

  • Copyright

  • List of Figures

    • Chapter 1

    • Chapter 2

    • Chapter 3

    • Chapter 5

    • Chapter 6

    • Chapter 7

    • Chapter 8

    • Chapter 9

    • Chapter 10

    • Chapter 11

    • Preface

    • Introduction

      • Java Speed

      • The Test Environment

      • Before You Optimize: A Word of Caution

      • Organization of This Book

      • Acknowledgments

      • Chapter 1. Java 'Strings'

        • Optimization 1: 'String' Concatenation

Tài liệu cùng người dùng

Tài liệu liên quan