Java Performance Tuning Second Edition Jack Shirazi
Java Performance Tuning Second Edition Jack Shirazi
Java Performance Tuning Second Edition Jack Shirazi
Java Performance Tuning Second Edition Jack Shirazi
Java Performance Tuning Second Edition Jack Shirazi
1.
Java Performance TuningSecond Edition Jack
Shirazi pdf download
https://ebookfinal.com/download/java-performance-tuning-second-
edition-jack-shirazi/
Explore and download more ebooks or textbooks
at ebookfinal.com
2.
We have selectedsome products that you may be interested in
Click the link to download now or visit ebookfinal.com
for more options!.
Oracle Performance Tuning for 10g R2 2nd Edition Gavin
Powell (Auth.)
https://ebookfinal.com/download/oracle-performance-tuning-
for-10g-r2-2nd-edition-gavin-powell-auth/
Java Performance 1st Edition Charlie Hunt
https://ebookfinal.com/download/java-performance-1st-edition-charlie-
hunt/
OCP Oracle9i Performance Tuning Study Guide with CDROM 1st
Edition Joseph C. Johnson
https://ebookfinal.com/download/ocp-oracle9i-performance-tuning-study-
guide-with-cdrom-1st-edition-joseph-c-johnson/
The Veil Unveiled 1st Edition Faegheh Shirazi
https://ebookfinal.com/download/the-veil-unveiled-1st-edition-faegheh-
shirazi/
3.
Java Servlet ProgrammingSecond Edition Jason Hunter
https://ebookfinal.com/download/java-servlet-programming-second-
edition-jason-hunter/
Java Message Service Second Edition Mark Richards
https://ebookfinal.com/download/java-message-service-second-edition-
mark-richards/
NATEF Standards Job Sheets Engine Performance A8 Third
Edition Jack Erjavec
https://ebookfinal.com/download/natef-standards-job-sheets-engine-
performance-a8-third-edition-jack-erjavec/
Object Oriented Programming and Java Second Edition Danny
Poo
https://ebookfinal.com/download/object-oriented-programming-and-java-
second-edition-danny-poo/
Developing Performance Indicators for Managing Maintenance
Second Edition Wireman
https://ebookfinal.com/download/developing-performance-indicators-for-
managing-maintenance-second-edition-wireman/
5.
Java Performance TuningSecond Edition Jack Shirazi
Digital Instant Download
Author(s): Jack Shirazi
ISBN(s): 9780596003777, 0596003773
Edition: Second Edition
File Details: PDF, 1.79 MB
Year: 2003
Language: english
O’reilly - JavaPerformance Tuning
- 4 -
10.1 User-Interface Thread and Other Threads
10.2 Race Conditions
10.3 Deadlocks
10.4 Synchronization Overheads
10.5 Timing Multithreaded Tests
10.6 Atomic Access and Assignment
10.7 Thread Pools
10.8 Load Balancing
10.9 Threaded Problem-Solving Strategies
10.10 Performance Checklist
11. Appropriate Data Structures and Algorithms - 233
11.1 Collections
11.2 Java 2 Collections
11.3 Hashtables and HashMaps
11.4 Cached Access
11.5 Caching Example I
11.6 Caching Example II
11.7 Finding the Index for Partially Matched Strings
11.8 Search Trees
11.9 Performance Checklist
12. Distributed Computing - 264
12.1 Tools
12.2 Message Reduction
12.3 Comparing Communication Layers
12.4 Caching
12.5 Batching I
12.6 Application Partitioning
12.7 Batching II
12.8 Low-Level Communication Optimizations
12.9 Distributed Garbage Collection
12.10 Databases
12.11 Performance Checklist
13. When to Optimize - 281
13.1 When Not to Optimize
13.2 Tuning Class Libraries and Beans
13.3 Analysis
13.4 Design and Architecture
13.5 Tuning After Deployment
13.6 More Factors That Affect Performance
13.7 Performance Checklist
14. Underlying Operating System and Network Improvements - 304
14.1 Hard Disks
14.2 CPU
14.3 RAM
14.4 Network I/O
14.5 Performance Checklist
15. Further Resources - 315
15.1 Books
15.2 Magazines
15.3 URLs
15.4 Profilers
15.5 Optimizers
Colophon - 317
10.
O’reilly - JavaPerformance Tuning
- 5 -
Preface
Performance has been an important issue with Java™ since the first version hit the Web years ago.
Making those first interpreted programs run fast enough was a huge challenge for many developers.
Since then, Java performance has improved enormously, and any Java program can now be made to
run fast enough provided you avoid the main performance pitfalls.
This book provides all the details a developer needs to performance-tune any type of Java program.
I give step-by-step instructions on all aspects of the performance-tuning process, right from early
considerations such as setting goals, measuring performance, and choosing a compiler, to detailed
examples on using profiling tools and applying the results to tune the code. This is not an entry-
level book about Java, but you do not need any previous tuning knowledge to benefit from reading
it.
Many of the tuning techniques presented in this book lead to an increased maintenance cost, so they
should not be applied arbitrarily. Change your code only when a bottleneck has been identified, and
never change the design of your application for minor performance gains.
Contents of This Book
Chapter 1 gives general guidelines on how to tune. If you do not yet have a tuning strategy, this
chapter provides a methodical tuning process.
Chapter 2 covers the tools you need to use while tuning. Chapter 3 looks at the Java Development
Kit™ ( JDK, now Java SDK), including VMs and compilers.
Chapter 4 through Chapter 12 cover various techniques you can apply to Java code. Chapter 12
looks at tuning techniques specific to distributed applications.
Chapter 13 steps back from the low-level code-tuning techniques examined throughout most of the
book and considers tuning at all other stages of the development process.
Chapter 14 is a quick look at some operating system-level tuning techniques.
Each chapter has a performance tuning checklist at its end. Use these lists to ensure that you have
not missed any core tuning techniques while you are tuning.
Virtual Machine (VM) Versions
I have focused on the Sun VMs since there is enough variation within these to show interesting
results. I have shown the time variation across different VMs for many of the tests. However, your
main focus should be on the effects that tuning has on any one VM, as this identifies the usefulness
of a tuning technique. Differences between VMs are interesting, but are only indicative and need to
be verified for your specific application. Where I have shown the results of timed tests, the VM
versions I have used are:
1.1.6
Version 1.1.x VMs do less VM-level work than later Java 2 VMs, so I have used a 1.1.x VM
that includes a JIT. Version 1.1.6 was the earliest 1.1.x JDK that included enough
optimizations to be a useful base. Despite many later improvements throughout the JDK, the
11.
O’reilly - JavaPerformance Tuning
- 6 -
1.1.x VMs from 1.1.6 still show the fastest results for some types of tests. Version 1.1.6
supports running with and without a JIT. The default is with a JIT, and this is the mode used
for all measurements in the book.
1.2
I have used the 1.2.0 JDK for the 1.2 tests. Java 2 VMs have more work to do than prior
VMs because of additional features such as Reference objects, and 1.2.0 is the first Java 2
VM. Version 1.2 supports running with and without a JIT. The default is with a JIT, and this
is the mode used for measurements labeled "1.2." Where I've labeled a measurement "1.2 no
JIT," it uses the 1.2 VM in interpreted mode with the -Djava.compiler=NONE option to set
that property.
1.3
I have used both the 1.3.0 full release and the 1.3 prerelease, as the 1.3 full release came out
very close to the publication time of the book. Version 1.3 supports running in interpreted
mode or with client-tuned HotSpot technology (termed "mixed" mode). Version 1.3 does not
support a pure JIT mode. The default is the HotSpot technology, and this is the mode I've
used for measurements labeled simply "1.3."
HotSpot 1.0
HotSpot 1.0 VM was run with the 1.2.0 JDK classes. Because HotSpot optimizations
frequently do not kick in until after the program has run for a little while, I sometimes show
measurements labeled "HotSpot 2nd Run." This set of measurements is the result from
repeating the particular test within the same VM session, i.e., the VM does not exit between
the first and second runs of the test.
Conventions Used in This Book
The following font conventions are used in this book:
Italic is used for:
• Pathnames, filenames, and program names
• Internet addresses, such as domain names and URLs
• New terms where they are defined
Constant width is used for:
• All Java code
• Command lines and options that should be typed verbatim
• Names and keywords in Java programs, including method names, variable names, and class
names
Constant width bold is used for emphasis in some code examples.
12.
O’reilly - JavaPerformance Tuning
- 7 -
Comments and Questions
The information in this book has been tested and verified, but you may find that features have
changed (or you may even find mistakes!). You can send any errors you find, as well as suggestions
for future editions, to:
O'Reilly & Associates, Inc.
101 Morris Street
Sebastopol, CA 95472
(800) 998-9938 (in the United States or Canada)
(707) 829-0515 (international/local)
(707) 829-0104 (fax)
You can also send messages electronically. To be put on the mailing list or request a catalog, send
email to:
info@oreilly.com
To ask technical questions or comment on the book, send email to:
bookquestions@oreilly.com
There is a web site for the book, where examples, errata, and any plans for future editions are listed.
You can access this site at:
http://www.oreilly.com/catalog/javapt/
For more information about this book and others, see the O'Reilly web site:
http://www.oreilly.com
Acknowledgments
A huge thank you to my wonderful wife Ava, for her unending patience with me. This book would
have been considerably poorer without her improvements in clarity and consistency throughout. I
am also very grateful to Mike Loukides and Kirk Pepperdine for the enormously helpful assistance I
received from them while writing this book. Their many notes have helped to make this book much
clearer and complete.
Thanks also to my reviewers, Patrick Killelea, Ethan Henry, Eric Brower, and Bill Venners, who
provided many useful comments. They identified several errors and added good advice that makes
this book more useful.
I am, of course, responsible for the final text of this book, including any erroors tthat rremain.
Chapter 1. Introduction
The trouble with doing something right the first time is that nobody appreciates how difficult it was.
—Fortune
13.
O’reilly - JavaPerformance Tuning
- 8 -
There is a general perception that Java programs are slow. Part of this perception is pure
assumption: many people assume that if a program is not compiled, it must be slow. Part of this
perception is based in reality: many early applets and applications were slow, because of
nonoptimal coding, initially unoptimized Java Virtual Machines (VMs), and the overheads of the
language.
In earlier versions of Java, you had to struggle hard and compromise a lot to make a Java
application run quickly. More recently, there have been fewer reasons why an application should be
slow. The VM technology and Java development tools have progressed to the point where a Java
application (or applet, servlet, etc.) is not particularly handicapped. With good designs and by
following good coding practices and avoiding bottlenecks, applications usually run fast enough.
However, the truth is that the first (and even several subsequent) versions of a program written in
any language are often slower than expected, and the reasons for this lack of performance are not
always clear to the developer.
This book shows you why a particular Java application might be running slower than expected, and
suggests ways to avoid or overcome these pitfalls and improve the performance of your application.
In this book I've gathered several years of tuning experiences in one place. I hope you will find it
useful in making your Java application, applet, servlet, and component run as fast as you need.
Throughout the book I use the generic words "application" and "program" to cover Java
applications, applets, servlets, beans, libraries, and really any use of Java code. Where a technique
can be applied only to some subset of these various types of Java programs, I say so. Otherwise, the
technique applies across all types of Java programs.
1.1 Why Is It Slow?
This question is always asked as soon as the first tests are timed: "Where is the time going? I did
not expect it to take this long." Well, the short answer is that it's slow because it has not been
performance-tuned. In the same way the first version of the code is likely to have bugs that need
fixing, it is also rarely as fast as it can be. Fortunately, performance tuning is usually easier than
debugging. When debugging, you have to fix bugs throughout the code; in performance tuning , you
can focus your effort on the few parts of the application that are the bottlenecks.
The longer answer? Well, it's true that there are overheads in the Java runtime system, mainly due
to its virtual machine layer that abstracts Java away from the underlying hardware. It's also true that
there are overheads from Java's dynamic nature. These overhead s can cause a Java application to
run slower than an equivalent application written in a lower-level language ( just as a C program is
generally slower than the equivalent program written in assembler). Java's advantages—namely, its
platform-independence, memory management, powerful exception checking, built-in
multithreading, dynamic resource loading, and security checks—add costs in terms of an
interpreter, garbage collector, thread monitors, repeated disk and network accessing, and extra
runtime checks.
For example, hierarchical method invocation requires an extra computation for every method call,
because the runtime system has to work out which of the possible methods in the hierarchy is the
actual target of the call. Most modern CPU s are designed to be optimized for fixed call and branch
targets and do not perform as well when a significant percentage of calls need to be computed on
the fly. On the other hand, good object-oriented design actually encourages many small methods
and significant polymorphism in the method hierarchy. Compiler inlining is another frequently used
technique that can significantly improve compiled code. However, this technique cannot be applied
14.
O’reilly - JavaPerformance Tuning
- 9 -
when it is too difficult to determine method calls at compile time, as is the case for many Java
methods.
Of course, the same Java language features that cause these overheads may be the features that
persuaded you to use Java in the first place. The important thing is that none of these overheads
slows the system down too much. Naturally, "too much" is different depending on the application,
and the users of the application usually make this choice. But the key point with Java is that a good
round of performance tuning normally makes your application run as fast as you need it to run.
There are already plenty of nontrivial Java applications, applets, and servlets that run fast enough to
show that Java itself is not too slow. So if your application is not running fast enough, chances are
that it just needs tuning.
1.2 The Tuning Game
Performance tuning is similar to playing a strategy game (but happily, you are usually paid to do
it!). Your target is to get a better score (lower time) than the last score after each attempt. You are
playing with, not against, the computer, the programmer, the design and architecture, the compiler,
and the flow of control. Your opponents are time, competing applications, budgetary restrictions,
etc. (You can complete this list better than I can for your particular situation.)
I once attended a customer who wanted to know if there was a "go faster" switch somewhere that he
could just turn on and make the whole application go faster. Of course, he was not really expecting
one, but checked just in case he had missed a basic option somewhere.
There isn't such a switch, but very simple techniques sometimes provide the equivalent. Techniques
include switching compilers , turning on optimizations, using a different runtime VM, finding two
or three bottlenecks in the code or architecture that have simple fixes, and so on. I have seen all of
these give huge improvements to applications, sometimes a 20-fold speedup. Order-of-magnitude
speedups are typical for the first round of performance tuning.
1.3 System Limitations and What to Tune
Three resource s limit all applications:
• CPU speed and availability
• System memory
• Disk (and network) input/output (I/O)
When tuning an application, the first step is to determine which of these is causing your application
to run too slowly.
If your application is CPU -bound, you need to concentrate your efforts on the code, looking for
bottlenecks, inefficient algorithms, too many short-lived objects (object creation and garbage
collection are CPU-intensive operations), and other problems, which I will cover in this book.
If your application is hitting system-memory limits, it may be paging sections in and out of main
memory. In this case, the problem may be caused by too many objects, or even just a few large
objects, being erroneously held in memory; by too many large arrays being allocated (frequently
used in buffered applications); or by the design of the application, which may need to be
reexamined to reduce its running memory footprint.
15.
O’reilly - JavaPerformance Tuning
- 10 -
On the other hand, external data access or writing to the disk can be slowing your application. In
this case, you need to look at exactly what you are doing to the disks that is slowing the application:
first identify the operations, then determine the problems, and finally eliminate or change these to
improve the situation.
For example, one program I know of went through web server logs and did reverse lookups on the
IP addresses. The first version of this program was very slow. A simple analysis of the activity
being performed determined that the major time component of the reverse lookup operation was a
network query. These network queries do not have to be done sequentially. Consequently, the
second version of the program simply multithreaded the lookups to work in parallel, making
multiple network queries simultaneously, and was much, much faster.
In this book we look at the causes of bad performance. Identifying the causes of your performance
problems is an essential first step to solving those problems. There is no point in extensively tuning
the disk-accessing component of an application because we all know that "disk access is much
slower than memory access" when, in fact, the application is CPU-bound.
Once you have tuned the application's first bottleneck, there may be (and typically is) another
problem, causing another bottleneck. This process often continues over several tuning iterations. It
is not uncommon for an application to have its initial "memory hog" problems solved, only to
become disk-bound, and then in turn CPU-bound when the disk-access problem is fixed. After all,
the application has to be limited by something, or it would take no time at all to run.
Because this bottleneck-switching sequence is normal—once you've solved the existing bottleneck,
a previously hidden or less important one appears—you should attempt to solve only the main
bottlenecks in an application at any one time. This may seem obvious, but I frequently encounter
teams that tackle the main identified problem, and then instead of finding the next real problem,
start applying the same fix everywhere they can in the application.
One application I know of had a severe disk I/O problem caused by using unbuffered streams (all
disk I/O was done byte by byte, which led to awful performance). After fixing this, some members
of the programming team decided to start applying buffering everywhere they could, instead of
establishing where the next bottleneck was. In fact, the next bottleneck was in a data-conversion
section of the application that was using inefficient conversion methods, causing too many
temporary objects and hogging the CPU. Rather than addressing and solving this bottleneck, they
instead created a large memory allocation problem by throwing an excessive number of buffers into
the application.
1.4 A Tuning Strategy
Here's a strategy I have found works well when attacking performance problems:
1. Identify the main bottlenecks (look for about the top five bottlenecks, but go higher or lower
if you prefer).
2. Choose the quickest and easiest one to fix, and address it (except for distributed applications
where the top bottleneck is usually the one to attack: see the following paragraph).
3. Repeat from Step 1.
This procedure will get your application tuned the quickest. The advantage of choosing the
"quickest to fix" of the top few bottlenecks rather than the absolute topmost problem is that once a
bottleneck has been eliminated, the characteristics of the application change, and the topmost
bottleneck may not even need to be addressed any longer. However, in distributed applications I
16.
O’reilly - JavaPerformance Tuning
- 11 -
advise you target the topmost bottleneck. The characteristics of distributed applications are such
that the main bottleneck is almost always the best to fix and, once fixed, the next main bottleneck is
usually in a completely different component of the system.
Although this strategy is simple and actually quite obvious, I nevertheless find that I have to repeat
it again and again: once programmers get the bit between their teeth, they just love to apply
themselves to the interesting parts of the problems. After all, who wants to unroll loop after boring
loop when there's a nice juicy caching technique you're eager to apply?
You should always treat the actual identification of the cause of the performance bottleneck as a
science, not an art. The general procedure is straightforward:
1. Measure the performance using profilers and benchmark suites, and by instrumenting code.
2. Identify the locations of any bottlenecks.
3. Think of a hypothesis for the cause of the bottleneck.
4. Consider any factors that may refute your hypothesis.
5. Create a test to isolate the factor identified by the hypothesis.
6. Test the hypothesis.
7. Alter the application to reduce the bottleneck.
8. Test that the alteration improves performance, and measure the improvement (include
regression testing the affected code).
9. Repeat from Step 1.
Here's the procedure for a particular example:
1. Run the application through your standard profiler (measurement).
2. You find that the code spends a huge 11% of time in one method (identification of
bottleneck).
3. Looking at the code, you find a complex loop and guess this is the problem (hypothesis).
4. You see that it is not iterating that many times, so possibly the bottleneck could be outside
the loop (confounding factor).
5. You could vary the loop iteration as a test to see if that identifies the loop as the bottleneck.
However, you instead try to optimize the loop by reducing the number of method calls it
makes: this provides a test to identify the loop as the bottleneck and at the same time
provides a possible solution. In doing this, you are combining two steps, Steps 5 and 7.
Although this is frequently the way tuning actually goes, be aware that this can make the
tuning process longer: if there is no speedup, it may be because your optimization did not
actually make things faster, in which case you have neither confirmed nor eliminated the
loop as the cause of the bottleneck.
6. Rerunning the profile on the altered application finds that this method has shifted its
percentage time down to just 4%. This may still be a candidate bottleneck for further
optimization, but nevertheless it's confirmed as the bottleneck and your change has
improved performance.
7. (Already done, combined with Step 5).
8. (Already done, combined with Step 6).
1.5 Perceived Performance
It is important to understand that the user has a particular view of performance that allows you to
cut some corners. The user of an application sees changes as part of the performance. A browser
that gives a running countdown of the amount left to be downloaded from a server is seen to be
faster than one that just sits there, apparently hung, until all the data is downloaded. People expect
17.
O’reilly - JavaPerformance Tuning
- 12 -
to see something happening, and a good rule of thumb is that if an application is unresponsive for
more than three seconds, it is seen to be slow. Some Human Computer Interface authorities put the
user-patience limit at just two seconds; an IBM study from the early '70s suggested people's
attention began to wander after waiting for more than just one second. For performance
improvements, it is also useful to know that users are not generally aware of response time
improvements of less than 20%. This means that when tuning for user perception, you should not
deliver any changes to the users until you have made improvements that add more than a 20%
speedup.
A few long response times make a bigger impression on the memory than many shorter ones.
According to Arnold Allen,[1]
the perceived value of the average response time is not the average,
but the 90th percentile value: the value that is greater than 90% of all observed response times. With
a typical exponential distribution, the 90th percentile value is 2.3 times the average value.
Consequently, so long as you reduce the variation in response times so that the 90th percentile value
is smaller than before, you can actually increase the average response time, and the user will still
perceive the application as faster. For this reason, you may want to target variation in response
times as a primary goal. Unfortunately, this is one of the more complex targets in performance
tuning: it can be difficult to determine exactly why response times are varying.
[1]
Introduction to Computer Performance Analysis with Mathematica (Academic Press).
If the interface provides feedback and allows the user to carry on other tasks or abort and start
another function (preferably both), the user sees this as a responsive interface and doesn't consider
the application as slow as he might otherwise. If you give users an expectancy of how long a
particular task might take and why, they often accept that this is as long as it has to take and adjust
their expectations. Modern web browsers provide an excellent example of this strategy in practice.
People realize that the browser is limited by the bandwidth of their connection to the Internet, and
that downloading cannot happen faster than a given speed. Good browsers always try to show the
parts they have already received so that the user is not blocked, and they also allow the user to
terminate downloading or go off to another page at any time, even while a page is partly
downloaded. Generally, it is not the browser that is seen to be slow, but rather the Internet or the
server site. In fact, browser creators have made a number of tradeoffs so that their browsers appear
to run faster in a slow environment. I have measured browser display of identical pages under
identical conditions and found browsers that are actually faster at full page display, but seem slower
because they do not display partial pages, or download embedded links concurrently, etc. Modern
web browsers provide a good example of how to manage user expectations and perceptions of
performance.
However, one area in which some web browsers have misjudged user expectation is when they give
users a momentary false expectation that operations have finished when in fact another is to start
immediately. This false expectation is perceived as slow performance. For example, when
downloading a page with embedded links such as images, the browser status bar often shows
reports like "20% of 34K," which moves up to "56% of 34K," etc., until it reaches 100% and
indicates that the page has finished downloading. However, at this point, when the user expects that
all the downloading has finished, the status bar starts displaying "26% of 28K" and so on, as the
browser reports separately on each embedded graphic as it downloads them. This causes frustration
to users who initially expected the completion time from the first download report and had geared
themselves up to do something, only to have to wait again (often repeatedly). A better practice
would be to report on how many pages need to be downloaded as well as the current download
status, giving the user a clearer expectation of the full download time.
Where there are varying possibilities for performance tradeoffs (e.g., resolution versus frame rate
for animation, compression size versus speed of compression for compression utilities, etc.), the
18.
O’reilly - JavaPerformance Tuning
- 13 -
best strategy is to put the user in control. It is better to provide the option to choose between faster
performance and better functionality. When users have made the choice themselves, they are often
more willing to put up with actions taking longer in return for better functionality. When users do
not have this control, their response is usually less tolerant.
This strategy also allows those users who have strong performance requirements to be provided for
at their own cost. But it is always important to provide a reasonable default in the absence of any
choice from the user. Where there are many different parameters, consider providing various levels
of user-controlled tuning parameters, e.g., an easy set of just a few main parameters, a middle level,
and an expert level with access to all parameters. This must, of course, be well documented to be
really useful.
1.5.1 Threading to Appear Quicker
A lot of time (in CPU cycles) passes while the user is reacting to the application interface. This time
can be used to anticipate what the user wants to do (using a background low priority thread), so that
precalculated results are ready to assist the user immediately. This makes an application appear
blazingly fast.
Similarly, ensuring that your application remains responsive to the user, even while it is executing
some other function, makes it seem fast and responsive. For example, I always find that when
starting up an application, applications that draw themselves on screen quickly and respond to
repaint requests even while still initializing (you can test this by putting the window in the
background and then bringing it to the foreground) give the impression of being much faster than
applications that seem to be chugging away unresponsively. Starting different word-processing
applications with a large file to open can be instructive, especially if the file is on the network or a
slow (removable) disk. Some act very nicely, responding almost immediately while the file is still
loading; others just hang unresponsively with windows only partially refreshed until the file is
loaded; others don't even fully paint themselves until the file has finished loading. This illustrates
what can happen if you do not use threads appropriately.
In Java, the key to making an application responsive is multithreading. Use threads to ensure that
any particular service is available and unblocked when needed. Of course this can be difficult to
program correctly and manage. Handling interthread communication with maximal responsiveness
(and minimal bugs) is a complex task, but it does tend to make for a very snappily built application.
1.5.2 Streaming to Appear Quicker
When you display the results of some activity on the screen, there is often more information than
can fit on a single screen. For example, a request to list all the details on all the files in a particular
large directory may not fit on one display screen. The usual way to display this is to show as much
as will fit on a single screen and indicate that there are more items available with a scrollbar. Other
applications or other information may use a "more" button or have other ways of indicating how to
display or move on to the extra information.
In these cases, you initially need to display only a partial result of the activity. This tactic can work
very much in your favor. For activities that take too long and for which some of the results can be
returned more quickly than others, it is certainly possible to show just the first set of results while
continuing to compile more results in the background. This gives the user an apparently much
quicker response than if you were to wait for all the results to be available before displaying them.
19.
O’reilly - JavaPerformance Tuning
- 14 -
This situation is often the case for distributed applications. A well-known example is (again!) found
in web browsers that display the initial screenful of a page as soon as it is available, without waiting
for the whole page to be downloaded. The general case is when you have a long activity that can
provide results in a stream, so that the results can be accessed a few at a time. For distributed
applications, sending all the data is often what takes a long time; in this case, you can build
streaming into the application by sending one screenful of data at a time. Also, bear in mind that
when there is a really large amount of data to display, the user often views only some of it and
aborts, so be sure to build in the ability to stop the stream and restore its resources at any time.
1.5.3 Caching to Appear Quicker
This section briefly covers the general principles of caching. Caching is an optimization technique I
return to in several different sections of this book, when it is appropriate to the problem under
discussion. For example, in the area of disk access, there are several caches that apply: from the
lowest-level hardware cache up through the operating-system disk read and write caches, cached
filesystems, and file reading and writing classes that provide buffered I/O. Some caches cannot be
tuned at all; others are tuneable at the operating-system level or in Java. Where it is possible for a
developer to take advantage of or tune a particular cache, I provide suggestions and approaches that
cover the caching technique appropriate to that area of the application. In some cases where caches
are not directly tuneable, it is still worth knowing the effect of using the cache in different ways and
how this can affect performance. For example, disk hardware caches almost always apply a read-
ahead algorithm : the cache is filled with the next block of data after the one just read. This means
that reading backward through a file (in chunks) is not as fast as reading forward through the file.
Caches are effective because it is expensive to move data from one place to another or to calculate
results. If you need to do this more than once to the same piece of data, it is best to hang on to it the
first time and refer to the local copy in the future. This applies, for example, to remote access of
files such as browser downloads. The browser caches locally on disk the file that was downloaded,
to ensure that a subsequent access does not have to reach across the network to reread the file, thus
making it much quicker to access a second time. It also applies, in a different way, to reading bytes
from the disk. Here, the cost of reading one byte for operating systems is the same as reading a page
(usually 4 or 8 KB), as data is read into memory a page at a time by the operating system. If you are
going to read more than one byte from a particular disk area, it is better to read in a whole page (or
all the data if it fits on one page) and access bytes through your local copy of the data.
General aspects of caching are covered in more detail in the section Section 11.4. Caching is an
important performance-tuning technique that trades space for time, and it should be used whenever
extra memory space is available to the application.
1.6 Starting to Tune
Before diving into the actual tuning, there are a number of considerations that will make your
tuning phase run more smoothly and result in clearly achieved objectives.
1.6.1 User Agreements
Any application must meet the needs and expectations of its users, and a large part of those needs
and expectations is performance. Before you start tuning, it is crucial to identify the target response
times for as much of the system as possible. At the outset, you should agree with your users
(directly if you have access to them, or otherwise through representative user profiles, market
information, etc.) what the performance of the application is expected to be.
20.
O’reilly - JavaPerformance Tuning
- 15 -
The performance should be specified for as many aspects of the system as possible, including:
• Multiuser response times depending on the number of users (if applicable)
• Systemwide throughput (e.g., number of transactions per minute for the system as a whole,
or response times on a saturated network, again if applicable)
• The maximum number of users, data, files, file sizes, objects, etc., the application supports
• Any acceptable and expected degradation in performance between minimal, average, and
extreme values of supported resources
Agree on target values and acceptable variances with the customer or potential users of the
application (or whoever is responsible for performance) before starting to tune. Otherwise, you will
not know where to target your effort, how far you need to go, whether particular performance
targets are achievable at all, and how much tuning effort those targets may require. But most
importantly, without agreed targets, whatever you achieve tends to become the starting point.
The following scenario is not unusual: a manager sees horrendous performance, perhaps a function
that was expected to be quick, but takes 100 seconds. His immediate response is, "Good grief, I
expected this to take no more than 10 seconds." Then, after a quick round of tuning that identifies
and removes a huge bottleneck, function time is down to 10 seconds. The manager's response is
now, "Ah, that's more reasonable, but of course I actually meant to specify 3 seconds—I just never
believed you could get down so far after seeing it take 100 seconds. Now you can start tuning." You
do not want your initial achievement to go unrecognized (especially if money depends on it), and it
is better to know at the outset what you need to reach. Agreeing on targets before tuning makes
everything clear to everyone.
1.6.2 Setting Benchmarks
After establishing targets with the users, you need to set benchmarks. These are precise
specifications stating what part of the code needs to run in what amount of time. Without first
specifying benchmarks, your tuning effort is driven only by the target, "It's gotta run faster," which
is a recipe for a wasted return. You must ask, "How much faster and in which parts, and for how
much effort?" Your benchmarks should target a number of specific functions of the application,
preferably from the user perspective (e.g., from the user pressing a button until the reply is returned,
or the function being executed is completed).
You must specify target times for each benchmark. You should specify ranges: for example, best
times, acceptable times, etc. These times are often specified in frequencies of achieving the targets.
For example, you might specify that function A takes not more than 3 seconds to execute from user
click to response received for 80% of executions, with another 15% of response times allowed to
fall in the 3- to 5-second range, and 5% allowed to fall in the 5- to 10-second range. Note that the
earlier section on user perceptions indicates that the user will see this function as having a 5-second
response time (the 90th percentile value) if you achieve the specified ranges.
You should also have a range of benchmarks that reflect the contributions of different components
of the application. If possible, it is better to start with simple tests so that the system can be
understood at its basic levels, and then work up from these tests. In a complex application, this
helps to determine the relative costs of subsystems and which components are most in need of
performance-tuning.
The following point is critical: Without clear performance objectives, tuning will never be
completed. This is a common syndrome on single or small group projects, where code keeps on
being tweaked as better implementations or cleverer code is thought up.
21.
O’reilly - JavaPerformance Tuning
- 16 -
Your general benchmark suite should be based on real functions used in the end application, but at
the same time should not rely on user input, as this can make measurements difficult. Any
variability in input times or any other part of the application should either be eliminated from the
benchmarks or precisely identified and specified within the performance targets. There may be
variability, but it must be controlled and reproducible.
1.6.3 The Benchmark Harness
There are tools for testing applications in various ways.[2]
These tools focus mostly on testing the
robustness of the application, but as long as they measure and report times, they can also be used for
performance testing. However, because their focus tends to be on robustness testing, many tools
interfere with the application's performance, and you may not find a tool you can use adequately or
cost-effectively. If you cannot find an acceptable tool, the alternative is to build your own harness.
[2]
You can search the Web for java+perf+test to find performance-testing tools. In addition, some Java profilers are listed in Chapter 15.
Your benchmark harness can be as simple as a class that sets some values and then starts the main(
) method of your application. A slightly more sophisticated harness might turn on logging and
timestamp all output for later analysis. GUI-run applications need a more complex harness and
require either an alternative way to execute the graphical functionality without going through the
GUI (which may depend on whether your design can support this), or a screen event capture and
playback tool (several such tools exist[3]
). In any case, the most important requirement is that your
harness correctly reproduces user activity and data input and output. Normally, whatever
regression-testing apparatus you have (and presumably are already using) can be adapted to form a
benchmark harness.
[3]
JDK 1.3 introduced a new java.awt.Robot class, which provides for generating native system-input events, primarily to support automated
testing of Java GUIs.
The benchmark harness should not test the quality or robustness of the system. Operations should
be normal: startup, shutdown, noninterrupted functionality. The harness should support the different
configurations your application operates under, and any randomized inputs should be controlled;
but note that the random sequence used in tests should be reproducible. You should use a realistic
amount of randomized data and input. It is helpful if the benchmark harness includes support for
logging statistics and easily allows new tests to be added. The harness should be able to reproduce
and simulate all user input, including GUI input, and should test the system across all scales of
intended use, up to the maximum numbers of users, objects, throughputs, etc. You should also
validate your benchmarks, checking some of the values against actual clock time to ensure that no
systematic or random bias has crept into the benchmark harness.
For the multiuser case, the benchmark harness must be able to simulate multiple users working,
including variations in user access and execution patterns. Without this support for variations in
activity, the multiuser tests inevitably miss many bottlenecks encountered in actual deployment and,
conversely, do encounter artificial bottlenecks that are never encountered in deployment, wasting
time and resources. It is critical in multiuser and distributed applications that the benchmark harness
correctly reproduces user-activity variations, delays, and data flows.
1.6.4 Taking Measurements
Each run of your benchmarks needs to be under conditions that are as identical as possible;
otherwise it becomes difficult to pinpoint why something is running faster (or slower) than in
another test. The benchmarks should be run multiple times, and the full list of results retained, not
just the average and deviation or the ranged percentages. Also note the time of day that benchmarks
22.
O’reilly - JavaPerformance Tuning
- 17 -
are being run and any special conditions that apply, e.g., weekend or after hours in the office.
Sometimes the variation can give you useful information. It is essential that you always run an
initial benchmark to precisely determine the initial times. This is important because, together with
your targets, the initial benchmarks specify how far you need to go and highlight how much you
have achieved when you finish tuning.
It is more important to run all benchmarks under the same conditions than to achieve the end-user
environment for those benchmarks, though you should try to target the expected environment. It is
possible to switch environments by running all benchmarks on an identical implementation of the
application in two environments, thus rebasing your measurements. But this can be problematic: it
requires detailed analysis because different environments usually have different relative
performance between functions (thus your initial benchmarks could be relatively skewed compared
with the current measurements).
Each set of changes (and preferably each individual change) should be followed by a run of
benchmarks to precisely identify improvements (or degradations) in the performance across all
functions. A particular optimization may improve the performance of some functions while at the
same time degrading the performance of others, and obviously you need to know this. Each set of
changes should be driven by identifying exactly which bottleneck is to be improved and how much
a speedup is expected. Using this methodology rigorously provides a precise target of your effort.
You need to verify that any particular change does improve performance. It is tempting to change
something small that you are sure will give an "obvious" improvement, without bothering to
measure the performance change for that modification (because "it's too much trouble to keep
running tests"). But you could easily be wrong. Jon Bentley once discovered that eliminating code
from some simple loops can actually slow them down.[4]
If a change does not improve performance,
you should revert back to the previous version.
[4]
"Code Tuning in Context" by Jon Bentley, Dr. Dobb's Journal, May 1999. An empty loop in C ran slower than one that contained an integer increment
operation.
The benchmark suite should not interfere with the application. Be on the lookout for artificial
performance problems caused by the benchmarks themselves. This is very common if no thought is
given to normal variation in usage. A typical situation might be benchmarking multiuser systems
with lack of user simulation (e.g., user delays not simulated causing much higher throughput than
would ever be seen; user data variation not simulated causing all tests to try to use the same data at
the same time; activities artificially synchronized giving bursts of activity and inactivity; etc.). Be
careful not to measure artificial situations, such as full caches with exactly the data needed for the
test (e.g., running the test multiple times sequentially without clearing caches between runs). There
is little point in performing tests that hit only the cache, unless this is the type of work the users will
always perform.
When tuning, you need to alter any benchmarks that are quick (under five seconds) so that the code
applicable to the benchmark is tested repeatedly in a loop to get a more consistent measure of where
any problems lie. By comparing timings of the looped version with a single-run test, you can
sometimes identify whether caches and startup effects are altering times in any significant way.
Optimizing code can introduce new bugs, so the application should be tested during the
optimization phase. A particular optimization should not be considered valid until the application
using that optimization's code path has passed quality assessment.
23.
O’reilly - JavaPerformance Tuning
- 18 -
Optimizations should also be completely documented. It is often useful to retain the previous code
in comments for maintenance purposes, especially as some kinds of optimized code can be more
difficult to understand (and therefore to maintain).
It is typically better (and easier) to tune multiuser applications in single-user mode first. Many
multiuser applications can obtain 90% of their final tuned performance if you tune in single-user
mode and then identify and tune just a few major multiuser bottlenecks (which are typically a sort
of give-and-take between single-user performance and general system throughput). Occasionally,
though, there will be serious conflicts that are revealed only during multiuser testing, such as
transaction conflicts that can slow an application to a crawl. These may require a redesign or
rearchitecting of the application. For this reason, some basic multiuser tests should be run as early
as possible to flush out potential multiuser-specific performance problems.
Tuning distributed applications requires access to the data being transferred across the various parts
of the application. At the lowest level, this can be a packet sniffer on the network or server machine.
One step up from this is to wrap all the external communication points of the application so that you
can record all data transfers. Relay servers are also useful. These are small applications that just re-
route data between two communication points. Most useful of all is a trace or debug mode in the
communications layer that allows you to examine the higher-level calls and communication
between distributed parts.
1.7 What to Measure
The main measurement is always wall-clock time. You should use this measurement to specify
almost all benchmarks, as it's the real-time interval that is most appreciated by the user. (There are
certain situations, however, in which system throughput might be considered more important than
the wall-clock time; e.g., servers, enterprise transaction systems, and batch or background systems.)
The obvious way to measure wall-clock time is to get a timestamp using
System.currentTimeMillis( ) and then subtract this from a later timestamp to determine the
elapsed time. This works well for elapsed time measurements that are not short.[5]
Other types of
measurements have to be system-specific and often application-specific. You can measure:
[5]
System.currentTimeMillis( ) can take up to half a millisecond to execute. Any measurement including the two calls needed to
measure the time difference should be over an interval greater than 100 milliseconds to ensure that the cost of the
System.currentTimeMillis( ) calls are less than 1% of the total measurement. I generally recommend that you do not make more than
one time measurement (i.e., two calls to System.currentTimeMillis( )) per second.
• CPU time (the time allocated on the CPU for a particular procedure)
• The number of runnable processes waiting for the CPU (this gives you an idea of CPU
contention)
• Paging of processes
• Memory sizes
• Disk throughput
• Disk scanning times
• Network traffic, throughput, and latency
• Transaction rates
• Other system values
However, Java doesn't provide mechanisms for measuring these values directly, and measuring
them requires at least some system knowledge, and usually some application-specific knowledge
(e.g., what is a transaction for your application?).
24.
O’reilly - JavaPerformance Tuning
- 19 -
You need to be careful when running tests that have small differences in timings. The first test is usually
slightly slower than any other tests. Try doubling the test run so that each test is run twice within the VM
(e.g., rename main( ) to maintest( ), and call maintest( ) twice from a new main( )).
There are almost always small variations between test runs, so always use averages to measure
differences and consider whether those differences are relevant by calculating the variance in the results.
For distributed applications , you need to break down measurements into times spent on each
component, times spent preparing data for transfer and from transfer (e.g., marshalling and
unmarshalling objects and writing to and reading from a buffer), and times spent in network
transfer. Each separate machine used on the networked system needs to be monitored during the test
if any system parameters are to be included in the measurements. Timestamps must be
synchronized across the system (this can be done by measuring offsets from one reference machine
at the beginning of tests). Taking measurements consistently from distributed systems can be
challenging, and it is often easier to focus on one machine, or one communication layer, at a time.
This is usually sufficient for most tuning.
1.8 Don't Tune What You Don't Need to Tune
The most efficient tuning you can do is not to alter what works well. As they say, "If it ain't broke,
don't fix it." This may seem obvious, but the temptation to tweak something just because you have
thought of an improvement has a tendency to override this obvious statement.
The second most efficient tuning is to discard work that doesn't need doing. It is not at all
uncommon for an application to be started with one set of specifications and to have some of the
specifications change over time. Many times the initial specifications are much more generic than
the final product. However, the earlier generic specifications often still have their stamps in the
application. I frequently find routines, variables, objects, and subsystems that are still being
maintained but are never used and never will be used, since some critical aspect of these resources
is no longer supported. These redundant parts of the application can usually be chopped without any
bad consequences, often resulting in a performance gain.
In general, you need to ask yourself exactly what the application is doing and why. Then question
whether it needs to do it in that way, or even if it needs to do it at all. If you have third-party
products and tools being used by the application, consider exactly what they are doing. Try to be
aware of the main resources they use (from their documentation). For example, a zippy DLL
(shared library) that is speeding up all your network transfers is using some resources to achieve
that speedup. You should know that it is allocating larger and larger buffers before you start trying
to hunt down the source of your mysteriously disappearing memory. Then you can realize that you
need to use the more complicated interface to the DLL that restricts resource usage, rather than a
simple and convenient interface. And you will have realized this before doing extensive (and
useless) object profiling, because you would have been trying to determine why your application is
being a memory hog.
When benchmarking third-party components, you need to apply a good simulation of exactly how
you will use those products. Determine characteristics from your benchmarks and put the numbers
into your overall model to determine if performance can be reached. Be aware that vendor
benchmarks are typically useless for a particular application. Break your application down into a
hugely simplified version for a preliminary benchmark implementation to test third-party
components. You should make a strong attempt to include all the scaling necessary so that you are
benchmarking a fully scaled usage of the components, not some reduced version that will reveal
little about the components in full use.
25.
O’reilly - JavaPerformance Tuning
- 20 -
1.9 Performance Checklist
• Specify the required performance.
o Ensure performance objectives are clear.
o Specify target response times for as much of the system as possible.
o Specify all variations in benchmarks, including expected response ranges (e.g., 80%
of responses for X must fall within 3 seconds).
o Include benchmarks for the full range of scaling expected (e.g., low to high numbers
of users, data, files, file sizes, objects, etc.).
o Specify and use a benchmark suite based on real user behavior. This is particularly
important for multiuser benchmarks.
o Agree on all target times with users, customers, managers, etc., before tuning.
• Make your benchmarks long enough: over five seconds is a good target.
o Use elapsed time (wall-clock time) for the primary time measurements.
o Ensure the benchmark harness does not interfere with the performance of the
application.
o Run benchmarks before starting tuning, and again after each tuning exercise.
o Take care that you are not measuring artificial situations, such as full caches
containing exactly the data needed for the test.
• Break down distributed application measurements into components, transfer layers, and
network transfer times.
• Tune systematically: understand what affects the performance; define targets; tune; monitor
and redefine targets when necessary.
o Approach tuning scientifically: measure performance; identify bottlenecks;
hypothesize on causes; test hypothesis; make changes; measure improved
performance.
o Determine which resources are limiting performance: CPU, memory, or I/O.
o Accurately identify the causes of the performance problems before trying to tune
them.
o Use the strategy of identifying the main bottlenecks, fixing the easiest, then
repeating.
o Don't tune what does not need tuning. Avoid "fixing" nonbottlenecked parts of the
application.
o Measure that the tuning exercise has improved speed.
o Target one bottleneck at a time. The application running characteristics can change
after each alteration.
o Improve a CPU limitation with faster code and better algorithms, and fewer short-
lived objects.
o Improve a system-memory limitation by using fewer objects or smaller long-lived
objects.
o Improve I/O limitations by targeted redesigns or speeding up I/O, perhaps by
multithreading the I/O.
• Work with user expectations to provide the appearance of better performance.
o Hold back releasing tuning improvements until there is at least a 20% improvement
in response times.
o Avoid giving users a false expectation that a task will be finished sooner than it will.
o Reduce the variation in response times. Bear in mind that users perceive the mean
response time as the actual 90th percentile value of the response times.
o Keep the user interface responsive at all times.
o Aim to always give user feedback. The interface should not be dead for more than
two seconds when carrying out tasks.
o Provide the ability to abort or carry on alternative tasks.
noise was deafening,but they plodded on. So steady was the
behaviour of all ranks that General Ponsonby afterwards issued a
special order of the day, stating that the 4th Battalion had come up
to his support as steadily as if it had been on parade. It suffered 30
casualties, which, in view of the amount of shell-fire, may be
considered astonishingly light.
The following graphic description of these two days was written
by Captain M. Chapman in a sketch entitled “Intelligence,” which he
began, but which he never lived to finish.
“On the morning of the — the Battalion marched up a long
wet pavé road in the direction of the gun-flashes and the
Véry Lights, whilst the Battalion ‘drums,’ somewhere in the
dark, played the tune that Grenadiers call their own, and the
C.O. in silence watched his men file by. The test of discipline
and training had begun. The figures of the men looked tall
and grim, magnified by the shadows cast from the shrouded
lanterns of the motor-lorries. The night was dark, and a
driving rain soon soaked the tramping men. In an hour’s time
you could see by the light of a torch a mist rising from the
soaked and perspiring humanity in front.
“A halt was called and men were detailed to pick up
bivouac-sheets and petrol-tins of water. The already heavy-
laden troops moved on again more slowly with their increased
burden, along slippery wooden tracks laid across a field of
mud. Another halt. An officer appeared, dripping with
moisture, accompanied by guides who took charge of the
companies and allotted them their area in which to bivouac.
“To-morrow was zero day, not for the 4th Battalion, but for
some one else. If some one else failed, then the Grenadiers
would have to put matters straight; that is to say, the
Grenadiers were in reserve. The Intelligence Officer gave one
last look at the inky darkness, and going down on hands and
knees crawled into a long, low-arched dug-out. Sleeping men
28.
sprawled across thefloor, while at the farther end a solitary
candle burned. Picking his way across the recumbent figures
he saw the Commanding Officer lying on his back, his head
propped against a pack, silently smoking a cigarette and
thinking. The Intelligence Officer lay down by his side, and,
watching the Adjutant writing orders and speaking down a
telephone, fell into a fitful sleep.
“Zero hour for some one else left him cold, unmoved. The
accustomed environment of war and great fatigue dull the
sensibility of man. The steady roar of countless guns was a
pleasing murmur as of rippling water in his sleepy brain.
“A ray of sunlight struggled through the narrow entrance
of the dug-out, and the sleeping mass of humanity near the
door stirred uneasily. The Intelligence Officer shivered, and,
cautiously rising into a stooping posture, crawled out into the
open air. The sun was trying to pierce a passage through the
heavy ground-mist. The troops were cooking their breakfast
and beating their chests with a flapping motion to restore the
circulation in their half-frozen limbs.
“On a modern battlefield, lines of wooden ‘duckboards’ run
like arteries across the trackless waste towards the front. Up
the arteries flow fresh men, new blood, human forms
complete; food to support life, ammunition to destroy it.
Down the arteries flow ghosts of what yesterday were men,
with tissues torn, and muscles rent; gibbering prisoners and
men who have been spared to be shattered another day.
“An artery passed the dug-out door. The Intelligence
Officer observed the circulation to and from the battlefield,
and speculated on the fate of the tide going up, watching the
expression on the faces of the advancing and receding
groups. The men lazily watched the passing tide, exchanging
jokes with friends going either way. Prisoners alone excited
29.
interest, but notsufficient to make men move more than a
few yards from where they stood.
“French gunners in a wood near by ran hotfoot to see each
band of prisoners pass, but our men with British phlegm
stayed where they stood, and eyed the foe with casual
glance. The passing wounded drew no expression of pity from
the onlookers, nor did the fate of the ingoing tide even raise a
questioning expression on their faces. This was the last spot
where selfishness still reigned supreme—the fringe of the
battle. Death and danger were not sufficiently close to draw
out the best in man; he behaved as he did in civil life—each
man for himself and the devil take the hindmost.
“The men who marched up the endless ribbon to the front
looked just like other men, and anxiety for their own safety
left no trace in their expression. They might have been the
crowd that streams through the factory gates in the early
morning. The outgoing men were different. They hastened by
and looked neither to the left nor right. They felt that fate
had been too good to them and that it might change its mind
and rend them if they loitered by the way. They had reached
the fringe where the ‘Ego’ was whispering in their ears with
insistent voice. They were alive; the others—they might be
dead—what matter? They were alive.
“The wounded stared in front of them, except those in
pain, and the prisoners looked cowed and miserable. The
escorts walked with jaunty air, rifle slung, bayonets fixed, and
exchanged jokes with all who would pay attention. The
feeling of victory was still in their veins, for the slouching
prisoners spurred their pride of race; were they not the
symbol of all their friends ‘up there’ had done?
“The stretcher-bearers, intent on their work, passed the
fringe of selfishness untouched. The bond of pain and
suffering held them fast in unselfishness until the moment
30.
when they deliveredtheir charge to the clearing-station in the
rear. While other men hurried from the battlefield, these
slowly and with aching arms and legs carried their burdens
carefully. Human suffering must touch some special chord of
self-sacrifice in man. Duty, discipline, and other self-taught
virtues would never produce that careful studied plod of the
stretcher-bearer under heavy shell-fire, or those deliberate
halts to attend to their patients’ needs.
“Thus the second day passed. The Grenadiers were not
called upon, but sat in the pit and watched the puppets
moving on and off the stage. The Intelligence Officer had the
critic’s box and made his notes. The night passed quietly and
slowly, the news filtered back that our friends in front had
taken all their objectives and that all went well. The morning
brought the fateful news that the 4th Battalion was under
orders to take over the front line that night, and afterwards to
attack. Every one was busy, even the Intelligence Officer, and
the passing puppets moved unnoticed. The 4th Battalion
prepared to leave the pit and occupy the stage.
“The third day passed quickly in preparation. At 4.30 in the
afternoon the first platoon stepped on to the wooden
pathway and moved up towards the front. The Intelligence
Officer started last, with Battalion Headquarters, while the
Commanding Officer and Adjutant and orderlies plodded off
alone. The sun had set and it was growing dark. That ribbon
of wood which led to the unknown had its advantages, for it
gave a hard, though slippery, foothold; but, once you stepped
upon it, you became its slave. The Path began to assume a
sinister character, when ahead you saw it lead into a wood
full of bursting shells. Then it took the form of an endless
moving staircase, surely leading to destruction. The serpent
of men moved into such a wood. The very name it bore was
ominous. No one spoke. The Intelligence Officer noticed his
throat was very dry. His heart pumped at the scream of each
31.
arriving shell. Hecontinued to move forward as in a dream.
At intervals he made way for stretcher cases. The flash of the
bursting shells disclosed a row of gun-emplacements. Two
gunners pinned under an overturned carriage screamed.
“Still Battalion Headquarters moved on—out of the wood
into the open—away from death to what seemed like security.
An odd shell or two burst near the path, while others shrieked
their way overhead, dealing death somewhere behind. The
mind neglected the latter, focussing all attention on the
former. The pathway crossed two streams. By now the
darkness was complete. A snorting, sobbing noise came from
somewhere in front, succeeded by a splashing sound. The
path went by a dark and slimy pool, in which the head and
ears of a bogged horse waggled this way and that
pathetically. Then all was still. A man’s figure could be dimly
seen attempting to cut off the pack saddle before it was
buried in the slough.
“The wooden track abruptly ended. A white tape feebly
glimmered in the dark, hanging loosely between upright iron
stakes, rifles driven muzzle down into the sodden soil, and
portions of broken branches.
“The Intelligence Officer seized the tape and floundered
slowly on. The men behind him breathed heavily, and in quiet
tones cursed the water and the mud, the tape and the hand
that laid it. Some one tripped. A halt was called. The
obstruction proved to be a comrade, some flotsam from the
men ahead. He was alive, warm, but inarticulate. A sergeant
felt him over in the dark. Some one said, ‘My Gawd, Sir, ’e’s
got it through the throat.’ The Intelligence Officer spoke
words of promise to the man and left him there. ‘Outgoing
troops would pick him up,’ and other well-worn words of
comfort, although he knew they might not see him. He felt he
was leaving him to die. This is war.
32.
“The tape suddenlyended. Heaps of broken stone
disclosed the close proximity of a concrete dug-out. A guide
cautiously felt his way into the darkness and presently led the
Intelligence Officer down some steps below the ground. At
the foot of the steps hung a soaking blanket, behind which a
light glimmered feebly. The Intelligence Officer cautiously
pulled the blanket to one side, and blinked at the group
inside. Two Commanding Officers and two Adjutants were
talking. ‘Handing over’ was in process. The outgoing were
clearly anxious to be gone; the incoming were anxious not to
let them go without knowing what lay before them.
“A succession of officers and orderlies peered through the
doorway, saluted and uttered the magic words, ‘Relief
complete, Sir,’ and vanished into the outer darkness. Their
strained expressions did not belie the full meaning of the
sentence. The outgoing C.O. pushing back his chair with a
scraping noise said, with a half-apologetic air, he would be off,
and he and his satellites vanished. He had laid down his
burden; the 4th Battalion had assumed it. His footsteps
sounded light and care-free as they died away.
“All that night officers and men groped their way through
mud and filth, visiting outposts, distributing rations, each bent
on a mission involving the safety and comfort of the other.
The Intelligence Officer felt that the atmosphere had
changed. The Commanding Officer could have reclined on the
German bed in the dug-out, his feet out of the six inches of
liquid slush. Actually he spent his time going round the line,
four hours of intense physical strain. Shells and bullets do not
sound more pleasant because it is dark.
“The Transport Officer might have dumped the rations
beyond the barrage and returned to the security of the horse-
lines, and the warmth of his valise. As a matter of fact, he led
his struggling animals up a broken, shattered road, through
the barrage, round the trunks of fallen trees, and delivered
33.
his consignment atB.H.Q. The Adjutant might have said with
reason that the ration parties had lost their way, that
conditions were impossible, but the Intelligence Officer
watched him supervise everything in person—in the open.
Before dawn the front line was rationed—every post
established, no chances taken. The Intelligence Officer saw it
all and said: ‘If this is war, some parts of it at least are good.’
“At dawn the next morning he arose and stood shivering in
the cold mist. He visited his observation-post, and, watching
trenches through his telescope as the sun slowly made its
way through the haze, he smiled as he recognised well-
known N.C.O.’s and men moving about in the nonchalant
manner which all assume before the sniper starts his work,
and when tired gunners take their rest. He knew that later he
might search for hours and find no movement; all would be
hiding in their shell-hole lairs.
“A distant hum reminding him of some gigantic insect,
drew his attention from his work, and two aeroplanes
appeared, flying very low. In a few minutes the moving
figures vanished from the field of view of his telescope. The
earth swallowed them up. Then commenced manœuvres that
reminded him of sparrow-hawks quartering their haunting
ground for prey. The droning insects flew back and forth. No
movement was visible on the ground. A hooded head looked
over the fuselage of each machine. The Iron Cross showed
clearly on the wings. Then warning lights were dropped from
each machine. Each light marked the position of a trench and
seemed to say, ‘Eat, drink, and be merry, for soon you will
die.’ The whole proceeding revolted the men watching from
the O.P. They knew the full intent of it. Their imagination
heard the scream of the shells which would surely fall where
the lights had dropped. They felt for their friends out there.
Discovered by their enemies, the hiding men used their
weapons viciously. The rattle of machine-guns and rifles was
34.
mixed with thedrone of the aeroplanes. The pilots knew their
work was done. They turned to fly. One of them staggered in
his course. The Intelligence Officer watched the machine
crash in flames in a distant forest. The hiding men in their
shell-holes sat down to wait for the punishment that they
knew must come. The Intelligence men watched great spouts
of earth rise skywards and listened to the rending crash that
came slowly across the intervening space. They longed to
help; instead they noted the time and place and entered the
information in their Intelligence report.
“Zero was set for 5 A.M., this time a zero that concerned
the 4th Battalion alone. The Commanding Officer and the
Intelligence Officer moved forward through the darkness to
an advanced position at three o’clock in the morning. Here
the nerve centre of the 4th Battalion was established. Here
would enter the news of battle. The Intelligence Officer
established himself in a corner of the new dug-out. His
carrier-pigeons made little noises to themselves, while the
telephone operators tested and re-tested their lines. The
Intelligence Officer’s hand kept wandering to his watch. The
Commanding Officer snored. His plans had been truly laid;
interference now would be fatal. He was a well-trained
soldier, and he slept.
“Five minutes before zero the Intelligence Officer woke the
Commanding Officer, and both waited for the well-known
throb of innumerable guns. One of them at least thought of
his friends waiting to follow up the moving death. What were
those others, his enemies, doing? Did they realise what hell
would break upon them? Did they suspect the impending
stroke?
“The blow fell to the minute. The dug-out rocked. A sheet
of flame lit up the sky. A thousand devils seemed to be
forging a red-hot band on the earth as far as the eye could
see. Their countless hammer-strokes were merged into one
35.
loud growling, rumblingnoise. Gradually the ear became
accustomed to the sound and detected the sharp crack of
answering bullets and the rattle of machine-gun fire. Dawn
was breaking and eyes were strained to pierce the half-light.
Minutes seemed like hours.
“The first messenger arrived at the nerve centre. He
brought good news. Others followed. All reported success.
The Intelligence Officer took out one of his pigeons, attached
a message to its leg, and released it. He noticed how clumsy
his handling of the bird had become. The pigeon circled once
and flew straight as an arrow in the right direction. This was
dramatic, exciting, the cream of war. Then came the sordid
side.
“The enemy artillery awoke. Great shells came hurtling
through the sky.
“The shelling grew less. The machine-gun fire died away.
The enemy was accepting the new situation. We had won; he
had lost. Both sides prepared to settle down where they
found themselves, too tired to prolong the struggle.
“The Commanding Officer was satisfied with the position.
Emerging cautiously from its shelter, the party moved back to
the original Battalion Headquarters. As they passed the
trenches and the scooped-out holes in which the supports
sheltered, inquiries were made as to casualties, and brave
words spoken to cheer the exhausted men. The Intelligence
Officer, ruminating on death, saw many signs of it. The true
value of the body in which for a short period resides the soul
of man was brought home to him. Three men crouched in a
trench. Two were cooking; some conversation was in
progress. The third man sat by their side and took no part.
He seemed by his attitude to be thinking deeply, immersed in
the solution of a problem. His face was turned away. The
attitude was one of puzzled thought.
36.
“The Intelligence Officermade inquiries as to how they
had fared. Two of the men looked up; they gave him a
friendly smile and told him all they knew. The other sat with
his head bent, still studying that inscrutable problem. The
Intelligence Officer noticed with a start the colour of his ears,
how wax-like in appearance; then he knew in a flash—the
man was dead. His comrades did not even explain the fact.
They seemed to realise that the figure by their side no longer
counted, that the soul and personality were fled, that there
was nothing dreadful in the husk that sat there and still
seemed one of them. War had taught them what a small
thing the body really is, what a matter of indifference whether
it is smashed or not. They had learned one thing at least—the
proportionate value of the body and the soul.
“That night the 4th Battalion handed over its burden to
some one else. It was due to be relieved. The Chaplain had
arrived to see to it that the brave dead had decent burial.
When it was possible, the Grenadiers always carried down
their dead, so that in the future, grouped together, they
would stand as a memorial of the cause they fought for, and
indicate plainly to future generations how Grenadiers could
fight and die—a monument to the power of discipline, self-
sacrifice, and pride of race.”
No. 1 Company under Captain Sloane-Stanley, No. 3 under
Lieutenant Nash, and No. 4 under Captain Paton, dug themselves in
with entrenching tools along the Anneux chapel—Mœuvres road,
while No. 2, under Captain Britten, was placed in Anneux chapel
itself. The shelling was very violent, and all the roads, by which
supplies and supports had to move, were accurately and persistently
shelled. The Brigadier, Lord Henry Seymour, came along, quite
unconcerned and not even wearing a helmet, to see how these
companies were getting on, and told them they might have to move
up later into Bourlon Wood. When it got dark snow began to fall,
and it became bitterly cold. The position of a lent battalion is by no
37.
means an enviableone, and soon orders and counter-orders from
different authorities succeeded each other with amazing rapidity.
Finally definite orders were sent to the Battalion to take up a
position in Bourlon Wood, and at the same time it was placed under
the orders of the 186th Brigade. While this move was being carried
out, Lieutenant Nash was wounded in the leg and sent back to the
dressing-station. In order to keep in touch with the 186th Brigade,
Second Lieutenant Tuckwell was sent to Graincourt to act as liaison-
officer to General Bradford, V.C.
Bourlon Wood, which covers about 100 acres, might well have
been a typical English covert, with its tall trees interspersed with
undergrowth about eight feet high. The line to be held consisted of a
road running north and south, parallel to the front line. The ground
was soaking wet, and the men had to force their way through the
dripping leaves and lie out in the wood with no protection of any
kind. Digging through the stubborn soil and soaking undergrowth
was no easy matter with light entrenching tools, but they soon
produced some sort of cover. The Fortieth Division, however, had
succeeded in its attack, and so there was nothing for the 4th
Battalion to do but to remain in the wood where it was. In the
evening, much to the satisfaction of every one, it reverted to the
command of the Guards Division. Lieutenant Ingleby, the acting
Quartermaster, arrived at Battalion Headquarters at 11 that night,
having guided the transport up to Anneux chapel through intense
shelling, and reported that Second Lieutenant N. A. Pearce, the
transport officer, who had shown great determination and pluck in
his efforts to bring all that was wanted up to the men in the
trenches, had been killed by a shell. Major-General Feilding received
the following message from Major-General Ponsonby:
I wish to express on behalf of my Division my sincere
thanks for the support given us on the 24th and 25th by the
Battalions of the Guards Division placed at my disposal for the
defence of Bourlon Wood, namely the 2nd Battalion Scots
Guards and 4th Battalion Grenadier Guards.
38.
Nov. 26.
I shouldlike to bring to your notice particularly the 2nd
Battalion Scots Guards, who throughout the period prevented
the enemy from breaking through the right flank of the
position, and assisted in repelling at least two of the enemy’s
counter-attacks. I enclose extracts from the report of the
Brigadier-General commanding the 119th Infantry Brigade:
“The 2nd Battalion Scots Guards reinforced the firing line,
which had become very thin, early in the morning of
November 25, and remained in action until they came under
the orders of the 186th Infantry Brigade on the night of 26-
27th November. All ranks behaved with the utmost gallantry,
and assisted to repel at least two German counter-attacks in
addition to continual enemy pressure. They inspired all with
great confidence.
“The 4th Battalion Grenadier Guards came under my
command in the afternoon of the 25th inst. To reach a
position of readiness it had to cross the open in artillery
formation for a great distance under enemy observation, and
were heavily shelled in so doing. The men were as steady as
if on parade. To the above-mentioned units I wish to express
my gratitude.”
The next day passed quietly, and the company
commanders were able to go in turn to Battalion
Headquarters to have some rest. In the evening snow fell heavily,
and the men had a cold and uncomfortable night. The 4th Battalion
was again to be lent to another brigade, that of General Sergison-
Brooke, who received orders to attack Fontaine. It was not actually
wanted for the attack, but merely to form a defensive line, on which
the assaulting waves could fall back in case of failure.
The enemy put down a heavy barrage on the whole line that
night, and Lord Gort sent Captain Chapman to inquire from the 2nd
Battalion Irish Guards what was happening, but it proved to be
merely the outcome of nervousness on the part of the Germans, and
39.
Nov. 27.
no attackdeveloped. The Battalion moved off at 5.30 A.M., to take
up new positions facing east instead of north, at very short notice;
and, as the night was very dark and wet and the enemy was so
close, the advance into position required some care. In order to
prevent any confusion in the jumping-off line, the Battalion was told
to occupy a position immediately in rear of the line, and to move up
in the line only when the attack had actually started.
Attack on Fontaine
In a drizzle of rain, and under an intense enemy barrage,
the attack of Sergison-Brooke’s Brigade started at 6.30 in the
morning of the 27th. It reached its objective, but the cost was so
great, that the survivors found it impossible to maintain the position
they had so dearly gained, without reinforcements. So weak were
the attacking battalions, that they were in danger of being
overwhelmed by counter-attacks. While the 4th Battalion was
waiting for orders about 10 A.M., the German counter-attacks began
to develop, and fire from the left became very heavy. No. 2
Company under Captain Britten was sent off to secure the left flank
of the Division, which seemed to be in a dangerously weak
condition. As they came up Second Lieutenant Windeler was killed
by a sniper, and Captain Britten himself was wounded in the arm by
a rifle bullet. Soon afterwards Second Lieutenant Oliver, who was
now in command of No. 3 Company, was severely wounded in the
chest, arm, and foot, while going out to bring in a wounded Irish
Guardsman. The casualties among other ranks were proportionately
heavy.
A warning order arrived from Brigadier-General Sergison-Brooke
at 10.30 A.M., preparing the Battalion to supply two companies for
the support of the 3rd Battalion Grenadiers and 1st Battalion
Coldstream, but it seemed doubtful whether a couple of companies,
or even four, would be of any use in the circumstances. Captain
Gerard, the Adjutant, reported that he had heard from Captain Paton
40.
Nov. 28.
that alreadythe 2nd Guards Brigade was falling back to the original
line.
Lord Gort went off at once with Captain Chapman to the
headquarters of the 3rd Battalion, and discussed the new situation
with Colonel Thorne. They decided that it would be inadvisable, in
view of the enemy’s strength, and the absence of any appreciable
reserves on our side, to renew the attack, and so use up the 4th
Battalion with small chance of success. Orders were accordingly
issued for the original line now held by the 4th Battalion to become
the line of resistance, under the command of Captain Paton and
Captain Sloane-Stanley. That night the 4th Battalion was relieved,
and returned to the Hindenburg line at Flesquières.
On the 28th it marched to Trescault, and pitched a camp
on the open ground between the Trescault—Metz road and
Havrincourt Wood. The enemy’s aircraft left them no peace, and so
the tents were struck the next morning, and pitched again in
Havrincourt Wood. The undergrowth was thick, and the cutting of it
took some time, but when the camp was finished it proved snug and
sheltered.
41.
Nov. 30.
Attack onFontaine
November 27. 1917.
The officers had just finished breakfast on the 30th, and
were about to inspect their companies, when the news
arrived that the Germans had broken through the line near
Gonnelieu. It was said that the enemy had been seen marching in
fours through Gouzeaucourt. Immediately orders were given for the
Battalion to be ready to start at a moment’s notice. Although the
42.
men had expecteda quiet day, and were quite unprepared, so
perfect were the organisation and discipline that in half an hour’s
time the Battalion was ready to move off.
Lord Gort’s orders were to concentrate on Metz, and accordingly
the Battalion moved off in that direction. The road was full of
transport moving in the opposite direction, and with it ran a stream
of men looking strangely unlike British soldiers, with no rifles or
equipment—wounded and unwounded with incoherent stories,
officers half-undressed, gunners with breechblocks in their hands, all
with a hunted look. Some high-explosive shells came streaming over,
and pitched not far from the road. Lord Henry Seymour with his
commanding officers rode on ahead to try and glean some
information, while the four battalions of his Brigade marched
through Metz, past the beetroot factory and on to the open ground
beyond, where they lay down and waited.
Attack on Gonnelieu
About 2.30 P.M. the whole Brigade, in artillery formation, moved
off in the direction of Gouzeaucourt, and in the meantime the attack
of De Crespigny’s Brigade had been completely successful and
required no reinforcements. The direction of the march was
consequently slightly changed. The 4th Battalion crossed the
Trescault—Gouzeaucourt road, where, thanks to Lieutenant Ingleby,
the cookers arrived, and the men were provided with hot food. That
night General Walker, commanding the 16th Brigade of the Sixth
Division, held a conference at the 4th Battalion Headquarters. His
object was to ensure that the 4th Battalion understood his scheme
of attack, for if his brigade failed it would have to carry out his plan.
The hurried manner in which the attack was planned, and the
obviously scanty information on which the plan was based, seemed
to indicate that it was not likely to succeed. At 1 A.M. a warning order
was issued to the effect that Seymour’s Brigade would assault
Gonnelieu, if the attack of the 16th Brigade failed. Lord Gort
43.
thereupon wrote outhis orders with the very meagre information at
his disposal.
To have to select a definite objective after dark made things very
difficult, since the final disposition depended upon the attack of the
16th Brigade, and whatever happened an indefinite front line would
be the result. If the 16th Brigade succeeded, Seymour’s Brigade
would simply relieve it, but if it failed the attack would have to be
attempted a second time. These considerations alone made it
necessary to work out alternative schemes. Lord Henry Seymour
fortunately prepared a detailed plan for the worst event, and fully
realised that his Brigade was to be employed in a manner generally
accepted as impossible, except in a great emergency, involving the
advance of infantry, unsupported by artillery, across the open against
an enemy occupying trenches, and houses bristling with machine-
guns.
The following officers took part in the attack on Gonnelieu:
Lieut.-Colonel Viscount Gort,
D.S.O., M.C. , M.C.
Commanding
Officer.
Major W. S. Pilcher, D.S.O. 2nd in Command.
Capt. C. R. Gerard Adjutant.
Capt. M. Chapman Intelligence Officer.
Capt. H. H. Sloane-Stanley No. 1 Company.
Lieut. C. E. Irby ” ”
2nd Lieut. J. M. Chitty ” ”
2nd Lieut. B. J. Hubbard, M.C. No. 2 Company.
2nd Lieut. R. C. Denman ” ”
2nd Lieut. D. E. A. Horne ” ”
Capt. J. B. M. Burke, M.C. No. 3 Company.
Lieut. the Hon. A. H. L. Hardinge ” ”
Lieut. L. R. Abel-Smith ” ”
Capt. G. H. T. Paton, M.C. No. 4 Company.
Lieut. B. C. Layton ” ”
44.
Dec. 1.
2nd Lieut.J. J. M. Veitch ” ”
When the news of the failure of the 16th Brigade’s attack reached
Lord Gort, he at once started off with the Battalion, and crossed the
Villers Plouich road. On reaching the railway the companies
extended, and dug themselves in. There they waited in the dark for
zero hour.
The order of battle for Seymour’s Brigade was as follows: The 1st
Battalion Welsh Guards on the right and the 4th Battalion Grenadiers
on the left were to undertake the attack. The 1st Battalion
Grenadiers was in support on the left, and had to protect the left
flank as the attack advanced, while the 2nd Battalion Scots Guards
had already occupied the high ground about Villers Plouich. In the
4th Battalion No. 2 Company under Second Lieutenant Hubbard on
the right and No. 3 under Captain Burke on the left formed the first
line. No. 4 Company under Captain Paton was in support, and No. 1
under Captain Sloane-Stanley formed the reserve. Captain Chapman
was sent forward to establish a forward Battalion Headquarters.
Without any artillery preparation the attack started at 6.30
A.M. It was still fairly dark, but the Germans could see enough
to use their machine-guns with considerable accuracy. The line of
advance was over open ground, up a gentle slope leading to
Gonnelieu, and there was no cover or protection of any kind for the
attackers. On came the leading companies of the 4th Battalion in
perfect order. The men never wavered for an instant, though they
knew that they were to be sacrificed to save the situation. They all
understood that the rules of modern warfare were to be defied, and
that instead of following a creeping barrage they were to advance
across the open, with not even a preliminary bombardment. Though
they knew this, they never faltered.
The enemy’s machine-gun fire when it broke over them was
terrible, like a driving hailstorm, but the pace was never checked for
a moment. Especially on the right the fire was terrific, and No. 2
Company, which had gone rather too far in that direction, suffered
45.
heavy losses: oneplatoon was practically wiped out. Second
Lieutenant Hubbard himself was killed, and Second Lieutenant
Denman was mortally wounded, gallantly attempting to silence a
German machine-gun, while Second Lieutenant Horne was also
wounded. No. 3 Company under Captain Burke maintained its
direction, and had few casualties until it came up close to the village.
On reaching a road running in the direction of Vacquerie, it had to
pause for a moment to allow No. 4 to come up before continuing its
advance. Second Lieutenant Veitch had his thigh smashed by a
bullet, and fell back into a shell-hole. Almost simultaneously a man
shot through the head fell on the top of him, and being too weak to
move the dying man, for twelve hours he remained in this cramped
position.
The left of the line met with less resistance than the right, and so
got far in advance. No. 3 Company dashed forward into the outskirts
of Gonnelieu, but the village seemed almost impregnable against
infantry unsupported by tanks or artillery. A small enclosure
sheltered by ruined buildings was the only protected spot, the
ground all round it was swept by machine-gun fire, and of course
the shrubs and rank grass were no cover at all. Captain Burke
dashed in on the left, and penetrated into the eastern outskirts of
Gonnelieu, while Lieutenant Hardinge with a few men got round to
the north of the village, and brought up a Lewis gun to a position in
the cemetery. This had a most disconcerting effect on the enemy, for
it threatened his right flank, and enfiladed the troops opposing Nos.
2 and 4 Companies.
The Germans quickly grasped the fact that this movement on
Lieutenant Hardinge’s part required immediate action. They
managed to press back the troops on the left of the Brigade, with a
view of enfilading the cemetery. With great ingenuity they worked
round with their machine-guns, and soon Lieutenant Hardinge’s
position became untenable. All his men were killed or wounded with
the exception of Sergeant Hull. Then the gun jammed. There was
now nothing to be done but to get back as best he could, and being
46.
luckily only slightlywounded, he was able to make his way back,
accompanied by Sergeant H. Hull.
Meanwhile Lieutenant L. Abel-Smith and Sergeant Williams went
down a line of huts to the right, to see if an advance could be made
in that direction, but were met with a withering fire from the right
flank. With two platoons they therefore advanced a short distance
down the centre of the village, but the enemy’s machine-gun fire
was so fierce that the ground over which they crawled was plastered
with bullets. Some men, who were creeping along behind a wall,
were killed by bullets which pierced the brickwork, and Lieutenant L.
Abel-Smith himself was wounded.
This most gallant attempt on the part of No. 3 Company to
capture the village resulted in such heavy losses that it was obvious
it would have to retire. A German counter-attack as it was
attempting to consolidate its position settled the matter. A certain
number of men managed to get back, but most of them were killed
or taken prisoners, including Captain Burke himself, who died
fighting to the last. The same fate befell Second Lieutenant Chitty,
who, with a party of No. 1 Company, had succeeded in entering the
village.
Captain Paton with No. 4 Company had the difficult task of
deciding what he should do, on reaching the trench in front of
Gonnelieu. No. 3 had gone on into the outskirts, and there was no
sign of the Welsh Guards on his right. It was obvious that his best
plan would be to hold the trench until the others came up into line,
so that at least those who had gone on would have a strong
supporting line to retire to. But there was a mixed medley of men on
his left, who seemed to be wavering in the face of the counter-
attack. Captain Paton thereupon leaped out of his trench, and ran
across the open, with machine-gun bullets ploughing up the ground
all round him. With almost reckless bravery he went from trench to
trench in full sight of the German machine-gunners, encouraging
these groups of men from various regiments. At first he seemed to
have almost a charmed life, and his splendid example inspirited all
47.
who saw him.The situation was saved, and he fell soon afterwards
mortally wounded. For this conspicuous act of gallantry he was
posthumously awarded the Victoria Cross. Captain Gerard, the
Adjutant, who came up to obtain information for Lord Gort, found
that owing to Captain Paton’s efforts the left flank was secure.
It was now clear that without considerable reinforcements and
unlimited sacrifices the village could not be taken. The enemy’s
machine-guns were too strong. The Germans were counter-
attacking, and were able to overpower any parties that had gained a
footing in the village. Only one of the fourteen tanks that had been
expected appeared, and, although it was undoubtedly a great help
to the Welsh Guards, it was quite inadequate by itself. The Brigade
on the left and the Welsh Guards on the right had been held up, so
that even had the Battalion taken the village they would not have
been able to hold it. A German officer captured that day stated that
his battalion had attacked from behind Gonnelieu at 6 A.M., and as
our attack started at 6.30 they had been completely disorganised by
our advance, which they imagined was a counter-attack delivered
with amazing rapidity.
Captain Sloane-Stanley, who had come up with No. 1 Company,
determined to consolidate the trench immediately in front of
Gonnelieu, so that it might be held with what remained of the
attacking Companies. Lieutenant Irby of the same Company held a
block in the trench against persistent bombing attacks, and
eventually knocked out a German machine-gun by counter-bombing.
Lord Gort himself now came up to see exactly how matters stood,
and walked about, as he always did on such occasions, with an
absolute disregard for all danger. It was not long, however, before he
was severely wounded; the only wonder was that he had not been
hit before. There were many acts of individual bravery, and perhaps
the gallantry displayed by Sergeants Canham and Buckle was one of
the most conspicuous. At one time, when the enemy were advancing
dangerously near our line, these two sergeants left their trench, and
48.
Dec. 3.
charged. TheGermans, imagining that these two wore only the
foremost of a large party, fled in confusion.
Major Pilcher, who now assumed command of the 4th Battalion,
was confronted with a very difficult situation. The sadly depleted
ranks of the Battalion were holding the trench in front of Gonnelieu,
and there were only three officers left—Captain H. Sloane-Stanley,
Lieutenant Layton, and Lieutenant Irby. The tactical position was
hazardous in the extreme, for both flanks were in the air and
dangerously large gaps in the line seemed to invite a German attack.
When the troops on the left retired, Major Pilcher called on the 1st
Battalion Grenadiers to send up one Company to his assistance, and
Captain Rhodes was sent to form a defensive flank. Later, when
further assistance was required, two more Companies under Captain
Spence and Captain Lawford advanced down the sunken road, and
prolonged the line to the left. This timely assistance undoubtedly
saved the left flank of the 4th Battalion, and enabled it to maintain
its position.
The line now formed a salient in front of Gonnelieu; the
apex being held by the 4th Battalion with some men of the
Northants Labour Battalion. On the left was the 1st Battalion
Grenadiers, which formed a defensive flank, while the Welsh Guards
écheloned back to the right. This position was maintained until
December 3, when the 4th Battalion was relieved by the 2nd
Battalion Scots Guards, which latter had been due the night before.
Owing to the delay the already exhausted officers and men had to
spend a further twenty-four hours in the trenches, exposed to a hard
frost. It was only through almost superhuman efforts that they
received their rations on the morning of the 2nd, as the failure to
relieve them had upset all arrangements for supply.
On the night of the 3rd they marched back, and bivouacked in
the open on some ground north of Gouzeaucourt Wood, where they
remained ready, in case their services should be required.
49.
1st Batt.
Nov.
When theGuards Division left the area of operations near
Gouzeaucourt, the 4th Battalion proceeded to Etricourt, where they
entrained for Laherliere. Thence they marched to Gouy-en-Artois,
and were placed in comfortable billets in a château. On December
11 they proceeded to Dainville, where they remained till the end of
the month training. The weather became very cold and misty, and
later there was a good deal of snow. On the 23rd the following
officers joined the Battalion: Lieutenant F. C. Lyon, the Hon. C. C. S.
Rodney, Second Lieutenant B. R. Osborne, Second Lieutenant R. D.
Richardson, and Second Lieutenant C. J. Dawson-Greene.
The 1st Battalion
After the operations at Bixschoote in October, the 1st
Battalion remained in billets at Zudroue, near Watten. During
this period the following officers joined the Battalion: Lieutenant I.
C. Gascoigne, Second Lieutenant D. B. Topham, Lieutenant R. D.
Lawford, Second Lieutenant A. H. Forbes, Second Lieutenant C.
Cruttenden, and Lieutenant H. G. Wiggins. Captain H. H. Castle,
R.A.M.C., also arrived to take the place of Captain P. H. Wells,
R.A.M.C. While the Battalion was at Zudroue, the Colonel of the
Regiment, Field-Marshal H.R.H. the Duke of Connaught, paid them a
visit.
On November 9 the move south began, and the 1st Battalion
marched to Enquin-les-Mines, continuing its march on the following
day to Fabain Palfart, and then on to Foolinricametz. Second
Lieutenant S. J. Hargreaves joined from the base on the 15th. The
march was continued on the 17th through Ivergny Pommier to
Achiet-le-Petit, where the men had twenty-four hours’ rest. The
greatest secrecy was preserved, and no orders were issued to the
Company Commanders till the last moment, though from the great
concentration of troops it seemed clear that some big move was
impending. The 1st Battalion was brought up in buses to Beaumetz-
les-Cambrai, and from there it marched with the rest of Seymour’s
Brigade to Flesquières. Though two Battalions of the Brigade were
50.
sent up tosupport the Fortieth Division, which was taking Bourlon
Wood, the 1st Battalion did not take part in these operations. On the
night of the 27th the 1st Battalion Grenadiers and the 1st Battalion
Welsh Guards, assisted by two Companies from the 2nd Battalion
Coldstream Guards, relieved the 2nd Guards Brigade in the front
line. The following officers took part in these operations:
Lieut.-Colonel M. E. Makgill-
Crichton-Maitland, D.S.O.
Commanding
Officer.
Capt. L. G. Fisher-Rowe, M.C. Second in
Command.
Lieut. W. H. Lovell, M.C. Acting Adjutant.
Lieut. L. de J. Harvard King’s Company.
Lieut. J. A. Lloyd ” ”
2nd Lieut. J. H. Frere ” ”
Capt. A. T. G. Rhodes No. 2 Company.
2nd Lieut. L. G. Byng ” ”
2nd Lieut. E. G. Hawkesworth ” ”
2nd Lieut. W. U. Timmis ” ”
Capt. P. M. Spence, M.C. No. 3 Company.
Lieut. H. G. Wiggins ” ”
Lieut. S. J. Hargreaves ” ”
2nd Lieut. C. Cruttenden ” ”
Capt. R. D. Lawford No. 4 Company.
Lieut. the Hon. P. P. Cary ” ”
2nd Lieut. C. C. Mays ” ”
Lieut. N. G. Chamberlain ” ”
Capt. H. H. Castle, R.A.M.C. Medical Officer.
Conditions were favourable for carrying out the relief, and the
next day passed without incident, although the enemy continued to
shell the valley south of Bourlon Wood. On the evening of the 28th
the 3rd Guards Brigade, having been relieved by the Fifty-ninth
Division, marched to the reserve trenches south-west of Ribecourt.
51.
Welcome to ourwebsite – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
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.
Let us accompany you on the journey of exploring knowledge and
personal growth!
ebookfinal.com