Professional Documents
Culture Documents
Full Chapter Asynchronous Programming in Rust 1St Edition Carl Fredrik Samson PDF
Full Chapter Asynchronous Programming in Rust 1St Edition Carl Fredrik Samson PDF
https://textbookfull.com/product/asynchronous-programming-in-
rust-1-converted-edition-carl-fredrik-samson/
https://textbookfull.com/product/programming-rust-1st-edition-
jim-blandy/
https://textbookfull.com/product/asynchronous-android-
programming-helder-vasconcelos/
The Rust Programming Language Covers Rust 2018 Steve
Klabnik
https://textbookfull.com/product/the-rust-programming-language-
covers-rust-2018-steve-klabnik/
https://textbookfull.com/product/hands-on-functional-programming-
in-rust-1st-edition-andrew-johnson/
https://textbookfull.com/product/the-rust-programming-
language-1st-edition-steve-klabnik/
https://textbookfull.com/product/programming-webassembly-with-
rust-1st-edition-kevin-hoffman/
https://textbookfull.com/product/network-programming-with-
rust-1st-edition-abhishek-chanda/
Asynchronous Programming
in Rust
ISBN 978-1-80512-813-7
www.packtpub.com
To my family—my brother, my parents, and especially my beloved wife and fantastic children that
make every day an absolute joy.
Prefacexiii
2
How Programming Languages Model Asynchronous Program
Flow25
Definitions26 Fibers and green threads 33
Threads27 Each stack has a fixed space 34
Context switching 35
Threads provided by the operating
Scheduling35
system29
FFI36
Creating new threads takes time 29
Each thread has its own stack 29 Callback based approaches 37
Context switching 30 Coroutines: promises and futures 38
Scheduling30 Coroutines and async/await 39
The advantage of decoupling asynchronous
operations from OS threads 31 Summary41
Example31
3
Understanding OS-Backed Event Queues, System Calls, and
Cross-Platform Abstractions 43
Technical requirements 44 epoll, kqueue, and IOCP 49
Running the Linux examples 45 Cross-platform event queues 50
Why use an OS-backed event queue? 45 System calls, FFI, and cross-platform
Blocking I/O 46 abstractions51
Non-blocking I/O 46 The lowest level of abstraction 51
Event queuing via epoll/kqueue and IOCP 47 The next level of abstraction 55
The highest level of abstraction 61
Readiness-based event queues 47
Completion-based event queues 48 Summary61
Table of Contents ix
5
Creating Our Own Fibers 95
Technical requirements 96 Running our example 107
How to use the repository alongside The stack 109
the book 96 What does the stack look like? 109
Background information 97 Stack sizes 111
Instruction sets, hardware architectures, and
ABIs97
Implementing our own fibers 112
The System V ABI for x86-64 99 Implementing the runtime 115
A quick introduction to Assembly language 102 Guard, skip, and switch functions 121
What the Rust language and standard I/O vs CPU-intensive tasks 134
library take care of 133 Summary135
7
Coroutines and async/await 137
Technical requirements 137 async/await154
Introduction to stackless coroutine/wait155
coroutines138 corofy—the coroutine preprocessor 155
An example of hand-written b-async-await—an example of a coroutine/
coroutines139 wait transformation 156
8
Runtimes, Wakers, and the Reactor-Executor Pattern 167
Technical requirements 168 Changing the Future definition 191
Introduction to runtimes and Step 2 – Implementing a proper
why we need them 169 Executor192
Reactors and executors 170 Step 3 – Implementing a proper
Improving our base example 171 Reactor199
Design173 Experimenting with our new
Changing the current implementation 177 runtime208
An example using concurrency 208
Creating a proper runtime 184
Running multiple futures concurrently and in
Step 1 – Improving our runtime parallel209
design by adding a Reactor and a
Waker187 Summary211
Creating a Waker 188
Table of Contents xi
9
Coroutines, Self-Referential Structs, and Pinning 213
Technical requirements 214 Pinning in theory 234
Improving our example Definitions234
1 – variables 214 Pinning to the heap 235
Setting up the base example 215 Pinning to the stack 237
Improving our base example 217 Pin projections and structural
pinning240
Improving our example
2 – references 222 Improving our example
4 – pinning to the rescue 241
Improving our example 3 – this
future.rs242
is… not… good… 227
http.rs242
Discovering self-referential Main.rs244
structs229 executor.rs246
What is a move? 231
Summary248
Pinning in Rust 233
10
Creating Your Own Runtime 251
Technical requirements 251 Explicit versus implicit reactor
Setting up our example 253 instantiation265
main.rs253 Ergonomics versus efficiency and
flexibility266
future.rs254
Common traits that everyone agrees
http.rs254
about267
executor.rs256
Async drop 268
reactor.rs259
The future of asynchronous Rust 269
Experimenting with our runtime 261
Summary269
Challenges with asynchronous
Rust265 Epilogue272
Index275
I want this book to feel like you’re joining me on a journey, where we build our knowledge topic by
topic and learn by creating examples and experiments along the way. I don’t want this book to feel
like a lecturer simply telling you how everything works.
This book is created for people who are curious by nature, the kind of programmers who want to
understand the systems they use, and who like creating small and big experiments as a way to explore
and learn.
There are two kinds of personas that I feel this book is especially relevant to:
• Developers coming from higher-level languages with a garbage collector, interpreter, or runtime,
such as C#, Java, JavaScript, Python, Ruby, Swift, or Go. Programmers who have extensive
experience with asynchronous programming in any of these languages but want to learn it
from the ground up and programmers with no experience with asynchronous programming
should both find this book equally useful.
• Developers with experience in languages such as C or C++ that have limited experience with
asynchronous programming.
Chapter 4, Create Your Own Event Queue, is the chapter where you create your own event queue that
mimics the API of mio (the popular Rust library that underpins much of the current async ecosystem).
The example will center around epoll and go into quite a bit of detail on how it works.
Chapter 5, Creating Our Own Fibers, walks through an example where we create our own kind of
stackful coroutines called fibers. They’re the same kind of green threads that Go uses and show one
of the most widespread and popular alternatives to the type of abstraction Rust uses with futures and
async/await today. Rust used this kind of abstraction in its early days before it reached 1.0, so it’s also
a part of Rust’s history. This chapter will also cover quite a few general programming concepts, such
as stacks, assembly, Application Binary Interfaces (ABIs), and instruction set architecture (ISAs),
that are useful beyond the context of asynchronous programming as well.
Chapter 6, Futures in Rust, gives a short introduction and overview of futures, runtimes, and
asynchronous programming in Rust.
Chapter 7, Coroutines and async/await, is a chapter where you write your own coroutines that are
simplified versions of the ones created by async/await in Rust today. We’ll write a few of them by
hand and introduce a new syntax that allows us to programmatically rewrite what look like regular
functions into the coroutines we wrote by hand.
Chapter 8, Runtimes, Wakers, and the Reactor-Executor Pattern, introduces runtimes and runtime
design. By iterating on the example we created in Chapter 7, we’ll create a runtime for our coroutines
that we’ll gradually improve. We’ll also do some experiments with our runtime once it’s done to better
understand how it works.
Chapter 9, Coroutines, Self-Referential Structs, and Pinning, is the chapter where we introduce self-
referential structs and pinning in Rust. By improving our coroutines further, we’ll experience first-hand
why we need something such as Pin, and how it helps us solve the problems we encounter.
Chapter 10, Create Your Own Runtime, is the chapter where we finally put all the pieces together. We’ll
improve the same example from the previous chapters further so we can run Rust futures, which will
allow us to use the full power of async/await and asynchronous Rust. We’ll also do a few experiments
that show some of the difficulties with asynchronous Rust and how we can best solve them.
The ideal way to read this book is to have the book and a code editor open side by side. You should
also have the accompanying repository available so you can refer to that if you encounter any issues.
You need Rust installed. If you haven’t already, follow the instructions here: https://www.rust-
lang.org/tools/install.
Some examples will require you to use Windows Subsystem for Linux (WSL) on Windows. If you’re
following along on a Windows machine, I recommend that you enable WSL (https://learn.
microsoft.com/en-us/windows/wsl/install) now and install Rust by following the
instructions for installing Rust on WSL here: https://www.rust-lang.org/tools/install.
If you are using the digital version of this book, we advise you to type the code yourself or access
the code from the book’s GitHub repository (a link is available in the next section). Doing so will
help you avoid any potential errors related to the copying and pasting of code.
The accompanying repository is organized in the following fashion:
• Code that belongs to a specific chapter is in that chapter’s folder (e.g., ch01).
• Each example is organized as a separate crate.
• The letters in front of the example names indicate in what order the different examples are
presented in the book. For example, the a-runtime example comes before the b-reactor-
executor example. This way, they will be ordered chronologically (at least by default on
most systems).
• Some examples have a version postfixed with -bonus. These versions will be mentioned in
the book text and often contain a specific variant of the example that might be interesting to
check out but is not important to the topic at hand.
Conventions used
There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names, filenames, file
extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “So, now
we have created our own async runtime that uses Rust’s Futures, Waker, Context, and async/
await.”
A block of code is set as follows:
When we wish to draw your attention to a particular part of a code block, the relevant lines or items
are set in bold:
struct Coroutine0 {
stack: Stack0,
state: State0,
}
$ cargo run
Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at customercare@
packtpub.com and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen.
If you have found a mistake in this book, we would be grateful if you would report this to us. Please
visit www.packtpub.com/support/errata and fill in the form.
xviii Preface
Piracy: If you come across any illegal copies of our works in any form on the internet, we would
be grateful if you would provide us with the location address or website name. Please contact us at
[email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you
are interested in either writing or contributing to a book, please visit authors.packtpub.com.
https://packt.link/free-ebook/9781805128137
In this part, you’ll receive a thorough introduction to concurrency and asynchronous programming.
We’ll also explore various techniques that programming languages employ to model asynchrony,
examining the most popular ones and covering some of the pros and cons associated with each. Finally,
we’ll explain the concept of OS-backed event queues, such as epoll, kqueue, and IOCP, detailing how
system calls are used to interact with the operating system and addressing the challenges encountered
in creating cross-platform abstractions like mio. This section comprises the following chapters:
• Async history
• Concurrency and parallelism
• The operating system and the CPU
• Interrupts, firmware, and I/O
This chapter is general in nature. It doesn’t specifically focus on Rust, or any specific programming
language for that matter, but it’s the kind of background information we need to go through so we
know that everyone is on the same page going forward. The upside is that this will be useful no matter
what programming language you use. In my eyes, that fact also makes this one of the most interesting
chapters in this book.
4 Concurrency and Asynchronous Programming: a Detailed Overview
There’s not a lot of code in this chapter, so we’re off to a soft start. It’s a good time to make a cup of
tea, relax, and get comfortable, as we’re about start this journey together.
Technical requirements
All examples will be written in Rust, and you have two alternatives for running the examples:
• Write and run the examples we’ll write on the Rust playground
• Install Rust on your machine and run the examples locally (recommended)
The ideal way to read this chapter is to clone the accompanying repository (https://github.
com/PacktPublishing/Asynchronous-Programming-in-Rust/tree/main/
ch01/a-assembly-dereference) and open the ch01 folder and keep it open while you read
the book. There, you’ll find all the examples we write in this chapter and even some extra information
that you might find interesting as well. You can of course also go back to the repository later if you
don’t have that accessible right now.
Non-preemptive multitasking
Non-preemptive multitasking was the first method used to be able to keep a UI interactive (and
running background processes).
This kind of multitasking put the responsibility of letting the OS run other tasks, such as responding
to input from the mouse or running a background task, in the hands of the programmer.
Typically, the programmer yielded control to the OS.
An evolutionary journey of multitasking 5
Besides offloading a huge responsibility to every programmer writing a program for your platform,
this method was naturally error-prone. A small mistake in a program’s code could halt or crash the
entire system.
Note
Another popular term for what we call non-preemptive multitasking is cooperative multitasking.
Windows 3.1 used cooperative multitasking and required programmers to yield control to
the OS by using specific system calls. One badly-behaving application could thereby halt the
entire system.
Preemptive multitasking
While non-preemptive multitasking sounded like a good idea, it turned out to create serious problems
as well. Letting every program and programmer out there be responsible for having a responsive UI
in an operating system can ultimately lead to a bad user experience, since every bug out there could
halt the entire system.
The solution was to place the responsibility of scheduling the CPU resources between the programs
that requested it (including the OS itself) in the hands of the OS. The OS can stop the execution of a
process, do something else, and switch back.
On such a system, if you write and run a program with a graphical user interface on a single-core
machine, the OS will stop your program to update the mouse position before it switches back to your
program to continue. This happens so frequently that we don’t usually observe any difference whether
the CPU has a lot of work or is idle.
The OS is responsible for scheduling tasks and does this by switching contexts on the CPU. This process
can happen many times each second, not only to keep the UI responsive but also to give some time
to other background tasks and IO events.
This is now the prevailing way to design an operating system.
Note
Later in this book, we’ll write our own green threads and cover a lot of basic knowledge about
context switching, threads, stacks, and scheduling that will give you more insight into this
topic, so stay tuned.
Hyper-threading
As CPUs evolved and added more functionality such as several arithmetic logic units (ALUs) and
additional logic units, the CPU manufacturers realized that the entire CPU wasn't fully utilized. For
6 Concurrency and Asynchronous Programming: a Detailed Overview
example, when an operation only required some parts of the CPU, an instruction could be run on the
ALU simultaneously. This became the start of hyper-threading.
Your computer today, for example, may have 6 cores and 12 logical cores.. This is exactly where hyper-
threading comes in. It “simulates” two cores on the same core by using unused parts of the CPU to
drive progress on thread 2 and simultaneously running the code on thread 1. It does this by using a
number of smart tricks (such as the one with the ALU).
Now, using hyper-threading, we could actually offload some work on one thread while keeping the
UI interactive by responding to events in the second thread even though we only had one CPU core,
thereby utilizing our hardware better.
Multicore processors
As most know, the clock frequency of processors has been flat for a long time. Processors get faster by
improving caches, branch prediction, and speculative execution, and by working on the processing
pipelines of the processors, but the gains seem to be diminishing.
On the other hand, new processors are so small that they allow us to have many on the same chip. Now,
most CPUs have many cores and most often, each core will also have the ability to perform hyper-threading.
Note
*However, modern CPUs can also do a lot of things in parallel. Most CPUs are pipelined,
meaning that the next instruction is loaded while the current one is executing. It might have
a branch predictor that tries to figure out what instructions to load next.
The processor can also reorder instructions by using out-of-order execution if it believes it
makes things faster this way without ‘asking’ or ‘telling’ the programmer or the OS, so you
might not have any guarantee that A happens before B.
The CPU offloads some work to separate ‘coprocessors’ such as the FPU for floating-point
calculations, leaving the main CPU ready to do other tasks et cetera.
As a high-level overview, it’s OK to model the CPU as operating in a synchronous manner,
but for now, let’s just make a mental note that this is a model with some caveats that become
especially important when talking about parallelism, synchronization primitives (such as
mutexes and atomics), and the security of computers and operating systems.
Important
Concurrency is about dealing with a lot of things at the same time.
Parallelism is about doing a lot of things at the same time.
We call the concept of progressing multiple tasks at the same time multitasking. There are two ways to
multitask. One is by progressing tasks concurrently, but not at the same time. Another is to progress
tasks at the exact same time in parallel. Figure 1.1 depicts the difference between the two scenarios:
8 Concurrency and Asynchronous Programming: a Detailed Overview
• Resource: This is something we need to be able to progress a task. Our resources are limited.
This could be CPU time or memory.
• Task: This is a set of operations that requires some kind of resource to progress. A task must
consist of several sub-operations.
• Parallel: This is something happening independently at the exact same time.
• Concurrent: These are tasks that are in progress at the same time, but not necessarily
progressing simultaneously.
This is an important distinction. If two tasks are running concurrently, but are not running in parallel,
they must be able to stop and resume their progress. We say that a task is interruptible if it allows for
this kind of concurrency.
Language: English
Credits: Al Haines
BY
A. HUGH FISHER
"The beauty of the world is simple like a looking-glass."
LONDON
T. WERNER LAURIE
CLIFFORD'S INN
TO MY FRIENDS IN ENGLAND
PREFACE
A. HUGH FISHER.
CONTENTS
CHAP.
I. RANGOON
II. HIS HIGHNESS THE SAWBWA OF HSIPAW
III. UP THE IRRAWADDY TO BHAMO
IV. THE DEAD HEART OF A KINGDOM
V. MANDALAY
VI. SOUTHERN INDIA, THE LAND OF HINDOO TEMPLES
VII. CALCUTTA
VIII. MY FIRST SIGHT OF THE HIMALAYAS
IX. BENARES
X. LUCKNOW
XI. CAWNPORE
XII. THE HOUSE OF DREAM
XIII. DELHI
XIV. DEHRA DUN AND LANDOUR
XV. AN EVENING OF GOLD
XVI. "GUARD YOUR SHOES"
XVII. "A GATE OF EMPIRE"
XVIII. THE CAPITAL OF THE PUNJAB
XIX. AT THE COURT OF HIS HIGHNESS THE RAJAH OF NABHA
XX. IN SIGHT OF AFGHANISTAN
XXI. RAJPUTANA
XXII. SIR PRATAP SINGH
XXIII. THE MOHARAM FESTIVAL
XXIV. RAKHYKASH
XXV. POLITICAL
INDEX
ILLUSTRATIONS
RANGOON
Down came the rain, sudden, heavy and terrible, seeming to quell even
the sea's rage and whelming those defenceless hundreds of dark-skinned
voyagers in new and more dreadful misery.
What trouble a Hindoo will take to keep his body from the rain!
Extremely cleanly and fond of unlimited ablutions he yet detests nothing so
much as a wetting from the sky, and now, wholly at the mercy of the
elements, do what they would, no human ingenuity availed to keep these
wretched people dry.
It was the season of the rice harvest, when South India coolies swarm
over to Burmah much as the peasantry of Mayo and Connemara used to
crowd to England every summer.
Somebody said that our ship was an unlucky one—that it ran down the
Mecca on her last trip and killed her third officer; but we got through safely
enough, though that crossing was one of the most disagreeable as well as the
most weird I ever made—disagreeable because of the bad weather, and
weird because of the passengers.
The deck and the lower deck were tanks of live humanity, and when it
began to get rough, as it did the morning after we left Madras, catching the
end of a strayed cyclone, it was worse than a Chinese puzzle to cross from
the saloon to the spar deck, and ten chances to one that even if you did
manage to avoid stepping on a body you slipped and shot into seven sick
Hindoo ladies and a family of children.
There were six first-class passengers, all Europeans, and 1700 deck
passengers, all Asiatics, and the latter paid twelve rupees each for the four
days' passage, bringing with them their own food.
After coffee the man next to me suddenly leapt from his chair with a
yell. He thought he had been bitten by a centipede. The centipede was there
right enough, but as the pain passed off the next day we supposed the brute
had only fastened his legs in and had not really bitten.
The nights were sultry and the ship rolled worse every watch. I think,
however, that I never saw people try harder than those natives did to keep
clean. They had all brought new palm-leaf mats to lie upon, but they could
not lie down without overlapping. I asked the captain what he did about
scrubbing decks, and he said it was always done at the end of the voyage!
Next morning the downpour, already referred to, began and did the business
with cruel effectiveness.
As we neared Burmah the sea grew calm again and the rain abated. The
sun dried sick bodies and cheered despondent hearts. I spoke to a woman
crouching by some sacks and tin cans, with an old yellow cloth round her
head and shoulders, and another cloth swathing her loins. She had very dark
brown eyes, and her fingernails were bright red and also the palms of her
hands from the "maradelli" tied round the nails at night. She was the wife of
a man the other side of fourteen people, some four yards away. I asked his
name, not knowing that a Hindoo woman may not pronounce her husband's
name. She called him "Veetkar," which means uncle or houseman: the man
was of the Palla caste, which is just a little higher than the Pariah, and they
had been married five years but had no children. This was the man's second
marriage, his first wife having died of some liver complaint he said. Like
most of the passengers they were going out for paddy-field work, but unlike
so many others, they were "on their own" not being taken over by a labour
contractor. The man said he should get work at Kisshoor village, about eight
miles from Rangoon. Every year for seven years he had been over.
Altogether, this man had saved, according to his own statement, two
hundred rupees in the seven years' work, and had invested this in bullocks
and a little field near his village, which was named Verloocooli. He had left
the son of his first wife to look after the house and the field.
About twenty people round one corner of the open hatch seemed to
belong to one another. They came from the Soutakar district and were
drinking rice-water—that is the water poured off when rice is boiled. A
Mohammedan with two sons was going to sell things. The boys would watch
the goods, he told me. He was returning to Upper Burmah, where he had
lived twenty-four years, and he had only been over to Madras to visit his
mother and father. He has "just a little shop" for the sale of such goods as
dal, chili, salt, onions, coconut oil, sweet oil, tamarind, matches and candles.
Then there was the Mongolian type of Mohammedan. He was very fat
and greasy, and had one of his dog teeth long like a tusk. He was a tin-
worker and made large cans in his shop in Rangoon.
I went down between decks and never saw people packed so closely
before except on Coronation Day. Even "marked" men discarded all clothing
but a small loin cloth: most of them could not move hand or foot without
their neighbours feeling the change of position; and as upon the deck above,
they often lay partly over each other. Yet in spite of the general
overcrowding, I noticed a woman of the Brahmin caste lying at her ease in a
small open space marked out by boxes and tin trunks. There was a large
lamp in a white reflector hanging by the companion-way, and some of those
lying nearest to it held leaf fans over their faces to keep the light from their
eyes.
The next day was brighter. There was a light wind and the whole sunlit
crowd was a babel of excited talk. A little naked Hindoo baby, just able to
walk, was playing mischievously with me. I had been nursing her for a while
and now she was laughing, and with palms up-turned was moving her hands
like a Nautch dancer as her eyes twinkled with merriment. She was called
Mutama, and the poor mite's ears had had a big cut made in them and the
lobes were already pulled out more than two inches by the bunches of metal
rings fastened in for this purpose.
A purple shawl, tied up to dry, bellied out in the wind over the side of the
ship in a patch of vivid colour. It had a border of gold thread and was of
native make. Not that the gold thread itself is made in Madras. It is curious
that English manufacturers have tried in vain to make these shawls so that
their gold thread shall not tarnish, whereas the gold thread obtained from
France does not do so.
The following morning we reached very turbid water, thick and yellow,
with blue reflections of the sky in the ripples. We could just see the coast of
Burmah and about noon caught sight of the pilot brig, and entering the wide
Rangoon river, passed a Chinese junk with all sails spread. Now the mats
began to go overboard and gulls swooped round the ship. We had passed the
obelisk at the mouth of the river when, above a green strip of coast on a little
blue hill, the sun shone upon something golden.
"The Pagoda!" I cried, and a pagoda it was, but only one at Siriam where
there is a garrison detachment. The Golden Pagoda—the Shwe Dagon—
appeared at first grey and more to the north. The water was now as thick and
muddy as the Thames at the Tower Bridge. It was full of undercurrents too,
and there was a poor chance for anyone who fell in.
Over went the mats, scores and scores and scores of them!
There is a bar a little further on called the Hastings, and it was a question
whether we'd get over it that afternoon. A line of yellow sand detached itself
from the green, and then the water became like shot silk, showing a pale
flood of cerulean slowly spreading over its turbid golden brown. On the low
bank were green bushes and undergrowth, and beyond—flat levels of tawny-
yellow and low tree-clad rising ground that reminded me of the Thames
above Godstow.
Beyond the green point of Siriam, just after the Pegu River branches off
to the right, the Rangoon River sweeps round in a great curve, at the far end
of which stretches the city. It was pale violet in the afternoon light, with
smoke streaming from vessels in the harbour, and on the highest point the
Shwe Dagon just showing on one edge that it was gold. Far to the right were
some twenty tall chimney-stacks of the Burmah Oil Works, but their colour,
instead of being sooty and unclean, was all blue and amethyst under a citron
sky.
The Customs Officer came out in a long boat, pulled by four men in red
turbans, and in his launch the medical officer of the port with a lady doctor.
There is a constant but ineffectual struggle to keep plague out of Burmah,
and every one of our 1700 deck passengers had to be thoroughly examined
—stripped to the waist with arms up, while the doctor passed his hands
down each side of the body.
The same night, on shore, I drove to the Shwe Dagon past the race-
ground, where a military tattoo was going on by torchlight.
Between great pillars, faced with plaster, red on the lower portion and
white above, I walked on while more dogs came yelping and snarling
angrily. I heard a low human wail which changed to a louder note and died
away—someone praying perhaps. Then all was quite still except for the
crickets. Now I was in a hall of larger columns and walked under a series of
carved screens—arches of wood set between pairs of them. Half-way up
these columns hung branches of strange temple offerings, things made in
coloured papers with gold sticks hanging from them.
At last I came out upon the upper platform on which stands the Pagoda
itself. Facing the top of the last flight of steps at the back of a large many-
pillared porch, reeking with the odour of burnt wax, I saw a cavernous
hollow, and set within it, behind lighted candles, dimly a golden Buddha in
the dusk. Outside, a strip of matting was laid over the flagged pavement all
round the platform, and in the stones little channels cut transversely for
drainage in the time of the rains lay in wait to trip careless feet.
Some years ago when the great "Hti" was brought down from the summit
of the Pagoda, after an earthquake, to be restored and further embellished,
people of all classes brought offerings of money and jewellery through the
turnstiles on to this platform. What a sight it must have been to see the lines
of Burmese people crowding up through these two turnstiles, one for silver
and one for gold—one woman giving two jewelled bracelets and the next a
bangle; a receipt would be given to each donor and then bangle and bracelets
thrown into the melting-pot after their jewels had been taken out for adding
to the "Hti."
HINDOO GIRL, SHOWING ELABORATE JEWELLERY.
Night had driven unscourged the money-changers from the temple, and
the magic light of the moon weaving silver threads through every garish tint
of paint had changed crude colours to ideal harmonies. Not colour alone but
form also was glorified. The grotesque had become dramatic, confusion had
changed to dignity, all surrounding detraction was subdued and the great
ascending curves of the Pagoda rose in simple, uncontested beauty. Nature
adored, acknowledging conquest, and the sound of those far wind-caught
bells was like that of the voices of angels and fairies singing about the cradle
of a child.
I had seen no building of such emotional appeal nor any that seems so
perfectly designed to wed the air and light that bathe it and caress it. But
imagine the Shwe Dagon transplanted to the cold light of some gargantuan
museum near the Cromwell Road; the nicest taste, the most steadfast
determination, could not unlock its charm. Here, upon easy hinge, the door
swings back at every raising of the eyes, and illumination is for all
beholders.
The following afternoon I was again at the Shwe Dagon, and to watch its
beauty under the glory of the setting sun was a further revelation. It seemed
to show fresh and delicate charm at each part of the day, and after burning at
sunset, like a man filled with impetuous passion, shone in the after-glow
with the diviner loveliness of the woman who gives her heart.
Building proceeds at such a rate that the big city seems to be growing
while you look at it, but there are plenty of open spaces. Government House,
in red brick and white stone, with an old bronze bell hung in front of the
portico between two brass cannon, stands in a goodly park with fine trees
and wide lawns and the Royal Lakes, across which there is a beautiful view
of the Shwe Dagon, are surrounded by large grounds with trim, well-kept
walks and drives. While I was painting by one of the lakes a water-snake
every now and then lifted its head above the surface, sometimes a foot and a
half out of the water like some long-necked bird.
I was driving back towards the hotel along the Calvert Road when I
noticed a temporary wood-framed structure, covered with coloured papers
and painted trellis-work. On inquiry I found it had been erected by a
Buddhist Society of that quarter of the city, and that the same night upon a
stage close to it in the open air a "Pwe" would be given, to which I was
bidden welcome about nine o'clock.
At my hotel two people had been poisoned by tinned food a few weeks
earlier, but whatever the table lacked in quality it made up in
pretentiousness. I quote that day's menu for comparison with the items of
another repast the same evening:—
It was after an early and somewhat abridged version of the above that I
drove in the cheerless discomfort of a "tikka gharry" through Rangoon again
in the moonlight. After twenty minutes I saw once more the paper temple.
There were two long lines of lanterns high in the air in the shape of a
horizontal V, and under them a great crowd of people. The trellised temple
itself was also charmingly decorated with lanterns.
ALTAR TABLE AT A BUDDHIST SOCIETY'S CELEBRATION.
Four silver dishes were now brought to me on a lacquered box, and these
contained Burmah cheroots, betel leaves and areca nut, tobacco leaves and
chunam (lime). Chilis were also brought, which made me long in vain for a
cool drink.
Outside, beyond the walls of pale green trellis, glowed the lanterns, and
faces peered at us between the strips of wood. Cloth of red and white stripes
lined the roof, and countless flags, quite tiny ones, were fastened along the
outer green railing.
In front of the Buddha had now been placed some beautiful gold
chalices. The white alabaster figure of Gautama was half as high as a man,
and a band covered with gems glittered across its breast.
About ten o'clock I moved outside, where another arm-chair had been
placed for me, this time in the midst of a great crowd of people.
My interpreter had now gone to join some ladies, and I was left to make
the best I could of this, my first, Burmese "Pwe."
Two characters were dancing on the stage when I took my seat. Perhaps
they were a prince and princess—at any rate they were dressed in old
Burmese court style, in very narrow skirts similar to the "hobble," and
strange short jackets cut with curled bases like horned moons stretched and
held in shape by bamboo frames. There was much swaying and posturing of
the body, combined with quick, jerky movements, the arms were moved a
great deal with bent elbows and the hands with fingers straight and the palms
bent back sharply at the wrists. When these dancers left the stage two men
entered in long white gowns, with broad white bands tied round the head in
big bows. They turned their backs upon the audience at first, and then
turning round squatted upon the floor. Two more similarly dressed came in
in the same manner, and after they had squatted beside the others two quite
astounding figures came on the scene with long bare swords.
The music all this while kept up an accompaniment of jingle and clapper
and tum, tum, tum—jingle and clapper and tum, tum, tum, with a
particularly squeaky wind instrument going ahead at the same time like a
cork being drawn backward and forward over a pane of wet glass.
I discovered now that on turning their backs to the audience on first
entering, the performers made obeisance to a draped bench at the back of the
stage. Two more sword-bearing figures came in and two lance-bearers in
very lovely bejewelled dresses of old gold. There was a long shrill speech
now—then a loud bang, at which all the actors fell to the ground, and a
figure entered bearing a short-pointed mace and sat at once on the draped
bench.
Every now and then I turned my head to look up at the great V-shaped
line of lanterns hanging high in the air overhead from tall bamboo poles, and
the stars shining over all from the night sky. A number of the children were
sleeping, though their elders made a good deal of noise, laughing heartily at
the comic actor as the play went on and on and on. I should like to have
stayed longer, but an appointment with some elephants at an early hour the
next morning made me reluctantly leave the "Pwe" at midnight and hunt
among the back rows of the audience for the driver of that "tikka gharry."
Everyone has heard of the Burmese elephants piling timber. The largest
of the timber companies employing elephants is the Bombay Burmah
Trading Corporation, Limited. The logs, floated down the river from forest-
lands, eight hundred or a thousand miles upstream, are stranded at high rain-
tides at Poozoondoung, a tract of lowland to which I drove in the early
morning.
I reached there just after sunrise, before the dew of the night was yet
evaporated, and the logs, on which one had to walk to avoid the mud, were
very slippery and more difficult to negotiate with boots than without.
The work of the elephants is to push, drag or pile the teak logs, and on
the morning of my visit there were three of the great quadrupeds at work:—
Hpo Chem, aged fifty, a fine tusker who had been twenty years at the work,
and two female elephants, Mee Cyan, seventy years of age, and Mee Poo,
thirty. The male elephant has, of course, tremendous strength in his tusks and
uses them for carrying, holding the log firmly with his trunk as he gravely
walks up the pile of logs to place his burden on the top. Female elephants
can only pile by a combined lift and drag, and do not raise the log entirely
from the ground. Pushing with the head is called "ounging."
At Poozoondoung, not far from the timber-yards, the chief rice-mills are
situated. They were idle now, but when I saw them again after the harvest
their big chimneys were belching forth black smoke from the burning husk.
The husk obtained from the milled grain is not only sufficient for all fuel
requirements, but much has to be shot into the creek for waste.
Native boats called "Loungoes" brought such of the "paddy" from the
country as did not come by rail.
"Hulling" the rice is the operation of breaking off the husk. There were
rows of pairs of round flat stones, the under ones stationary, the upper ones
revolving, not grinding but merely breaking off the husk. Both grain and
husk fell from these stones together to the floor below, and were carried by
bucket-elevators to a fanning-room, where the husk was blown off. After
leaving the fans the grain had its remaining inner skin taken off in "cones"—
cement-faced stones made to press the grain against an outer jacket of
perforated wire. At the base of the cone a cloth hung round an opening in the
floor, through which the rice dropped, while the white skin fell upon the
floor outside to be called "bran," and shipped to Europe for use in the
manufacture of cattle cakes.
When the rice-mills are in full work the smoke of their chimneys hangs
above Rangoon, but overhead every evening the flying foxes pass as usual,
and the beautiful Pagoda is far enough away to remain untarnished upon its
little hill.
BOY SHOWING TATOOING CUSTOMARY WITH ALL BURMESE
MALES.
CHAPTER II