100% found this document useful (6 votes)
23 views

Download ebooks file The dRuby Book Distributed and Parallel Computing with Ruby 1st Edition Masatoshi Seki all chapters

Masatoshi

Uploaded by

donedaknirke
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (6 votes)
23 views

Download ebooks file The dRuby Book Distributed and Parallel Computing with Ruby 1st Edition Masatoshi Seki all chapters

Masatoshi

Uploaded by

donedaknirke
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 81

Download the full version of the ebook at

https://ebookultra.com

The dRuby Book Distributed and Parallel


Computing with Ruby 1st Edition Masatoshi
Seki

https://ebookultra.com/download/the-druby-book-
distributed-and-parallel-computing-with-ruby-1st-
edition-masatoshi-seki/

Explore and download more ebook at https://ebookultra.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Design and Analysis of Distributed Algorithms Wiley Series


on Parallel and Distributed Computing 1st Edition Nicola
Santoro
https://ebookultra.com/download/design-and-analysis-of-distributed-
algorithms-wiley-series-on-parallel-and-distributed-computing-1st-
edition-nicola-santoro/
ebookultra.com

High Performance Parallel Database Processing and Grid


Databases Wiley Series on Parallel and Distributed
Computing 1st Edition David Taniar
https://ebookultra.com/download/high-performance-parallel-database-
processing-and-grid-databases-wiley-series-on-parallel-and-
distributed-computing-1st-edition-david-taniar/
ebookultra.com

Mobile Intelligence Wiley Series on Parallel and


Distributed Computing 1st Edition Laurence T. Yang

https://ebookultra.com/download/mobile-intelligence-wiley-series-on-
parallel-and-distributed-computing-1st-edition-laurence-t-yang/

ebookultra.com

Fundamentals of Computer Organization and Architecture


Wiley Series on Parallel and Distributed Computing 1st
Edition Mostafa Abd-El-Barr
https://ebookultra.com/download/fundamentals-of-computer-organization-
and-architecture-wiley-series-on-parallel-and-distributed-
computing-1st-edition-mostafa-abd-el-barr/
ebookultra.com
Distributed Computing Principles and Applications M.L. Liu

https://ebookultra.com/download/distributed-computing-principles-and-
applications-m-l-liu/

ebookultra.com

Elements of Parallel Computing 1st Edition Eric Aubanel

https://ebookultra.com/download/elements-of-parallel-computing-1st-
edition-eric-aubanel/

ebookultra.com

Introduction to Parallel Computing 2nd Edition Ananth


Grama

https://ebookultra.com/download/introduction-to-parallel-
computing-2nd-edition-ananth-grama/

ebookultra.com

Introduction to Parallel Computing 2nd Edition Ananth


Grama

https://ebookultra.com/download/introduction-to-parallel-
computing-2nd-edition-ananth-grama-2/

ebookultra.com

Mobile Agents in Networking and Distributed Computing 1st


Edition Jiannong Cao

https://ebookultra.com/download/mobile-agents-in-networking-and-
distributed-computing-1st-edition-jiannong-cao/

ebookultra.com
The dRuby Book Distributed and Parallel Computing
with Ruby 1st Edition Masatoshi Seki Digital Instant
Download
Author(s): Masatoshi Seki
ISBN(s): 9781934356937, 193435693X
Edition: 1
File Details: PDF, 7.29 MB
Year: 2012
Language: english
What Readers Are Saying About
The dRuby Book

The dRuby Book is a fantastic introduction to distributed programming in Ruby


for all levels of users. The book covers all aspects of dRuby, including the principles
of distributed programming and libraries and techniques to make your work
easier. I recommend this book for anyone who is interested in distributed program-
ming in Ruby and wants to learn the basics all the way to advanced process
coordination strategies.
➤ Eric Hodel
Ruby committer, RDoc and RubyGems maintainer

dRuby is the key component that liberates Ruby objects from processes and
machine platforms. Masatoshi himself explains its design, features, case studies,
and even more in this book.
➤ Yuki “Yugui” Sonoda
Ruby 1.9 release manager

dRuby naturally extends the simplicity and power Ruby provides. Throughout
this book, Rubyists should be able to enjoy a conversation with dRuby that makes
you feel as if your own thoughts are traveling across processes and networks.
➤ Kakutani Shintaro
RubyKaigi organizer, Ruby no Kai
Any programmer wanting to understand concurrency and distributed systems
using Ruby should read this book. The explanations and example code make
these topics approachable and interesting.
➤ Aaron Patterson
Ruby and Ruby on Rails core committer

A fascinating and informative look at what is classically a total pain in the neck:
distributed object management and process coordination on a single machine or
across a network.
➤ Jesse Rosalia
Senior software engineer
The dRuby Book
Distributed and Parallel Computing with Ruby

Masatoshi Seki
translated by Makoto Inoue

The Pragmatic Bookshelf


Dallas, Texas • Raleigh, North Carolina
Many of the designations used by manufacturers and sellers to distinguish their products
are claimed as trademarks. Where those designations appear in this book, and The Pragmatic
Programmers, LLC was aware of a trademark claim, the designations have been printed in
initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer,
Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trade-
marks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes
no responsibility for errors or omissions, or for damages that may result from the use of
information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team create
better software and have more fun. For more information, as well as the latest Pragmatic
titles, please visit us at http://pragprog.com.

The team that produced this book includes:


Susannah Pfalzer (editor)
Potomac Indexing, LLC (indexer)
Kim Wimpsett (copyeditor)
David J Kelly (typesetter)
Janet Furlow (producer)
Juliet Benda (rights)
Ellie Callahan (support)

Original Japanese edition:


“dRuby niyoru Bunsan Web Programming” by Masatoshi Seki
Copyright © 2005. Published by Ohmsha, Ltd

This English translation, revised for Ruby 1.9, is copyright © 2012 Pragmatic Programmers, LLC.
All rights reserved.

No part of this publication may be reproduced, stored in a retrieval system, or


transmitted, in any form, or by any means, electronic, mechanical, photocopying,
recording, or otherwise, without the prior consent of the publisher.

Printed in the United States of America.


ISBN-13: 978-1-934356-93-7
Encoded using the finest acid-free high-entropy binary digits.
Book version: P1.0—March 2012
Contents
Foreword . . . . . . . . . . . . . . ix

Acknowledgments . . . . . . . . . . . xi

Preface . . . . . . . . . . . . . . xiii

Part I — Introducing dRuby


1. Hello, dRuby . . . . . . . . . . . . . 3
1.1 Hello, World 3
1.2 Building the Reminder Application 7
1.3 Moving Ahead 14

2. Architectures of Distributed Systems . . . . . . 15


2.1 Understanding Distributed Object Systems 15
2.2 Design Principles of dRuby 20
2.3 dRuby in the Real World 24
2.4 Moving Ahead 26

Part II — Understanding dRuby


3. Integrating dRuby with eRuby . . . . . . . . 31
3.1 Generating Templates with ERB 31
3.2 Integrating WEBrick::CGI and ERB with dRuby 40
3.3 Putting Them Together 48
3.4 Adding an Error Page 53
3.5 Changing Process Allocation 54
3.6 Moving Ahead 56
Contents • vii

4. Pass by Reference, Pass by Value . . . . . . . 57


4.1 Passing Objects Among Processes 57
4.2 Passing by Reference Automatically 67
4.3 Handling Unknown Objects with DRbUnknown 72
4.4 Moving Ahead 75

5. Multithreading . . . . . . . . . . . . 77
5.1 dRuby and Multithreading 77
5.2 Understanding the Thread Class 79
5.3 Thread-Safe Communication Using Locking, Mutex, and
MonitorMixin 86
5.4 Passing Objects via Queue 104
5.5 Moving Ahead 108

Part III — Process Coordination


6. Coordinating Processes Using Rinda . . . . . . 111
6.1 Introducing Linda and Rinda 111
6.2 How Rinda Works 113
6.3 Basic Distributed Data Structures 124
6.4 Toward Applications 134
6.5 Moving Ahead 136

7. Extending Rinda . . . . . . . . . . . 137


7.1 Adding a Timeout in a Tuple 137
7.2 Adding Notifications for New Events 141
7.3 Expressing a Tuple with Hash 144
7.4 Removing Tuples Safely with TupleSpaceProxy 146
7.5 Finding a Service with Ring 148
7.6 Examples of Ring Applications 155
7.7 Moving Ahead 163

8. Parallel Computing and Persistence with Rinda . . . . 165


8.1 Computing in Parallel with rinda_eval 165
8.2 Concurrency in rinda_eval 167
8.3 Persisting a Tuple with PTupleSpace 174
8.4 Moving Ahead 179

9. Drip: A Stream-Based Storage System . . . . . . 181


9.1 Introducing Drip 181
9.2 Drip Compared to Queue 182
viii • Contents

9.3 Drip Compared to Hash 187


9.4 Browsing Data with Key 190
9.5 Design Goals of the API 194
9.6 Moving Ahead 195

10. Building a Simple Search System with Drip . . . . . 197


10.1 Running the App 197
10.2 Examining Each Component 199
10.3 Crawling Interval and Synchronization with Indexer 205
10.4 Resetting Data 206
10.5 Using RBTree for Range Search 207
10.6 Adding a Web UI 213
10.7 Moving Ahead 217

Part IV — Running dRuby and Rinda in a Production Environment


11. Handling Garbage Collection . . . . . . . . 221
11.1 Dealing with GC 221
11.2 Using DRbIdConv to Prevent GC 225
11.3 Moving Ahead 227

12. Security in dRuby . . . . . . . . . . . 229


12.1 dRuby’s Attitude Toward Security 229
12.2 Accessing Remote Services via SSH Port Forwarding 234
12.3 Summary 241

Bibliography . . . . . . . . . . . . 243

Index . . . . . . . . . . . . . . 245
Foreword
In 2004, Ruby on Rails became public. The world was surprised by its pro-
ductivity and by the magic of Ruby that enabled Ruby on Rails. Many people
knew Ruby before Rails, but few realized the power of the language, especially
metaprogramming.

But Rails is not the first framework to realize the power of Ruby. dRuby came
long before Rails. It uses metaprogramming features for distributed program-
ming. Proxy objects “automagically” delegate method calls to remote objects.
You don’t have to write interface definitions in XML or any IDL. dRuby is a
good example of a very flexible system implemented by Ruby. In this sense,
Rails is a follower.

Even though dRuby has a long history, its importance hasn’t been reduced
a bit in recent years. In fact, distributed programming is getting more
important. We have access to more and more computers over the Internet.
In the “cloud” age, we should find a way to utilize those enormous numbers
of computers. And we already have the answer: dRuby.

dRuby is not known outside of Japan as much as it should be. I hope this
book helps people learn the lesser-known technology proven by history. And
you will see the power and magic of dRuby and Ruby.

Yukihiro “Matz” Matsumoto


Japan, November 2011

report erratum • discuss


Acknowledgments
For the Japanese Edition

I would like to thank the development team of Ohmsha, Ltd., for publishing
the dRuby book again; Akira Yamada, Kouhei Sutou, and Shintaro Kakutani
for reviews; and the fireflies from Houki River for encouraging me.

For the English Edition

I would like to thank Makoto Inoue for translating this book, Dave Thomas
and Susannah Pfalzer of Pragmatic Bookshelf for giving me the opportunity
to publish the English edition, Hisashi Morita and Shintaro Kakutani for
advice based on knowledge of the Japanese edition, and all the reviewers—
Eric Hodel, Ivo Balbaert, Sam Rose, Kim Shrier, Javier Collado, Brian Schau,
Tibor Simic, Stefan Turalski, Colin Yates, Leonard Chin, Elise Huard, Jesse
Rosalia, and Chad Dumler-Montplaisir.

report erratum • discuss


Preface
Stateful web servers are a core concept of dRuby. dRuby lets you pass normal
Ruby objects and call their methods across processes and networks seamless-
ly. With dRuby, you’ll experience the world of distributed computing as a
natural extension of Ruby.

The most widely used distributed system in the world is probably the Web.
It’s one of the most successful ways to distribute documents around the world
—and dRuby’s history is related to the Web. Back when Ruby was still in
version 1.1, a web server called shttpsrv was available. shttpsrv was similar
to WEBrick, but WEBrick was so innovative that Shinichiro Hara—one of the
core committers of Ruby and the author of shttpsrv—decided to ditch the
new version of shttpsrv in favor of WEBrick (which now comes as part of
Ruby’s standard libraries). But I really liked the small and cool web server
called shttpsrv, so I wrote a servlet extension for it. With this extension,
shttpsrv transformed from an ordinary web server to a special TCP server
with state. And that is how dRuby started.

This is the third edition of The dRuby Book (the previous two editions were
in Japanese). For this edition, I’ve rewritten the book to cover the latest
dRuby information and new libraries. If you are looking for theoretical defini-
tions of distributed objects or detailed comparisons of various systems, look
elsewhere! This book is full of hands-on exercises and interesting code
examples. I hope you put this book to use by writing code as you read and
discovering new things along the way.

Ruby changes your thinking process, and so does dRuby. dRuby is not just
a tool to extend a method invocation. You’ll discover new techniques, program-
ming styles, and much more as you learn how dRuby works.

dRuby will show you a side of Ruby you’ve never seen before. Let’s explore
together!

report erratum • discuss


xiv • Preface

Who This Book Is For

You’ll gain a lot from this book if you are...

• Interested in finding out about the benefits of writing apps using dRuby

• Excited by the concept of “distributed systems” such as NoSQL but think


most of the existing systems are too complicated

• Interested in client-server network programming and web programming


but are interested in a more lightweight alternative to Ruby on Rails or
Sinatra

• Interested in adding concurrent programming, such as multithreading,


messaging, and the Actor model, to your applications

You don’t need to know much about distributed systems as a prerequisite


for reading this book, but you should know the basic Ruby syntax, know the
standard Ruby classes, and be able to write some simple code.

More important, you don’t need big infrastructure to apply what you will learn
in this book. I created most of the libraries to solve problems I was having.
Because many personal computers come with multicore processors these
days, everyone can benefit from multiprocessing libraries such as dRuby.
dRuby and my other libraries will give you some basic constructs to build
tools that will make your personal computing environment flexible and pow-
erful. After reading this book, you’ll be ready to start making your own
distributed tools.

Environment

All the sample programs have been tested on OS X with Ruby 1.9.2. Some of
the code runs differently depending on your operating system (especially on
Windows machines). I’ll mention the differences as we go along.

Throughout this book, we’ll do lots of experiments using the interactive Ruby
shell (irb). When invoking irb, we pass the --prompt simple option to switch the
command prompt to a simpler version (>>). Also, we have omitted some of
the output prompts (=>) for a more concise display. Finally, you may want to
specify --noreadline if you are an OS X user and experience problems using
dRuby from irb (for more details, see OS X and readline, on page 5).

report erratum • discuss


What’s in This Book • xv

What’s in This Book

This book covers a wide range of topics related to distributed computing and
more. The main focus is on dRuby, but you’ll also find out about other libraries
I created, such as ERB, Rinda, and Drip, and how to integrate them with
dRuby. You’ll learn about some advanced Ruby techniques, such as multi-
threading, security, and garbage collection. dRuby exposes some unique
problems that you might not often encounter, so you’ll find out how to deal
with those situations too.

Chapter 1, Hello, dRuby, on page 3


The fun part starts here. We’ll launch multiple terminals and access
dRuby via irb. You’ll learn how to use dRuby and write some simple pro-
grams to explore the power of dRuby.

Chapter 2, Architectures of Distributed Systems, on page 15


You’ll learn about distributed object systems in general and how dRuby
is different from others.

Chapter 3, Integrating dRuby with eRuby, on page 31


eRuby is a templating system often used to render HTML. ERB is an
implementation of eRuby that I wrote, and it’s also part of the Ruby
standard libraries. In this chapter, I’ll explain how easily you can integrate
ERB with dRuby.

Chapter 4, Pass by Reference, Pass by Value, on page 57


Even though dRuby is a seamless extension of Ruby, there are a few dif-
ferences. In this chapter, you’ll learn two ways of exchanging objects over
processes: by reference and by value.

Chapter 5, Multithreading, on page 77


You need to know about multithreading to have a better understanding
of how dRuby works. When using dRuby, multiple processes work in
coordination with multithreading. In this chapter, you’ll learn about
threading in Ruby and how you can synchronize threads, which is
important for avoiding unexpected bugs.

Chapter 6, Coordinating Processes Using Rinda, on page 111


Linda is a system for multiple processes to coordinate with one another.
In this chapter, you’ll learn how to coordinate processes via TupleSpace
using Rinda, the Ruby implementation of Linda.

report erratum • discuss


xvi • Preface

Chapter 7, Extending Rinda, on page 137


Rinda started as a port of Linda, but I added a few extra functionalities I
thought necessary while developing applications with Rinda. You’ll also
learn about a service registration service called Ring, which comes with
Rinda.

Chapter 8, Parallel Computing and Persistence with Rinda, on page 165


After releasing Rinda, I created an extension library called more_rinda
that adds parallel computing capability and a persistence layer to Rinda.
They are not part of Ruby standard libraries but have interesting exten-
sions—with some drawbacks. I’ll explain why. If you’re interested in par-
allel computing or NoSQL, this is a chapter you shouldn’t miss.

Chapter 9, Drip: A Stream-Based Storage System, on page 181


If more_rinda is the trial and error of all my attempts at the art of distribut-
ed programming, Drip is my solution. Drip is a stream-based storage
system, with fault tolerance and a messaging system built in. I will explain
the basic usage of Drip by comparing Queue and Hash and also talk about
the design policy behind Drip.

Chapter 10, Building a Simple Search System with Drip, on page 197
We’ll create a simple desktop search system using Drip. You will experience
how you can use Drip as both a storage system and a process coordination
tool. We will also talk about the RBTree data structure we used in the search
system, which Drip uses internally.

Chapter 11, Handling Garbage Collection, on page 221


You may not need to worry about garbage collection when you use Ruby
daily, but there are a few things you have to know when you use dRuby.
Ruby has a garbage collection system that cleans up unused objects, but
this doesn’t consider how dRuby passes references across processes. In
this chapter, you’ll see how to protect dRuby referenced objects from
garbage collection and what you have to know about garbage collection
when you are building applications.

Chapter 12, Security in dRuby, on page 229


dRuby lets you communicate with other processes seamlessly, but this
also means you have to be more careful about security to prevent unin-
tended access. You’ll learn what dRuby does and doesn’t do when it comes
to security and what you have to do at the application level. I’ll also explain
how to use dRuby over networks using SSH port forwarding.

Everyone should read Chapter 1, Hello, dRuby, on page 3 and Chapter 6,


Coordinating Processes Using Rinda, on page 111 to get a basic understanding

report erratum • discuss


Conventions Used in This Book • xvii

of dRuby and Rinda. If you already use dRuby and are seeking some practical
tips, then you’ll find the following chapters packed with detailed explanations:
Chapter 4, Pass by Reference, Pass by Value, on page 57; Chapter 5, Multi-
threading, on page 77; Chapter 11, Handling Garbage Collection, on page 221;
and Chapter 12, Security in dRuby, on page 229. If you’re new to dRuby, you
might find the level of detail in these chapters overwhelming. Feel free to read
only the first section of these chapters and jump to the following chapters.
You can always refer to these chapters as a reference when you encounter
problems using dRuby.

Newly added for this English edition or greatly modified are the following
chapters: Chapter 3, Integrating dRuby with eRuby, on page 31; Chapter 8,
Parallel Computing and Persistence with Rinda, on page 165; and Chapter 9,
Drip: A Stream-Based Storage System, on page 181. They’re packed with unique
ways to use each library and also contain many new concepts.

Conventions Used in This Book

Ruby method names follow the convention of the Ruby manual. For example,
String.new represents a class method, and String#chomp represents an instance
method. The arguments are just examples, and you should add your own
arguments when working on the code.

The book’s website1 has a place to submit errata for the book and to participate
in its discussion forum. You’ll also find the source code for all the projects
we build. You can click the box before the code excerpts to download that
snippet directly.

Let’s get started!

1. http:// pragprog.com/titles/sidruby

report erratum • discuss


Part I

Introducing dRuby

Welcome to the world of dRuby. In this part, you’ll


learn dRuby’s basic concepts and architecture
through a few simple applications. You’ll see how
Ruby and dRuby make distributed programming
easy.
CHAPTER 1

Hello, dRuby
Let’s get familiar with dRuby. dRuby stands for “distributed Ruby.” It’s one
of the standard libraries that comes with the Ruby core code, and you can
use it to write distributed programming apps without the hassle of installing
and configuring additional components. In this chapter (because it’s an
unwritten rule), we’ll start with “Hello, World” and then create a small reminder
application that you can access from multiple terminals.

1.1 Hello, World

Let’s create a server that prints out strings. Then we’ll code a simple client
and use it to make the server print “Hello, World.” The client and server will
each run in a separate process (and to make that easy, we’ll run each process
from a separate terminal window).

Creating the Printing Server


puts00.rb is the puts server.

puts00.rb
Line 1 require 'drb/drb'
- class Puts
- def initialize(stream=$stdout)
- @stream = stream
5 end
-
- def puts(str)
- @stream.puts(str)
- end
10 end
- uri = ARGV.shift
- DRb.start_service(uri, Puts.new)
- puts DRb.uri
- DRb.thread.join()

report erratum • discuss


4 • Chapter 1. Hello, dRuby

Let’s go through the script:

1. On line 1, we require the drb library.

2. We create a class called Puts on line 2. This class contains the puts method
that we’ll make available to the client.

3. On line 12, we start the dRuby service. We provide the URI (which the
user passes in on the command line). The URL is the address the client
uses to connect to the server. We also provide the object that will be tied
to the URI. You’ll find out more about the URI in The dRuby URI, Services,
and Clients, on page 7.

4. A dRuby service runs in a separate thread. One of the most common


mistakes new dRuby programmers make is to forget that their program
will simply exit unless they make sure to wait until the thread stops exe-
cuting. On line 14, we use DRb.thread.join to keep the script up and running.

We’re going to use one terminal window to run the server. Let’s call it terminal
1. In that window, run puts00.rb, passing it the URI of the service.
# [Terminal 1]
% ruby puts00.rb druby://localhost:12345
druby://localhost:12345

The server process waits for the request to arrive. Make sure that the server
doesn’t terminate, even after it prints out the URI of the service.

Using the Service from irb


The next step is to write the client. Rather than writing a program file, we’ll
just use irb. Open another terminal (terminal 2) and type the following:
# [Terminal 2]
% irb
irb(main):001:0> require 'drb/drb'
=> true
irb(main):002:0> there = DRbObject.new_with_uri('druby://localhost:12345')
=> #<DRb::DRbObject: ... >

We start by requiring the drb library—the client and the server both need it.
We then create a dRuby object (of class DRbObject) by calling DRbObject.new_with_uri
(refer to OS X and readline, on page 5 if you encounter a problem getting
the prompt back), passing it the same URI we used when creating the server.
We store this object in the variable there.

Now we can use this dRuby object to access methods on the server. It’s as if
the client has access to the Puts object we created on the server.

report erratum • discuss


Hello, World •5

OS X and readline
If you use OS X and have problems getting a prompt after there = DRbObject.new_with_uri(uri),
then it may be a problem with the readline library. To work around the problem, spec-
ify --noreadline.

irb --noreadline

The OS X readline library prohibits Thread from switching, and this may be causing
problems when you use dRuby from irb.

irb(main):003:0> there.puts('Hello, World.')


=> nil

We called the puts method of the Puts server (see Figure 1, Puts server and irb
client, on page 6). You should see “Hello, World.” printed on terminal 1 where
the server is running.
% ruby puts00.rb druby://localhost:12345
druby://localhost:12345
Hello, World.

That’s pretty cool. We needed only a few lines of code to create a simple dis-
tributed server.

If you didn’t notice any difference, try other characters. Make sure you observe
the server terminal while you are typing in irb.

Back in irb on terminal 2, let’s call the server again.


# [Terminal 2]
irb(main):004:0> there.puts('R is for Ruby.')
=> nil

You should see the second message appear on terminal 1.

The there variable in the client refers to the Puts service object. By sending the
puts method to the there variable, you invoke the puts method in the server, and
it prints the object you pass to standard output.

What happens if you stop the server? Try it—type Ctrl-C on terminal 1 and
make sure you get back to a command prompt.

Now, back on terminal 2, call there.puts again.


# [Terminal 2]
irb(main):005:0> there.puts('Hello, again.')
DRb::DRbConnError: druby://localhost:12345 - #<Errno::ECONNREFUSED....

report erratum • discuss


6 • Chapter 1. Hello, dRuby

Puts
Client
puts('Hello, World.')
puts()

puts00.rb irb

Figure 1—Puts server and irb client

dRuby raised an exception. DRbConnError means that there is a communication


error between dRuby processes. The client failed to invoke the method because
the server is stopped.

Let’s start the server again in terminal 1.


# [Terminal 1]
% ruby puts00.rb druby://localhost:12345
druby://localhost:12345

Try there.puts again.


# [Terminal 2]
irb(main):006:0> there.puts('Hello, again.')
=> nil

This time, there is no exception, and you should see “Hello, again.” printed
on terminal 1.
# [Terminal 1]
% ruby puts00.rb
druby://localhost:12345
Hello, again.

Let’s stop irb for now.


# [Terminal 2]
irb(main):007:0> exit

Creating the Script Version of the Client


As a final “Hello, World” experiment, let’s rewrite this as a script.
hello00.rb
require 'drb/drb'

uri = ARGV.shift
there = DRbObject.new_with_uri(uri)
there.puts('Hello, World.')

report erratum • discuss


Building the Reminder Application •7

As you can see, this script contains most of the same code that you typed
into irb, except it gets the URI from the command line. Let’s try it. Run hello00.rb
in terminal 2.
# [Terminal 2]
% ruby hello00.rb druby://localhost:12345

You should see “Hello, World” appear on terminal 1.

So far, we’ve experimented with a simple dRuby example, and we’ve seen how
easy it is to write a client-server model script. It’s time to go a little further.

The dRuby URI, Services, and Clients


In the previous example, we used druby://localhost:12345 as a URI, but we haven’t
seen what this actually means. In this section, we’ll learn about the relation-
ship between the dRuby URI and the URI specified in DRb.start_service.

A dRuby URI defines the path to a dRuby server. It consists of the protocol
(always druby), an optional hostname, and an optional port number.
druby://[hostname]:[port number]

When you create a service (using DRb.start_service), you give it a URI. dRuby
arranges things so that clients that subsequently specify that URI will be
connected to this service. Each active DRbServer has one unique URI.
DRb.start_service(uri, front)

To connect a client to a service, pass that service’s URI to DRbObject.new_with_uri.


there = DRbObject.new_with_uri(uri)

An object that’s associated with the URI is called the front object because it
acts as an entrance to the service (see Figure 2, The front object is the gateway
to the application, on page 8). All the method calls that are created by DRbOb-
ject.new_with_uri() go to this front object. When you write an actual application,
you don’t directly associate the model object of the application; rather, you
have a proxy object that handles access control or batches multiple operations.

1.2 Building the Reminder Application

Let’s create a simple task list application in which anyone can create, read,
and delete entries. To keep it simple, the user interface is irb.

Let’s define the Reminder class first. It has three methods: Add, delete, and to_a.
Each item has a unique ID that’s used when deleting an item.

report erratum • discuss


8 • Chapter 1. Hello, dRuby

Application

foo()
bar()

Front
Client
Foo foo()
Object
Object

Bar

Figure 2—The front object is the gateway to the application.

reminder0.rb
class Reminder
def initialize
@item = {}
@serial = 0
end

def [](key)
@item[key]
end

def add(str)
@serial += 1
@item[@serial] = str
@serial
end

def delete(key)
@item.delete(key)
end

def to_a
@item.keys.sort.collect do |k|
[k, @item[k]]
end
end
end

Let’s start the Reminder server via irb. We’ll run it in terminal 1.
# [Terminal 1]
% irb --prompt simple -I . -r reminder0.rb -r drb/drb

report erratum • discuss


Building the Reminder Application •9

>> front = Reminder.new


>> DRb.start_service('druby://localhost:12345', front)
>> DRb.uri
=> "druby://localhost:12345"

Next we’ll use irb in terminal 2 as a client to this server.


# [Terminal 2]
% irb --prompt simple -r drb/drb
>> r = DRbObject.new_with_uri('druby://localhost:12345')
>> r.to_a
=> []
>> r.add('13:00 Meeting')
=> 1
>> r.add('17:00 Status report')
=> 2
>> r.add('Return DVD on Saturday')
=> 3
>> r.to_a
=> [
[1, "13:00 Meeting"],
[2, "17:00 Status report"],
[3, "Return DVD on Saturday"]
]

Let’s start another client in a third terminal session and add and delete items.
# [Terminal 3]
% irb --prompt simple -r drb/drb
>> r = DRbObject.new_with_uri('druby://localhost:12345')
>> r.to_a
=> [
[1, "13:00 Meeting"],
[2, "17:00 Status report"],
[3, "Return DVD on Saturday"]
]
>> r.delete(2)
>> r.to_a
=> [[1, "13:00 Meeting"], [3, "Return DVD on Saturday"]]
>> r.add('15:00 Status report')
>> r.to_a
=> [
[1, "13:00 Meeting"],
[3, "Return DVD on Saturday"],
[4, "15:00 Status report"]
]

The two clients are accessing the same shared data. This is because both
terminals 2 and 3 share the same Reminder object, which exists on the server
(terminal 1). The clients both have a remote reference to them (see Figure 3,
Clients at terminals 2 and 3 operate the reminder at terminal 1, on page 10).

report erratum • discuss


10 • Chapter 1. Hello, dRuby

Reminder
item
serial
add r
delete
to_a

Terminal 1 Terminal 2

Terminal 3

Figure 3—Clients at terminals 2 and 3 operate the reminder at terminal 1.

Next let’s check the object’s life span. Stop both client sessions by typing exit
at the irb prompt. Then restart the client in terminal 2.
# [Terminal 2]
% irb --prompt simple -r drb/drb
>> r = DRbObject.new_with_uri('druby://localhost:12345')
>> r.to_a
=> [
[1, "13:00 Meeting"],
[3, "Return DVD on Saturday"],
[4, "15:00 Status report"]
]

This is as we expected. The actual Reminder object exists on the server, so


quitting and restarting the clients doesn’t have any impact on the data stored
in it.

report erratum • discuss


Building the Reminder Application • 11

One of the benefits of using dRuby for your system is being able to share the
state of a object across multiple processes. You could use dRuby as an
alternative way to create persistence. For example, you could combine a short-
running Common Gateway Interface (CGI) script and a long-running dRuby
server when you write a web application.

To simplify the client operation, let’s write a ReminderCUI script. ReminderCUI is a


character-based user interface that you can use via irb. This class has a list
method to show all the items and a delete method to delete an item after
confirmation.
reminder_cui0.rb
class ReminderCUI
def initialize(reminder)
@model = reminder
end

def list
@model.to_a.each do |k, v|
puts format_item(k, v)
end
nil
end

def add(str)
@model.add(str)
end

def show(key)
puts format_item(key, @model[key])
end

def delete(key)
puts "[delete? (Y/n)]: #{@model[key]}"
if /\s*n\s*/ =~ gets
puts "canceled"
return
end
@model.delete(key)
list
end

private
def format_item(key, str)
sprintf("%3d: %s\n", key, str)
end
end

report erratum • discuss


12 • Chapter 1. Hello, dRuby

Let’s start ReminderCUI at terminal 3 and do some experimentation (see Figure


4, The ReminderCUI at terminal 3 operates the reminder at terminal 1, on page
13).
# [Terminal 3]
% irb --prompt simple -I . -r reminder_cui0.rb -r drb/drb
>> there = DRbObject.new_with_uri('druby://localhost:12345')
>> r = ReminderCUI.new(there)
>> r.list
1: 13:00 Meeting
3: Return DVD on Saturday
4: 15:00 Status report
=> nil
>> r.add('Request Ruby Hacking Guide to library')
>> r.list
1: 13:00 Meeting
3: Return DVD on Saturday
4: 15:00 Status report
5: Request Ruby Hacking Guide to library
=> nil
>> r.delete(1)
[delete? (Y/n)]: 13:00 Meeting
n # Type "n"
canceled
=> nil
>> r.delete(1)
[delete? (Y/n)]: 13:00 Meeting
y # Type "y"
3: Return DVD on saturday
4: 15:00 status report
5: Request Ruby Hacking Guide to library
=> nil

Using irb, you can create a multiclient program interface easily. We’ll add a
web interface for this in Chapter 3, Integrating dRuby with eRuby, on page
31, so hold on!

In this section, we created a simple distributed application using dRuby. By


now, you should have a pretty good idea of how dRuby works. But before we
leave this introductory chapter, let’s dig a little deeper into the URIs we’ve
been using to access our dRuby servers.

The Hostname and Port Number


The hostname and port number components of the URI are optional on the
call to DRb.start_service.

If the hostname is specified, the connection is associated with that network


interface. If omitted, TCPServer will automatically assign the hostname.

report erratum • discuss


Building the Reminder Application • 13

Reminder CUI
item model
serial add
add delete
delete list
to_a show

Terminal 1 Terminal 3

Figure 4—The ReminderCUI at terminal 3 operates the reminder at terminal 1.

If the port name is 0, the first available port will be automatically assigned.

If nil is passed instead of a URI, then it acts as if both the hostname and the
port number were omitted.

Here are some examples:

• 'druby://hostname:12345': Both are specified.


• 'druby://:12345': A hostname is omitted.
• 'druby://hostname:0': A port number is omitted.
• 'druby://:0': Both a hostname and a port number are omitted.
• nil: Both a hostname and a port number are omitted.

You can always find the host and port that were used by start_service by calling
the method DRb.uri. Let’s try this in irb.
% irb -r drb/drb
irb(main):001:0> DRb.start_service('druby://localhost:12345'); DRb.uri
=> "druby://localhost:12345"
irb(main):002:0> DRb.start_service('druby://:12346'); DRb.uri
=> "druby://yourhost:12346"
irb(main):003:0> DRb.start_service('druby://localhost:0'); DRb.uri
=> "druby://localhost:52359"
irb(main):004:0> DRb.start_service('druby://:0'); DRb.uri
=> "druby://yourhost:52360"
irb(main):005:0> DRb.start_service(nil); DRb.uri
=> "druby://yourhost:52361"
irb(main):006:0> exit

Now let’s try the “Hello, World” example without a URI. This time, use --prompt
simple to simplify the irb prompt.

report erratum • discuss


14 • Chapter 1. Hello, dRuby

Start the server in terminal 1. Don’t pass a URI to it.


# [Terminal 1]
% ruby puts00.rb
druby://yourhost:52369 # Auto generated URI

Now start the client in terminal 2, using the URI displayed by the server.
# [Terminal 2]
% irb --prompt simple -r drb/drb
>> uri = 'druby://yourhost:52369'
>> # Specify the same hostname and port number as in the terminal 1
>> there = DRbObject.new_with_uri(uri)
>> there.puts('Hello, World.')

You should see “Hello, World.” pop up on terminal 1.

When we first tried the “Hello, World” app, we used localhost as the hostname,
so we were able to run the clients on the same machine as the server. This
time, we’ve used an externally accessible name, so you can try running a
client on a separate machine that is networked with the server. Just specify
the URI of the server, the same way you did when running the client locally.

1.3 Moving Ahead

In this chapter, we learned the following:

• We can use dRuby out of the box, because it comes with Ruby. All we
need to do is require drb/drb to load the library.

• We use DRb.start_service to start a service.

• The URI identifies DRbServer.

• Each DRbServer object can associate with one object to expose it to the
public.

• Clients create reference objects by specifying the URI.

Now that we understand the basics of writing a distributed app with dRuby,
in the next chapter we’ll step back and study the concept of distributed sys-
tems in general. We’ll see how dRuby hides the complexity of these systems,
thanks to the power of Ruby.

report erratum • discuss


CHAPTER 2

Architectures of Distributed Systems


In this chapter, we’ll walk through the concept of distributed object systems
and see how dRuby fits in. First you’ll learn about distributed object systems
in general, and then you’ll see the similarities and differences between dRuby
and the other distributed object systems out there.

2.1 Understanding Distributed Object Systems

Client-server systems are among the most well-known ways to build distributed
systems or applications. A distributed object system is an enhancement of
this client-server model. It’s a library in which you can build distributed
applications using object-oriented programming.

When you write a distributed application, you have to pay special attention
to network programming. If you don’t, you may end up spending more time
dealing with network programming issues than building application logic.

Many developers have tried coming up with libraries that let you easily pro-
gram distributed applications by hiding these complex interprocess networking
protocols. Let’s take a look at the available libraries.

Remote Functions with RPC and RMI


Remote Procedure Call (RPC) is a way to call remote functions as if you were
calling local functions (see Figure 5, How RPC works, on page 16). It generates
a client stub from interface descriptions. The client stub hides network pro-
gramming logic so that you don’t have to worry about the location of the
server or how to connect.

In Figure 5, How RPC works, on page 16, the client stub converts function
calls into network communication. The “server stub” receives the communi-
cation from the client, invokes the main function, and then returns the result.

report erratum • discuss


16 • Chapter 2. Architectures of Distributed Systems

Client Process Server Process

implementation of func
calling func()
func() { ... }

y = func(x) func(x)

Client Stub Server Stub

marshalling unmarshalling

Network

Figure 5—How RPC works: Client -> Stub -> Network -> Stub -> Server

The server stub is often called the skeleton or framework. It not only executes
the incoming function request but also acts as a listener to wait for any
incoming calls.

Remote Method Invocation (RMI) is a way to extend method invocation


remotely, and the concept is very similar to RPC (see Figure 6, How RMI works,
on page 17). The main difference is how you think about the concept. RPC
“calls” remote functions, whereas RMI “sends” a message to remote objects.
RMI also provides a client stub and a server stub to hide the interprocess
communication layer. The server stub is in charge of network server program-
ming and identifies which object should receive the call.

Clients can call methods without worrying about the location of the receiver
object. You can also use the remote object reference as if it existed locally.
For example, you can set a reference of a remote object into a variable or pass
it as a method argument. The type of library where you can treat remote
objects and local objects equally is called a distributed object or a distributed
object system. A distributed object is also referred to as a remotely located
object (in contrast to a local object).

report erratum • discuss


Understanding Distributed Object Systems • 17

Client Process Server Process


Object
Method call
obj.foo(x) foo(x)

call
Object

foo(x)

Client Stub Server Stub

marshalling unmarshalling

Network

Figure 6—How RMI works: Client -> Stub -> Network -> Stub -> Server

Distributed Objects from a Programming Perspective


So far, we’ve learned the semantics of distributed systems. Let’s now think
about how these distributed systems affect our programming style.

When we write normal programs, all objects, variables, and methods are allo-
cated inside one process space. Each process area is protected by the operating
system (OS), and they can’t access each other (see Figure 7, Location of objects
and processes for a normal system, on page 18).

In a distributed object system, we treat other processes or objects in other


machines as if they were in the same process space (see Figure 8, Location
of objects and processes within a distributed object systems, on page 19).

How local processes and remote processes behave differently depends on their
implementation. For example, some systems may be able to pass remote
objects into arguments or return remote objects, but others may not. Some
systems may require you to take extra steps when local objects communicate
with remote objects.

report erratum • discuss


18 • Chapter 2. Architectures of Distributed Systems

Process 1 Process 2

code code

text text

object object

data data

object object

object object

Cannot access
stack across processes stack
Can access

object object

object object

heap heap

Figure 7—Location of objects and processes for a normal system. Objects can’t access
each other across processes.

Furthermore, there are often differences between “objects” in distributed


systems and “objects” in programming languages. The smaller the difference
is, the more seamless it will be to switch between programming languages.

The Popular Distributed Object Systems


Distributed Component Object Model (DCOM), Common Object Request
Broker Architecture (CORBA), and Java RMI are widely known, and of course
dRuby is also a distributed object system.

While Java RMI and dRuby are tightly coupled with their hosting languages,
DCOM and CORBA are language-independent systems. C++, Java, and non-
OOP languages such as C can use them.

DCOM, CORBA, and Java RMI require us to define the interface for stub
generation because they are statically typed languages. For example, DCOM

report erratum • discuss


Understanding Distributed Object Systems • 19

Distributed Object System

Process 1 Process 2

code code

text text

object object

data data

object object

object object

Can access
stack across stack
Can processes
access

object object

object object

heap heap

Figure 8—Location of objects and processes within a distributed object systems. Objects
can access each other across processes.

and CORBA require us to write an interface using a language called Interactive


Data Language (IDL); see Figure 9, Writing interfaces using IDL, on page 20.
Once we generate stubs from IDL, we need to link them to all the clients that
may use these remote objects in advance.

Dynamically typed languages, such as Cocoa/Objective-C and dRuby, don’t


need IDL because methods are linked at execution time. We also don’t need
to link to the stub of every single class. Instead, we link to only one class for
the client and one for the server. This sounds so easy compared to statically
typed languages, but you need to be aware of one thing. When you want to
copy an object of unknown remote class (rather than just calling remote
methods), then the class definition of the remote object must exist locally.

report erratum • discuss


20 • Chapter 2. Architectures of Distributed Systems

IDL

Generated by IDL

Client Stub Server Stub

Link Link

Client Server
App App

Figure 9—Writing interfaces using IDL

Your programming style becomes very different between a system that needs
to know the interface in advance and a system that doesn’t need to know it.

So far, we’ve seen the different flavors of distributed systems in other lan-
guages. Some are language dependent, and others aren’t. Also, distributed
systems in statically typed languages tend to require the interface of remote
objects to be defined as IDL, while dynamic languages don’t. Next, let’s see
how dRuby fits into this distributed system paradigm.

2.2 Design Principles of dRuby

I designed dRuby to extend Ruby method invocation over networks. dRuby


is a library to implement distributed objects in Ruby.

dRuby has the following characteristics:

• Limited to Ruby
• 100 percent written in Ruby
• No IDL required

Let’s look at these concepts a little more closely.

report erratum • discuss


Design Principles of dRuby • 21

Application

dRuby

Ruby

POSIX Windows Mac OS X

Figure 10—The software layers. Observe where dRuby sits above the operating systems.

Pure Ruby
dRuby is a distributed object system purely targeted to Ruby. It sounds lim-
iting, but this also means you can run dRuby in any environment where Ruby
can run (see Figure 10, The software layers, on page 21). This is very similar
to Java RMI, which also can run anywhere Java can run.

Figure 11, An example of a system across multiple OSs, on page 22 shows the
architecture of a complex system across different operating systems.

dRuby is written purely in Ruby without using any C extension libraries—


another bonus. Ruby comes with network, thread, and marshaling-related
libraries as part of its standard library, so I was able to write everything in
Ruby. The first version of dRuby had only 160 lines (the current dRuby has
more than 1,700 lines including RDoc), and the core part of the library is still
the same (see The First dRuby, on page 23). The concise codebase of dRuby
demonstrates how easily you can write a complex library by using just Ruby’s
standard libraries.

Feels Like Ruby


I paid special attention to the compatibility between dRuby and Ruby. Many
features of Ruby remain in dRuby, too.

Ruby is very dynamic. You don’t need to use inheritance most of the time
because the variables of Ruby aren’t typed. Ruby looks up methods at execu-
tion time (method invocation time); these characteristics also apply to dRuby.
dRuby doesn’t have type-in variables, and method searches are done at exe-
cution time. Because you don’t need to prepare the list of methods and their
inheritance information, you don’t need to write IDL.

report erratum • discuss


22 • Chapter 2. Architectures of Distributed Systems

WEBrick Div Div

RWiki Div

Ring Dip

POSIX Windows Mac OS X

Figure 11—An example of a system across multiple OSs. Div, Ring, Dip, and RWiki are
applications that use dRuby.

dRuby’s core mission isn’t about changing the behavior of Ruby, apart from
extending Ruby method invocation across networks. With this functionality,
you can have as much ease and fun programming in dRuby as you do with
Ruby. For example, you can still use a block for method calls and use
exceptions as well. Other multithreading synchronization methods, such as
Mutex and Queue, are also available remotely, and you can use them to
synchronize multiple processes.

Pass by Reference, Pass by Value


Having said all that, sometimes you need to know the difference between
Ruby and dRuby.

In Ruby, objects are all exchanged by reference when you pass or receive
method arguments, return values, or exceptions.

In dRuby, objects are exchanged either by reference or by the copy of the


original value. When an object is passed by reference, the operation to the
object will affect the original (like a normal Ruby object). However, when
passed by value, the operation doesn’t affect the original, and the change
stays within the process where the object is modified (see Figure 12, Passing
by reference and passing by value, on page 24).

This difference doesn’t exist in Ruby, and you have to pay special attention
to this when you program with dRuby.

If I really wanted to make dRuby look the same as Ruby, I could have designed
dRuby to always pass by reference. However, remote object method invocation
requires some network overhead, and doing small object operations all via

report erratum • discuss


Design Principles of dRuby • 23

The First dRuby


The first version of dRuby was created in 1999 and posted to the Japanese Ruby user
mailing list.a The email is written in Japanese, but you can see some snippets of
source code that look very similar to dRuby now.

# Starting drb server.


DRb.start_server('druby://hostname:port', front)
# Connecting to the remote server
ro = DRbObject.new(nil, 'druby://server:port')
ro.sample(1, DRbEx.new(2), 3)

The original source code is about 160 lines, and about 50 lines of the core code will
give you clear idea about how dRuby works internally.

class DRbObject
def initialize(obj, uri=nil)
@uri = uri || DRb.uri
@ref = obj.id if obj
end
def method_missing(msg_id, *a)
succ, result = DRbConn.new(@uri).send_message(self, msg_id, *a)
raise result if ! succ
result
end

attr :ref
end

DRbObject acts as a proxy object, so it doesn’t have any methods. Therefore,


method_missing receives all the method calls and sends them to the DRbConn class.

class DRbConn
include DRbProtocol

def initialize(remote_uri)
@host, @port = parse_uri(remote_uri)
end
def send_message(ref, msg_id, *arg)
begin
soc = TCPSocket.open(@host, @port)
send_request(soc, ref, msg_id, *arg)
recv_reply(soc)
ensure
soc.close if soc
end
end
end

DRbConn acts as a TCPSocket server. It transfers the message to the remote server—so
simple. If you’re interested in the internals of dRuby, read the rest of the original code
to get a better idea about the structure of the library before jumping into reading the
current version of dRuby, which is more than 1,700 lines.

a. http:// blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/15406

report erratum • discuss


24 • Chapter 2. Architectures of Distributed Systems

To pass object "Foo"...

Foo
@foo Reference information
foo Location and id of original
foo=(obj)
dup

Pass by Reference

Foo Foo
@foo @foo
foo foo
foo=(obj) foo=(obj)
dup dup

Clone
Copy of the original
No impact on the original

Pass by Value

Figure 12—Passing by reference and passing by value

RMI isn’t effective. It’s vital to pass the copy of the object in certain situations
to increase your application’s performance. Also, if you keep passing by refer-
ence, you’ll never get the actual value from the remote server. Instead, you’ll
be looping forever, trying to find out the object’s state.

It might sound a bit complicated, but don’t worry. You don’t have to specify
whether you plan to pass by value or by reference—dRuby does it for you.
Because dRuby automatically selects the reference method, you don’t have
to write a special method for dRuby.

You’ll see more detail about automatically passing by value or by reference


in Chapter 4, Pass by Reference, Pass by Value, on page 57.

2.3 dRuby in the Real World

With dRuby, you can create distributed systems as if you were doing normal
Ruby programming, which helps you turn your ideas for complex distributed
systems into working applications quickly. dRuby offers a generic way to
achieve RMI. Some people use dRuby to sketch their initial system and then

report erratum • discuss


dRuby in the Real World • 25

swap with more specialized middleware as their systems grow. For inspiration,
the following are some real-world examples of dRuby systems.

Hatena Screen Shot


Hatena1 is Japan’s leading Web 2.0 company and provides various services,
such as a blogging system and a social bookmark system. Hatena used to
provide a service called Hatena Screen Shot, which generates a screenshot
of a given URL and provides it as a thumbnail. The architecture of this service
was unique because it consisted of different operating systems. The web
frontend was built on Linux, and the screen-capturing component was built
with a Windows Internet Explorer component. This is a good example of
integrating a cross-platform system using dRuby. The system was also
architected to be able to run screen-capturing services in parallel so that the
component could scale horizontally by simply adding more Windows machines.

Twitter
Twitter used dRuby and Rinda before it built its own queuing system called
Starling in Ruby (until the system was replaced by another in-house system
written in Scala). At SDForum Silicon Valley Ruby Conference 2007, Blaine
Cooke presented a talk called “Scaling Twitter.”2 In the presentation, Cooke
mentioned dRuby as “stupid easy and reasonably fast” (though he also
described it as “kinda flaky”).

Buzztter
Buzztter3 is a web service to analyze tweets from Twitter, which extracts
trending keywords. The service started in 2007, before Twitter started its own
“Trending Topics.” The service still provides a useful way to extract topics
from Japanese tweets because Japanese sentences don’t have word separation
and are therefore harder to analyze. Buzztter consists of multiple subsystems,
and it used Rinda (Chapter 6, Coordinating Processes Using Rinda, on page
111) as middleware to consume tweets from Twitter’s REST API. The system
used Rinda for two years, eventually replacing it with RabbitMQ4 in 2009. In
November 2007, Rinda handled 125,000 tweets (72MB) a day.

1. http:// www.hatena.ne.jp
2. Slide: http:// www.slideshare.net/Blaine/scaling-twitter, video: http:// video.google.com/videoplay?docid=-
7846959339830379167
3. http:// buzztter.com
4. http:// www.rabbitmq.com

report erratum • discuss


26 • Chapter 2. Architectures of Distributed Systems

RWiki
RWiki is a wiki system written with dRuby and still actively used in my
workplace. It’s been running for more than ten years, and the system stores
more than 40,000 pages in memory (more than 1GB). RWiki doesn’t use an
RDBMS but logs pages in plain text. RWiki persists the data by recovering
the log when the system restarts. RWiki uses Ruby Document (RD) as a doc-
ument format. Once you write your wiki page, the page is stored as a Ruby
object, and you can retrieve the content of the page (not just the entire source
but also various components, such as chapters, sections, links, incoming
links, and other customized attributes) via method invocations. RWiki acts
as a wiki via HTTP but acts as an object database via dRuby. We use the
object database in several ways. For example, we’ve been using agile
methodologies for years, and we store user stories5 and request tickets in the
RWiki. Then we connect to RWiki pages via dRuby from a separate process
to automatically generate TestSuite or aggregate statistical information of all
the request tickets.

Libraries
Many libraries use dRuby to take advantage of its interprocess communication
capability. Here are some examples:

god
https://github.com/mojombo/god: Process monitoring system.

RSpec
http://rspec.info/rails/runners.html: Testing framework. With the --drb option, you
can speed up tests by preloading the entire Rails app.

BackgrounDRb
http://backgroundrb.rubyforge.org: Job server and scheduler. This tool off-loads
longer-running tasks from the Ruby on Rails application.

They are all open source and good examples to study for how to use dRuby
in various ways.

2.4 Moving Ahead

In this chapter, we learned about distributed object systems in general and


then compared dRuby with other systems. You’ll find that dRuby hides most
of the complexity of building distributed systems so that you can write a

5. http:// www.extremeprogramming.org/rules/userstories.html

report erratum • discuss


Moving Ahead • 27

distributed program as an extension of normal Ruby programming. Having


said that, there are a few differences to bear in mind, especially how to pass
Ruby objects.

In the next chapter, I’ll introduce another library I wrote called ERB. ERB is
a template library that we’ll use to add a web interface to the Reminder app we
created in Chapter 1, Hello, dRuby, on page 3.

report erratum • discuss


Part II

Understanding dRuby

In this part, you’ll integrate dRuby with other com-


ponents to make more complex applications.
Through various exercises, you’ll learn what you
need to consider when communicating with multiple
processes.
CHAPTER 3

Integrating dRuby with eRuby


In this chapter, you’ll learn how to integrate dRuby into ERB, an implemen-
tation of the eRuby templating library. eRuby is a templating system used to
embed Ruby scripts into documents; it’s handy for creating templates or
rendering web pages and is an excellent companion to dRuby. We’ll first learn
the basics of eRuby and ERB, and we’ll then work through some examples
to integrate them with the Reminder dRuby script we created in Chapter 1,
Hello, dRuby, on page 3.

You may already be familiar with ERB through web frameworks such as Rails;
I’ll show you some cool ways of using ERB with dRuby.

3.1 Generating Templates with ERB

You probably see lots of templates from day to day, used for things such as
bills, meeting agendas, HTML, and domain-specific languages (DSLs) such
as program generators.

In this chapter, we’ll learn various ways to generate templates using ERB.

Let’s look at a sample email first.


-----------------------------------------
Qty Item
Shipping Status
-----------------------------------------
1 Recollections of erb
- Shipped June 22, 2008
1 Great BigTable and my toys
- Shipped July 18, 2009
1 The last decade of RWiki and lazy me
- Just shipped
-----------------------------------------

report erratum • discuss


32 • Chapter 3. Integrating dRuby with eRuby

You can print the receipt and check the status of this
order (and any of your other orders) online by visiting
your account at http://www.druby.org/m_seki

http://www.druby.org

If we want to turn the preceding example into a reusable template, we can


combine String concatenation and a String literal, as follows:
shipping_notify_pre.rb
class ShippingNotify

def initialize
@account = ''
@customer = ''
@items = []
end
attr_accessor :account, :customer, :items

def to_s
str = <<EOS
Dear #{customer}

This note is just to let you know that we've shipped


some items that you ordered.

-----------------------------------------
Qty Item
Shipping Status
-----------------------------------------
EOS
items.each do |qty, item, shipped|
if shipped == Date.today
status = 'Just shipped'
elsif shipped < Date.today
status = 'Shipped ' + shipped.strftime("%B %d, %Y")
else
status = 'NA'
end
str << "#{qty} #{item}\n"
str << " - #{status}\n"
end
str << <<EOS
-----------------------------------------

You can print the receipt and check the status of this
order (and any of your other orders) online by visiting
Your Acount at http://www.druby.org/#{account}

http://www.druby.org
EOS

report erratum • discuss


Generating Templates with ERB • 33

return str
end
end

if __FILE__ == $0
greetings = ShippingNotify.new

greetings.account = 'm_seki'
greetings.customer = 'Masatoshi SEKI'
items = [[1, 'Recollections of erb', Date.new(2008, 6, 22)],
[1, 'Great BigTable and my toys', Date.new(2009, 7, 18)],
[1, 'The last decade of RWiki and lazy me', Date.today]]
greetings.items = items

puts greetings.to_s
end

As you can see, lots of string literals are scattered across the script. There
are two problems with embedding the partial templates into a script: it’s hard
to read, and it’s hard to exchange scattered templates.

Many templating languages take an opposite approach. Rather than embedding


documents into scripts, they embed scripts into documents, which is the
approach eRuby takes.

eRuby is a templating system for embedding Ruby script into text files, and
ERB is a Ruby library to write eRuby. There is also an “eruby” library imple-
mented in C, but ERB is the one included in the Ruby standard libraries.

You can use eRuby not just to print out HTML but also to print out any text
files (however, it won’t detect invalid HTML files).

Here’s how to embed a Ruby script:

<% ... %>


Execute the Ruby script.

<%= ... %>


Embed the result after evaluating the statement.

Other characters
Embed to strings as they are.

Not only can you use the result of the statement, but you can also control
flow and iterations. Let’s rewrite the previous example using ERB. The follow-
ing example splits the previous example into two programs. shipping_notify.erb
is a template, and shipping_notify2.rb has all the data and logic.

report erratum • discuss


Exploring the Variety of Random
Documents with Different Content
CHAPTER II
EARLY WORK IN LONDON
1851—APRIL, 1856

Through all the bright and free life at Finchley, Mrs. Hill had never forgotten
that her daughters would have to earn their living. Miranda, indeed, at the age of
thirteen, had begun to earn as a pupil teacher in the private school of a friend; and
her sister Margaret mentions in a letter the characteristic fact that Miranda had
wished to give some of her first earnings to her half-sisters, who were starting a
school. When, then, these sisters realised that Mrs. Hill was considering Octavia’s
future work, they, in their turn, offered to give her a free education, as a start in
life. On the other hand, Octavia’s artistic talent had already attracted the attention
of Mrs. Hill’s friend, Miss Margaret Gillies; and she offered to train Octavia in her
studio. Both these offers attracted Octavia herself; but Mrs. Hill did not wish to
part with her. Whilst she was still hesitating, her attention was drawn to the notice
of an Exhibition, to be held at 4 Russell Place, Fitzroy Square, of special
preparations of painted glass, consolidated so as to make it suitable for tables and
other purposes. She found that Miss Wallace, the patentee, was promoting the
Exhibition, partly to secure work for some Polish exiles, in whom she was
interested, partly with the more general aim of finding regular suitable paying
employment for ladies.
Mrs. Hill mentions that her first thought was that Miranda, whose overflowing
fancy seemed to her dangerously unpractical, might be roused to more steady work
by such an occupation as this. But it was natural that it soon occurred to her that
Octavia’s admitted artistic talent might also be utilised in this way. So she applied
for admission for both her daughters to this work. But, as Miss Wallace was unable
to carry on the business, Mr. Vansittart Neale most generously came forward with
the capital, in order to carry it on on a co-operative basis. He asked Mrs. Hill to
become the manager, which she very gladly consented to do, as she was much
interested in co-operation and in the employment of women.
Such was Octavia’s first introduction to London. The change from the healthy
open-air life at Finchley, and from the beauty of the country, to the ugliness of her
new surroundings told heavily on her spirits; and this depression was increased by
the sudden sense of the evil and misery in the world. Among the workers at the
Guild was a Miss Joanna Graham, who rapidly became a warm friend of Miranda’s.
She introduced both sisters to the “London Labour and the London Poor,” then
just brought out by Mayhew; also to the pamphlets and other essays written by the
Christian Socialist leaders of the movement with which Mr. Neale had already
brought them into contact. The pictures given by Mayhew of the life of the London
poor, and the desire awakened by the Christian Socialists to struggle against evils,
which seemed to her irresistible, produced in Octavia such a state of mind that she
began to think that all laughter or amusement was wicked. Miranda, always able to
see the humorous side of a question, tried to laugh her out of this extreme
depression; and, when Octavia persisted, the elder sister composed an imaginary
epitaph on herself, supposed to be written by Octavia:

“Her foibles were many, her virtues were few;


And the more that she laughed, the more stern the world grew.”

This produced a most startling letter of stern remonstrance from Octavia; so stern
that one is relieved to find it closed by a loving message and followed by a P.S.
“Love to all. Thank you for the apples.”
Of course, this extreme gloom, unnatural in any young girl, was especially out of
keeping with anyone of Octavia’s buoyant temperament, and the happy busy life at
the Ladies’ Guild soon had its effect.
THE LADIES’ The following account given by Mrs. Hill in April,
GUILD 1856, shows somewhat of the social life. “The ladies
used to go to lectures together. In this case, the subject
of the lecture became, next day, that of the conversation in the workroom. The
conversation in general fell on interesting subjects, the favourite subjects being
politics, religion, art, news, the country and its scenery, poverty and wages, etc. A
very favourite subject was the derivation and definition of words; then the ladies
would join their voices in chorus, taking different parts. Indeed a merrier
company, ‘within the limits of becoming mirth,’ the writer never chanced to see.
There was generally some joke in hand. In the winter, they often assembled in the
evening at the Guild. Sometimes they drank tea together, and afterwards sang and
danced joyously.”
The artistic work at the Guild brought Octavia into contact with the Rogers
family. Mr. G. Rogers was wood carver to the Queen, and produced some very
interesting work. All his family had artistic leanings; but it was his daughter, who is
best known by her writings on Palestine, who specially attracted Octavia, and for
whom she formed one of those enthusiastic friendships which exercised so marked
an influence on her life. A younger friend, whose name was afterwards to be so
closely associated with Octavia’s, was Miss Emma Cons. She, like Octavia, was
much interested in art; and, on the other hand, her high girlish spirits called out in
Octavia again the old love of exercise and fun that had shown itself so strongly in
the Finchley days. Indeed Miss Cons was so much given to romps that Octavia’s
fellow workers (including her sisters) were rather startled at the attraction which
her new friend had for her. But it is clear from the letters, produced here, that
Octavia saw the real power concealed for the time under these hoydenish ways;
and she marked her as one on whom she could rely, and from whom she expected
much.
But it must not be forgotten that among the most important of these influences,
then at work on Octavia, were the characters and teaching of the Christian Socialist
leaders. Soon after joining the Guild she had begun to attend the lectures at the
Hall of Association; and her attendance at Lincoln’s Inn Chapel brought her in
1852 under the influence of my father, Rev. F. D. Maurice. She and Emily attended
the daily morning service; and, after a time, my father used often to let them walk
back with him, and he would answer many of Octavia’s difficulties about religious
and social questions. On one occasion she asked him if it would not be very nice if
one could get rid of all responsibility. He laughed and said it would indeed be very
comfortable. But that she did not shirk responsibility is shown by the following
incident. It was in the early days of the Guild, when Octavia was only about
fourteen, that she was alone in the house with the exception of Mrs. Horne,[5] who
was at the top of the house. It was Sunday; and everyone else had gone to Church.
On coming out of a second-floor room she saw a man standing near the door of a
large cupboard, in which she supposed he must have hidden. “How did you come
up here?” she asked. “I came up the stairs,” replied the man. “Then you will please
to walk down again,” said Octavia in a quiet tone. He obeyed her, and she walked
behind him down three long flights of stairs, and saw him out at the front door.
Her sense of responsibility was the greater because some money, belonging to the
Guild, had been paid late on Saturday and was in the office.
After the Guild had been carried on for some time, Mr. Neale was asked to take
over a new kind of work, which a lady had started in order to employ some Ragged
School children. This was the making of a special kind of toy which she had
invented; and Mr. Neale appointed Octavia head of the workroom. The following
account is given by my wife and her sister Miranda. The management of the toy-
making helped to “develop Octavia’s business faculties. She had to pass the
children’s work, which was paid by the piece, to assign the various processes to
each child, to choose the shapes and colours of the toy furniture, to price it, and to
see that, when the suites were finished, they were neatly packed in boxes and sent
over to the show room, where the ladies’ glass work was also exhibited. From time
to time she had to take stock, and to see if the sales justified the expenditure.
TOY-WORKERS “Her daily intercourse with the girls taught her to
know intimately the life of the poor. Most of the
children came from very poor homes, and had, though so young, experienced great
hardships. There was Louisa, an emotional, affectionate girl who had lost both
parents, and helped to support herself and the aunt with whom she lived. She had
worked at artificial flower-making, and told us how, when trade was busy, she had
been kept late into the night, and had had to run frightened through the streets in
the small hours of the morning, and tap at the window to wake her aunt. There was
poor Denis whose face and neck were terribly disfigured with burns; but who had
such a sweet pathetic voice that, when she sang, one forgot her ugliness. There was
Clara, a tall, over-grown girl from a dirty home, who was half-starved and cruelly
treated. She wore a low dress and short sleeves, and one could see her bones
almost coming through her skin. On one occasion when her work was too slovenly
to be passed, she burst into tears, and said that her mother would beat her if she
did not take back the money expected of her. There was little Elizabeth, a stunted
child of about nine, with so fierce a look that Octavia, in loving raillery, called her
her little wild beast. She had never come with us on the Saturday-afternoon walks
to Hampstead, but used to look wistfully after us. Once we pressed her very much
to come, and then she exclaimed ‘I cannot, I have to nurse the baby.’
“Another child was R. who was lost sight of, and later on was found in a dark
cellar into which one descended by a ladder, where she sat all day to sell
pennyworths of coal. She was half-starved and unkindly treated, but she seemed to
take that as a matter of course; what she did resent was that her cat was starved.
Later on Octavia sent her to an Industrial School; and after some years she
emigrated, and wrote to tell of her happy married life.
“Harriet and her sister were of a higher class, and had a clean, respectable home.
They were earnest Methodists. We lost sight of Harriet for forty years, and then
found her very happily married. She had remembered Octavia with the deepest
affection, and had preserved all her letters.
“The girls were in the habit of bringing their dinners to eat in the workroom, and
what they brought was very poor fare. Octavia suggested that they should club
together to buy their food, and that each girl in turn should cook it. The long table
was cleared, and a white cloth laid, and the food served nicely. Octavia brought
over her own luncheon to eat with the girls, and, after the Grace had been sung, it
was a pretty sight to see the sad, careworn faces of the children light up, as they sat
round the table while she talked to them. Among other things, she learnt to scrub
the floor, in order to teach the children to keep the workroom clean.
“A good many of the girls were older than Octavia and inclined to be
insubordinate, but she very soon established order, and that without recourse to
punishment. The girls had been accustomed to be fined for offences, and they were
quite amazed when they found this was no longer the case. On one occasion they
refused to scrub the work-tables, which was part of their daily duty. Immediately
Octavia and her two younger sisters set to work to do the scrubbing, and soon the
girls gave in. They had been fined for swearing, but the swearing soon ceased, and
they sang hymns or nice songs. Octavia was their leader and companion in all that
they did, and this sharing in their work, and yet leading the way, won them all to
obey as well as to love her. Sometimes, on a Saturday afternoon, she would take
her little group of workers for a walk to Hampstead Heath or Bishop’s Wood. Her
sister Gertrude remembers walking in Highgate Lane on a spring afternoon with
Professor Owen, who was quietly explaining something about the mosses on Lord
Mansfield’s fence—all being very still—when, to her surprise, the hedge was broken
open, and, with a burst of joy, who should leap down from the bank with a staff in
her hand and a straw hat torn by the thicket but Octavia, followed by a troop of
ragged toy-workers, happy and flushed, each with a lap full of blue-bells. Octavia
stayed for a minute to speak to her sister and the Professor; then off they all went
back into the wood and away towards Finchley.
“Schools were not what they are now, and Octavia was amazed at the ignorance
of these girls. They quite believed that wolves and bears might be lurking in the
woods; and they did not know the names of any of the flowers. It was afterwards
arranged that Miranda should give the girls lessons for an hour or so each
afternoon.”[6]
In 1854 Dr. Southwood Smith left Hillside and moved to Weybridge, where his
grandchildren were always welcomed in the same loving way that they had been at
Highgate.
But, before he could move, he was seized with a severe illness which necessitated
an operation. A few weeks later his granddaughter Emily was attacked by scarlet
fever, and her life was despaired of by two doctors. Then her grandfather, in spite
of his weak state, came back to London, and saved her life; and when she could be
removed, took her to Weybridge to watch over her convalescence. This of course
withdrew her from the toy work, and threw more of the burden on Octavia. A year
later her youngest sister Florence was also withdrawn from the work by ill-health,
and taken to Italy by her aunt, Miss Emily Smith, who gave her loving care for six
years. It was in the summer of 1855 that an expedition of the toy-workers into the
country led to the formation of some important friendships. Mrs. Harrison, to
whose house at Romford they were invited, was the sister of Mrs. Howitt, and she
and her family became warm friends of Octavia’s. Some of the letters given further
on were written to Mary, the eldest daughter, who was very artistic.
EARLY But even more important was the friendship then
FRIENDSHIPS formed with Miss Mary Harris, a member of the Society
of Friends, who was a great deal older than Octavia, and
whose calm, loving nature was a great rest to her. From the time they first met till
1893, when Miss Harris died, Octavia poured out more of her secret thoughts to
her than to anyone else, and when they were away from each other wrote to her
constantly.
On the occasion of this visit to Romford another guest was Mr. Ellis Yarnall, the
American, whose letters to Lord Coleridge have lately been published. He recorded
in his diary the following description of Miranda and Octavia.
“Some young ladies were expected, and with them about twenty children, girls to
whom they are teaching some decorative arts. The children played in the grounds;
the young ladies (Miranda and Octavia) were with us at luncheon; and we had a
great deal of talk about Mr. Ruskin, who is a friend of theirs. They described his
eloquence as a speaker, his earnestness of manner, his changing countenance, even
when he was silent, as though thoughts grave and gay were passing through his
mind. It was plain to me that his strong intellect and bright fancy were having their
true influence on these young persons, themselves highly gifted and altogether
like-minded, eighteen and sixteen or thereabouts—sisters. I was astonished at the
strength of intellect which they displayed. The talk of the elder one especially was, I
think, more striking than that of any person of her age I ever knew. She reminded
me of Corinne and other women of renown. What a pleasure it was to look at her
fine face with the glow of enthusiasm upon it, and to wonder whether gifts like hers
would not one day produce fruits which the world would value. Her description of
the effect which the hearing of Beethoven’s music on some late occasion had had
upon her was an utterance of passionate feeling showing true poetic susceptibility.
“They are the granddaughters of Dr. Southwood Smith.”

Towards the end of 1855 an important event took place, which led to Mrs. Hill’s
withdrawal from the Ladies’ Guild. My father had been interested in Octavia’s
work for the Toy-workers, and offered to take a Bible Class for them. The
Theological Essays controversy was just then at burning point; and the ladies who
had handed over the business part of the toy work, still considered that they had a
right to interfere about the religious instruction of the children. These ladies were
very Evangelical (as Evangelicalism went in those days) and they threatened to
withdraw all pecuniary help and the support of the Ragged School Union, if my
father was allowed to teach the girls. The managers of the business were so much
alarmed at this threat that they asked my father to withdraw his offer. Mrs. Hill
and her daughters were naturally very indignant at this; and Mrs. Hill’s protests
led to her losing the post of Manager at the Guild. She and Emily went to
Weybridge. Miranda and Octavia continued to work for a time; but when it seemed
likely that the Guild would fail, Miranda obtained daily teaching and Octavia
applied to Ruskin to learn from him if there would be any chance of her supporting
herself by painting. He replied most kindly, and asked her to let him have a table-
top designed and painted by herself. This design[7] was a spray of bramble leaves in
all their brilliant autumn colours, encircling the centre space which formed a
background that was dark at one part and gradually grew lighter, and finally
changed into soft blue, suggesting storm clouds passing away, and leaving a bright
sky. Round the edge, among the leaves, were the words of the Psalm, “He brought
them out of darkness and out of the shadow of death, and brake their bonds in
sunder.”
This led to Ruskin’s undertaking to train Octavia and give her work. Soon after
this came the final crisis at the Guild; and Octavia obtained the appointment
mentioned in the last letter of this chapter.
EARLY WORK IN
LONDON
June 14th, 1852.

To Miranda.

Thank you many many times for your sweet letter. It was such a
comfort to me.
I am very well indeed now. I do not know when I have been better,
except that I am rather weak. I am at Finchley with Minnie. I long
dreadfully to go to town; but I think I can wait patiently till
Wednesday.
I have been very unfortunate in being away from the Guild just at
this time. Do you know Mr. Walter Cooper has been there? and Mr.
Lewis and the trustees (Mr. Furnivall) go there so often; and all the
bustle, and trying to feel Christian-like to Mr. and Miss ——. O,
would it not have been delightful!
I have Miss Graham’s books here; they are so interesting. I am so
very happy when I am reading them. My interest gets deeper and
stronger every day. I wish, oh! I so long, to do something, and I
cannot. Andy! do you think I ever shall be able to do anything really
useful?
I do not at all like Mr. ——, or rather I entirely despise and dislike
his opinions. I will tell you all about it when I see you. I will only tell
you now that he likes “the subordination of the employed to the
employer”; and he thinks “there is no tribunal so proper as the
discretion of the employer to decide those delicate questions of the
personal conduct of the employed.” Did you ever hear of such a
thing? Is it not horrible?
Mr. Furnivall I admire more and more the more I know and read
of him; and, as to Mr. Ludlow, certainly there is not (excepting Mr.
Furnivall) such a person in the whole world. He has the largest,
clearest, best-balanced mind joined to the truest most earnest wish
to help the working classes I ever met with (of course excepting Mr.
Furnivall’s).
I have read to-day his “Christian Socialism and its Opponents.” All
I can say of it, and all he writes is that it is grand, and that I never
can forget it, or cease to be grateful for it. His lectures have sunk
deeper into my heart than anything else; one reason is, I dare say,
that they were the first; but they were most noble and grand; his own
great soul seemed to breathe itself into his works. But I forget—I
shall get no sympathy from you. I must tell Miss Graham. Andy, do
you think Mr. Furnivall will bring him to the Guild? Do you think he
meant it; or, if not, do you think we ever shall know him?
The Festival will be on Monday. I am looking forward to it with
such pleasure. I do so long to see you; it seems ages since I did; I
want to know what you think about the ‘Guild’; I do so want your
advice, too, upon a thousand subjects. I have a good deal to read to
you, which I have written since you were away. Give my dearest love
to Miss Graham. Tell her I never can thank her enough for all the
noble and beautiful books she has lent me; that, as to the Christian
Socialist, I never never before read anything which inspired such
earnest longing to do something for the cause of association; and it
interested me so very much that the hours I have spent in reading
that are never to be forgotten; they were unequalled in pleasure to
any that I have ever spent in reading; and that, if I live years and
years, I shall never forget, or cease to remember with gratitude that it
was to her that I owe the great happiness of first reading a Socialist
book, which I consider one of the greatest happinesses any one can
have. Thank her, also, for the other books; tell her the “Cheap
Clothes and Nasty” and “Labour and the Poor” are some of the most
dreadful things I ever read. They have made a deep impression on
me. How delightful the History of the Working Tailors’ Association
is!
Do you know I have a post at the Guild? I have to give out the
stores and am responsible for them. The ladies have all sent me a
book as a testimony of their gratitude to me for reading to them.
How very kind it is of them! Dear Laura has written me such a sweet
letter. I love to think of you among those lovely scenes by the
beautiful sea, with dear Miss Graham....
Your own loving little sister, Ockey.

I am sadly afraid the Journal[8] will stop at Midsummer. What is to


become of me???

Ladies’ Guild,
July 27th, 1852.

Miranda to Joanna Graham,


We all declare that we have never spent a more glorious evening. I
think I never saw such a face as Mr. Kingsley’s. That face was the
chief pleasure of all, though there was a most splendid collection of
people there. We went a party of six, Ockey, Mama, Mary, I, Mr.
Rogers, and Miss Cons. We met Walter Cooper at the door, and he
was very kind and seemed glad to see us. The Hall was very crowded
but he got seats for us. Mama and I were together. We looked round
and got glimpses of the Promoters.[9] Mary fixed on Mr. Neale at
once and was delighted with him. She noticed his head among all the
rest and admired it almost more than any.... Suddenly, amongst a
great crowd of faces, Mary pointed out one to me and asked if that
was Mr. Kingsley, and it was. Mary thought it noble. Mr. Neale
introduced Kingsley to Mama, and he talked to her for some time ...
and Mr. Neale introduced Mr. Ludlow to Mama, much to Ockey’s
delight.... I think Mr. Kingsley’s face extremely suffering and full of
the deepest feeling. But there is such a sublime spirituality; he looks
so far above this earth, as if he were rapt up in grand reveries; one
feels such intense humility and awe of him. I hardly dared look at
him; and the more I looked, the more I felt what a grand thing the
human soul is when developed as it is in him. Professor Maurice was
called to the chair, and he made a nice speech. He seemed as if he felt
a great deal more than he could express, and therefore left feelings
rather than ideas in one’s mind. He said a great deal about self-
sacrifice; though he said he felt almost ashamed to speak of self-
sacrifice to working men, while he himself was in possession of all
the comforts of life. He had to leave after he had made his speech;
and, just as he was about to leave the platform, Mr. Cooper said that
the Manager of the Builders’ Association, Mr. Pickard, would read an
address to Professor Maurice as an embodiment of the sentiments of
the Associations, and that the Manager of the Printers would present
him with a testimonial, the exclusive gift of the working men. The
address of thanks was very nicely expressed; and then the
testimonial, a silver inkstand, was presented. It was so touching to
think of all those poor working men, who had worked so hard to earn
the money to make the testimonial, and the beautiful spirit of
gratitude. I could not restrain my tears. Professor Maurice answered
the address and thanked them in the most heartfelt manner. After he
left, Mr. Hansard was put in the chair, and Lloyd Jones spoke on Co-
operative Stores. Mr. Newton spoke on Mechanics’ Institutes, and
said they were not at all satisfactory as far as they professed to
educate the working men. Someone in the Hall got up and said that
he knew of one gentleman on the Committee of these Institutes, who,
in opposition to the majority of the Committee, threatened to resign
if “Alton Locke” was allowed in the Library. I could not see Mr.
Kingsley’s face.... The next subject was the Industrial and Provident
Societies Bill which had just been passed. Mr. Kingsley then made a
short speech; one knew at once that it was a poet who was
speaking.... Gerald Massey’s is a very fine face. He has dreamy eyes
and wild looking hair; but, after the others, he’s not to be thought of.
Ladies’ Guild,
October 22nd, 1852.

To Gertrude.

Oh Gertrude! I am so happy, so very very happy. I wish you were


with me. You would so love all my beautiful things. I will tell you
about them when you come. I have a little room, all to myself. When
anything is wrong or unjust down stairs, I have only to come up into
my own little room, and it is so still. It is full of such happy
recollections. I have my nice books; all my great soul-inspiring books
are here. Then I have all my writing things. I write a great deal now. I
have such a beautiful book of extracts that I have made. I have
usually some flowers; for the ladies are very kind in bringing me
them. I have a few poor little plants that I am fond of. Then I have
eleven dear little snails. They are such darlings. And then, Gertrude,
I have my drawing things. I do not let anyone see my drawings. I do
not do much. It is sad to think, after I have done anything, “And,
after all your visions of grandeur and beauty, is this all you can
produce?” I believe I am very wrong about my drawing; I never draw
things for the sake of learning. I try things above me. I have such
dreams, both day and night, of what I would do, and when I try what
do I see? A little miserable scrap that is not worth looking at. Once I
tried a figure. Of course it was frightful.... We have returned Ruskin.
I do so miss it. It was so very beautiful. This evening I have found
such an extract from “Modern Painters” that I shall copy it for you.
Do you go on with your drawing? I hope you do. Oh Gertrude! is it
not a glorious thing to think that a divine thought should descend for
ages and ages? Think of Raphael and Michael Angelo! (though I
know but little of them).—To think that every grand feeling they had
they could preserve for centuries! Oh what an influence they must
have! Think of the thousands of great thoughts they must have
created in people’s minds; the millions of sorrow that one great
picture (one truly great picture) would calm and comfort. Will that
never be painted again? Do you think there will? And when? I am
going to see the Dulwich Gallery soon. Is it not glorious? I wish you
could see a bit of hawthorn I have here, such colours! I am writing a
curious letter; just what comes foremost in my mind.... When I have
finished work and go up to tea, if any one is out of spirits, it makes
me so; and I feel (do you know what I mean?) a tear in my throat.

Ladies’ Guild,
July 13th, /53.

To Gertrude.

I write to you because I wish to give you a happier impression of


me than you can have from Tuesday. I am all alone; it is so still; and I
am very happy; now I will try and account for the strange state I was
in last night.

When I got into the country I felt that, if I stayed looking at sky
and trees and flowers,[10] my friends would think me dull and become
dull themselves and spoil all enjoyment. So all the day my whole
energies were “stretched” to be merry and lively. I felt that if I waited
one moment to look at anything, I should never tear myself away,
and I got into a wild state. I did enjoy very much the mere exercise,
and the mirth, and happiness of every one. I hardly thought all this; I
only felt it. Then, at the singing class, the strain being over, and
having nothing to sustain me, I sank into low spirits. As we were
singing “Oh come ye into the summer woods,” a longing came over
me to be there; a dim recollection of tops of the trees with the
evening sun upon them, a panting desire to sit there, and cry myself
quiet....
But it is all too beautiful now; I could almost fancy myself at
home.... As to my drawing, whether I will or no I must go on with
that; and, though I do not hope, I trust....

September 18th, /53.

Dear Sisters,

I fully intended to come over to you to-day, but I have a sore foot,
and can only limp to the classes. Private. On Wednesday evening I
went to see Miss Cooper, and spent the whole evening there. Just as I
was going William Cooper came in and told me (don’t tell anyone)
that they have discovered heresy in Professor Maurice’s last book,
and he will probably be expelled from the Church. I had not time to
ask any questions, as Miss Cooper returned, and she is not to know.
Professor Maurice came to town on Monday night, went to Walter
Cooper on Tuesday before Miss Cooper was out of bed, and returned
to the country in the evening.... On Thursday there was a Council.
Walter Cooper looks very grave and rather ill and anxious. What all
this betokens, I cannot guess; but I fear something sad.
I have been reading “The Message of the Church to the Labouring
Men”; it is so beautiful; also “The Duty of the Age.” I did not think
Lord Goderich[11] was so nice; it would just suit Andy.
Mr. Edwards will give us a large order for a skirting board of
marble if we can do it for 8d. a foot; also an order for a painted glass
conservatory.
If any of you love me, see if you can’t send me a piece of Indian ink
and a paint brush, and “The Land we live in,” and look out for some
toys, or books that you don’t want—the latter two for the little child
at the needlewoman’s.

November 27th, 1853.

To Gertrude.
About Ruskin, it matters very little to me what The Times, or
anything else, says of him. I see much, very very much, to admire in
him, and several things which I could wish different. If, as I suppose,
The Times accuses him of affectation of style and want of humility, I
entirely deny the first charge; as I think there is never a single word
he writes, which could have been left out without loss, or changed
without spoiling the idea; and, if it means that each sentence of his
has a beauty of sound as well as of meaning, I say that it is to me all
the more right for that; and that to be able to reproduce that sound is
a gift not to be neglected.... As to the second objection I say, if Ruskin
sees a truth which is generally denied, he is right to proclaim it with
his whole strength. He says not “I see it is so because I am a higher
creature than you,” but “I see it, because I have gone to God, and His
works for it. You may all see it, if you will look, using the powers He
has given you; only look in sincerity and humility. It is only because I
am humble, because I am content to give up my own ideas and
notions, to take the truth because it is God’s, to believe that it is good
and right. It is only so I can discover harmony in this universe, and I
am sent (he says) with a loud voice to proclaim this to you.”

Ladies’ Guild,
December 5th, 1853.

To Gertrude.

Ruskin has been here. All went as well as I could possibly wish. He
was most delighted with the things, as showing the wonderful power
we possess of introducing and preserving colour. He gave us some
most interesting and useful hints about colour, and ordered five slabs
to be painted for him; adapting two of the designs he wanted from
some we had, which Mr. Terry was to go to his house to do on
Monday. He offered to lend us some things to copy. If you had seen
the kind, gentle way in which he spoke, the interest he showed, the
noble way in which he treated every subject, the pretty way in which
he gave the order, and lastly, if you had seen him as he said on going
away, his eyes full of tears, “I wish you all success with all my heart,”
you would have said with me that it was utterly wonderful to think
that that was the man who was accused of being mad, presumptuous,
conceited and prejudiced. If it be prejudice to love right and beauty,
if it be conceited to declare that God had revealed them to you, to
endeavour to make your voice heard in their defence, if it be mad to
believe in their triumph, and that we must work to make them
triumph, then he is all four, and may God make us all so!... All my
sisters, Kitty and Mama, have given me Mr. Maurice’s “Ancient
Philosophy” and have written in it “From her sisters in affection and
work.” This sentence makes me very happy. I know it is true. I know
our work has bound us together.... Another thing happened on
Sunday which pleased me very much. Mr. Neale heard Miranda
talking about my birthday; and he said he was going to give me Mr.
Maurice’s “Prophets and Kings of the Old Testament.” He came on
Sunday on purpose to bring it. It seems such a glory that he does look
upon us as related to him, not merely as receivers of wages, that he
considers us workers with him. All that I have struggled to
accomplish, so long and so wearily, seems just now to be succeeding,
all fruitless as the work has seemed; the seeds buried, dead as I
thought them, have sprung above the ground.

Ladies’ Guild,
January 10th, 1854.

To Gertrude.

Mr. Cooper gave me last night a copy of the Address of the


congregation at Lincoln’s Inn to Mr. Maurice. He had asked Mr.
Ludlow for it on purpose for me, and Mr. Ludlow had written my
name on it.
I got “Yeast” for Miranda. Have you ever read it, and do you
remember that Barnakill forbids Launcelot to be an artist? It has
made a great impression on me.

Hillside,
February 10th, 1854.
Miranda to Miss Joanna Graham.

You have not heard yet that there is great thought of enrolling the
Guild as an Industrial Society, under the new Act. Would it not be
very nice? Mr. Neale had drawn out a set of rules; and he sent them
to Mama for her to approve or make her remarks upon. There are
however some difficulties in the way.
I have not yet been able to write a recollection of that very
beautiful class at Mr. Maurice’s; but I hope to do it.

Ladies’ Guild,
June 11th, 1854.

To Gertrude.
(Speaking of Hillside.)

I hope that I may never, as long as I live, forget the sunny,


bright happy hours I have passed there. There remains in my mind a
recollection, a vision of beauty connected with it, which can never be
effaced....
Mr. Maurice has been speaking to-day of sacrifice as the link
between man and man, and man and God. It was such a sermon!
One feels as if all peace and quiet holiness were around one;
everything appears to have a beauty and calm in it, to which we can
turn back in times of storm and wild noisy rivalries, as to the
memory of sunny days, and to shed a light on all dark and difficult
things, on sorrow and loneliness....
It is so still! A garnet coloured glass is on the table full of bright
golden buttercups, and grass; now the door is open they tremble in
the wind, carrying one back to slopes of long grass full of buttercups
and sorrel, as the evening wind sweeps over it.

INFLUENCE OF
RUSKIN AND F. D.
September 17th, 1854.
MAURICE
To Miranda.
(In the Lake Country.)

I have spent three happy evenings with Miss Rogers. I have


had a very interesting conversation on religion with Charlie Bennett,
Harry and Mr. Rogers.... You cannot think what pleasure your notes
have been, telling us, as they do, of a life of rest and beauty. One
doesn’t seem to know much about that sort of thing, and yet they
seem to speak of home to you, as not many things do. One thing will
be that you will be able to understand Ruskin infinitely better than
you would have done. I imagine that some of the descriptions, that
appear to us bright images of things almost vague at times (they are
so far off), will remind you of actual beauties that you have really
seen, memories connected with life. Ruskin has done something to
rescue many things from vagueness. He has embodied them in words
which will convey these impressions they gave you, as nobody else
ever has, I believe....
I have been to Westminster Abbey with Miss Cons, have I ever
spoken about her to you? It seems to me that she is capable of a very
great deal. She said something the other day about Mr. Maurice and
Walter Cooper that made me very angry. I told her I would never tell
her anything again; however, instead of that, I told her a great deal
more than I ever did before. I told her that it was he who had led me
to the Church, who had shown me a life in the creeds, the services
and the Bible; who had interpreted for me much that was dark and
puzzling in life; how the belief in a Father, a Son and a Holy Ghost
might be the most real faith, not a dead notion; that I might believe,
not only that God was manifesting himself to each man in the inward
consciousness of light and beauty in himself and all around; that
those had led to infinite perplexities and doubts, but that a real
person had come amongst us, who had known the Father, whose will
had been brought into harmony with His; that He was stronger than
doubts and sorrow and had overcome them; that He had declared
that we might have life, that life was knowledge of God. From this
conversation came a determination that Miss Cons and I should read
the Theological Essays together.
... Oh if you could but see my ferns and all my things here. I have
so many things I want to do in this room, but they all want money,
sometimes as little as threepence, sometimes several pounds. It is
perfect, because everything is progressing. The ivy will some day
creep around the windows. I shall some day know my books better,
and perhaps at last the room will be all grey stone, the window
Gothic, and there may be pictures of my own painting; and the stony
walls may be covered with wild masses of leaves standing out boldly
in the sunlight, with their shadows sharp and dark on the grey
background.
I began this letter to-day, as the first sunbeam fell on my flowers.
Nobody could have been happier. Now I have run up from work to
finish it, feeling very cross. Kitty has complained to Mama that Miss
Cons and I make a great deal of noise. We never do anything but talk.
Never mind! she’ll find me silent enough.

INFLUENCE OF
RUSKIN
Ladies’ Guild,
March 14th, 1855.

To Emily.

I find on reflection that it will be a rather more difficult


undertaking than I imagined to write to you every two days. However
I will do my best.
You will have seen, by this time, what a wonderful event is about to
take place in my life, and will, no doubt, have realized what it will be
to me. But, however wonderfully you may all enter into my feelings,
or even discover them, I do not think any of you can really
understand what this is to me, unless you could have looked into my
heart continually for three years, and seen how at first he was only a
friend of Mr. Furnivall’s[12]; then how his books were everything and
he nothing; then how his name suggested a vision of vague beauty
and distant and indefinite glory.... Still he was distant, almost unreal.
He might be in Italy, or Palestine, or he might be passing me at that
moment.... Perhaps in a year or two hence I may tell you what my
thoughts were, and are at this period;—but, all this time I was
learning to admire him more and more, and now leave the rest till
after Friday.
I send you a prospectus of the College, which I beg you will return.
Walter Cooper was with us last night; but I don’t think we heard any
news.
Anna Mary (Howitt) has fulfilled her promise to lend me “Modern
Painters.” She sent them yesterday; I leave you to put in all the marks
of admiration and the “oh how delightfuls!” according to your own
fancies; working people have no time for anything but facts, (not that
the delight of reading “Modern Painters” is less a fact than that the
book is in this house), but——
I am very bright to-night, as you may perceive, and am writing this
in the most comfortable way, in bed. Tell F. that I expect she is quite
a woman, and is quite independent of my letters, and, as I promised
to write to you, she must not expect letters from me; but she must
accept my kindness to Pussie, and my care of her plants, as the
affectionate proof of my remembrance and friendship. Will you, dear
children, think of me very earnestly on Friday at two; and try to see
poor Mansfield’s[13] grave? I suppose there is not a single fern. You
know how much I want them.
I’m getting a toothache with sitting up in the cold; so I must lie
down and read. I’ve written to accept Ruskin’s invitation.

Ladies’ Guild,
March 16th, 1855.

To Emily.

There is only one thing to speak about just now, Ruskin. I have
been,—fancy! We could not get an omnibus which would pass the
door, without waiting till it would be too late. We took one which
brought us to Camberwell Gate; we tore along, thinking we were late,
and too much engrossed by that idea, to see or think of anything else.
At last we arrived at a green gate with a lodge. We asked for Mr.
Ruskin, and were sent on to the house. Imagine a handsome
mansion or large villa, a broad sweep of gravel road leading to it,
bordered by a lawn, on which stood an immense cedar of Lebanon,
on the other a bank covered with golden celandines in full flower,
and shaded by immense elms. Ascending a flight of steps leading to a
glass door, we looked into a handsome hall; a footman came and
showed us upstairs; we entered Mr. Ruskin’s study, and he was there.
He received us very warmly, asked us about our journey there, and
about the weather, which I then for the first time perceived. The
room was lofty, the furniture dark, the table covered with papers, the
walls rich with pictures, a cabinet full of shells, with a dead fern or
two; and looking out of the window over a garden (I never looked at
it) on to a field which sloped very gently, more like a bit of park, large
trees on it, with their shadows strongly marked by the bright sun,
and very still; beyond, slopes of meadow and woodland, over which
the shadows of large white clouds kept passing. Mr. Ruskin was very
kind, and showed us numbers of manuscripts, which I admired more
than I had any idea of, and sketches. He evidently thought my design
well done, admired the fir and bramble, blamed my not knowing
exactly what colours I should put everywhere, and illustrated these
things—that in a fine design each thing is of importance, that the
effect of the whole would be spoilt by the alteration of any part; that
simplicity of form is needful to show colour; that no colour is
precious till it is gradated; that grass is more yellow than we think;
that holly is not green (made only with blue and yellow) (sic) but
with crimson and white in it; that it is impossible to have colour on
paper so light and so living as in nature; that, in the fourteenth and
fifteenth centuries, work becomes coarser, more floral, less grotesque
than in the thirteenth. We had a delightful conversation about one
thing. I remarked what a world of beauty he was surrounded with;
and he answered that, if I could change places with him, I should be
no happier than I am now. I said I knew that very well; but I affirmed
there was a positive pleasure in a beautiful thing. He said he was very
covetous, always wanting more; and that he desired happiness, but
from the success of what he was doing; that he would part with all he
possessed, if he could thereby insure that some real illuminators
would arise. We then, though quite consistent, appeared to change
sides in the argument. I said that there was as much pleasure to be
found in London as in the country; that the beauties were more
valued when seen, and the scraps of beauty more loved. He said that
man was not meant to be in a constant state of enthusiasm (of which
by the way we stand in no danger); that the blessing of the country
was more negative; that brick walls were a positive pain. I said that I
was very glad to say that, although sometimes feeling crushed by the
ugliness, I could forget it. He ended by saying that, as I was fond of
the country, he hoped after May, when the weather was warm, I
should often go down there; and then, altering the reason of the
invitation, he said that, if I wanted to refresh my memory and come
to see his MSS., I could come any day and chance finding him at
home; or, if I would send a line the day before, he would try and be at
home. This is not half of this conversation, and we had several
others, to say nothing of illustrations and propositions.
And now, M., do you, or do you not wish to hear what I think of it;
that that which is asked for is given; that, well-used, this friendship
(?), so happily begun, may be a long and growing one; that I have
seen a world of beauty; and that this might be the opening to a more
glorious path; and that I would give years, if I could bring to Ruskin
“the peace which passeth all understanding”?

WORK FOR
RUSKIN
Ladies’ Guild,
March 19th, 1855.

To Emily.

I ought to have written yesterday; but, as I cannot write on


Saturdays, I thought it was well to get to the right days again. You
must not think it unkind, if I do not write to you again, as Mr. Ruskin
has lately sent us some work to do. Of course I wish to do it; so, as
there is other work wanted, I shall have to do it in the evening. Mr.
Maurice also will be home on Wednesday; and I am not sure that we
shall not be admitted to two meetings there are to be.... Tell F. her
kettle mourns day and night at its loneliness, and muses over its
utter uselessness; and the book-case looks sadly dejected, but it has
not told me the reason.
Don’t expect a merry letter to-night. I am rather dejected.... I often
wish now I were quite free and could work at what I liked.... It
requires a strong heart to go on working, without anyone caring
whether you are longing to do anything else. I am going to work all
the Fast[14] day at Ruskin’s things; and God give me a brave heart, for
I am sure nothing else can.
Dear child, I hope you are happy and enjoying the country very
much. I long to see Mr. Maurice again. When I do, I shall have more
to tell you, if I have time to write. I am very wretched. I am not to
begin Ruskin’s work to-morrow.... I am trying very hard not to
complain. If I have attained so far thro’ all obstacles of three long
years, surely I shall be helped to go farther; and surely there is a
reward, there is a use in all the long hours I have worked, all the
energy I have given; surely there is a brighter day coming. He who
works for man must look to man for his reward; but we have worked
for God, and He will reward us.

Ladies’ Guild,
March 21st, 1855.

To Emily.

Thank you very much for your letter. I am very much interested by
your account of that clergyman. I should think from what you say,
that his influence must be very good. The mere fact of the
congregation being so poor and degraded would seem to shew it. It is
very difficult to tell what the doctrines of a man are from one
sermon; and very likely you heard the worst side of them.
I have been to Lincoln’s Inn to-day, and have heard Mr. Maurice,
and have seen Mr. Hughes, Mr. Kingsley and Mr. Ludlow. Mr.
Cooper advises me to go and see whether we shall be admitted at the
meeting. Mr. Kingsley will preach at Bethnal Green on Sunday
evening. I am in the very heart of painting Ruskin’s designs, really
enjoying it.
SERMON BY F. D. I have a copy of the form of prayer for to-
MAURICE day, which you will like to read when you
return. Mr. Maurice preached such a beautiful sermon about it.[15]
The text was the 1st to 8th verses of 1st Chapter of S. Luke. He said
that, three weeks ago all England was startled by the news that the
man[16] whom she had looked upon as her most deadly enemy was
dead; that whatever hopes statesmen or merchants might entertain
of the result, had proved wrong; that many people said there must be
a purpose in this event; that however sinful it might be to rejoice over
it, they could not but believe that it was working towards some good
end. To such people, he continued, I would answer, “assuredly not an
emperor falls (because not a sparrow falls) without our Father in
Heaven; and to Him who wills it every event will bring a blessing.”
And what should we learn from this? In the first place, we have all of
us fancied that we were fighting against a man; whereas the fact is we
are fighting against a principle, which is represented, perhaps in a
nobler form than usual, in this man. People objecting to this say, “no,
we are fighting against flesh and blood; we leave all abstractions to
philosophers.” I agree with them thus far. We are engaged with
realities; if a principle be a mere theory, to be disputed about in
books, it is nothing to living men; but, if it be that which gives energy
and motive to action, then it has everything to do with them. We are
fighting against that arbitrary power, which treats men as mere
machines or tools, and is utterly indifferent to national life. There is
great danger connected with the belief that our enemies are men, not
principles. We are likely, we are almost sure, not to see the same
enemy at home. We are all too much inclined to think that we live
only to carry on our separate trades and professions. We happen,
indeed, to carry them on together in a certain geographical position,
which has been for some years called the island of Great Britain. We
have, it is true, a common language. It is very convenient it should be
so, just as it is very convenient to have a medium of exchange. It
would hinder our buying and selling very much, if it were not so. It is
also very important to have laws to punish those who injure their
neighbours. These laws must be general, lest one class should gain
the ascendency. We must also have a doctrine preached about future
rewards and punishments. Of course about such an uncertain subject
there can be little agreement; and therefore, if all compete in
preaching, it will suit all tastes. We do not want a sense of national
life. It is this indifference to it which we have been striving against
thro’ all generations. This common enemy unites us to all past ages;
if we have lost sight of it, we lose the meaning of history. And this is
the meaning of a Fast day. It speaks to us all as members of a nation;
it tells us of a stronger bond than that of possessing a common
enemy; that we possess a common Father; this gives prayer a
meaning, and national life a reality. And this speaks to us
individually. So long as we look upon the Emperor of Russia as our
enemy we cannot expect to have to conquer him; (sic), and we cannot
ask for help to do so.... Thank you for the promise of ferns. Bring
several. Numbers here will be glad of them. We are having the
garden dug, and shall be glad of all contributions. Can you bring a
stone and a root from Mr. Mansfield’s grave?... It is very late, past
twelve (long).

Ladies’ Guild,
March 27th, 1855.

To Emily.

Thank you for your two dear letters. They interested me very much
indeed. Have you read “Brave Words”?[17] I think G. and you might
like to read it together. Mr. Maurice preached at Lincoln’s Inn on
Sunday morning. I did not know of it. Since I have known him[18] I
have missed hearing him four times, Stepney, Whitechapel, lecture
on Newspapers, and last Sunday. It was a funeral sermon for Mr.
Mansfield; and all his friends met together afterwards. They are
going to have it every year. Mama went with me in the afternoon.
The text was the 27th verse of the fourteenth of St. John. Mr.
Maurice began by saying that these words were not understood at the
time they were spoken. The events which followed them seemed the
most awful contradiction of them; for even He who had spoken them
appeared to have lost then the gift which He promised. The question
was, What peace was it which He gave? It could not be peace in the
world; the wars, the contentions showed that that had not been
given. The Gospel which they brought to the world seemed to bring
divisions not unity, strife not peace. It could not be peace in the
Church; for a few weeks it seemed as if this might be the gift which
Christ had left. They had all things in common; and then arose
contentions, people pretending to have sold their possessions, and
given the whole value of them to the Church, when they had retained
half. Paul rebuking Peter; discussions about circumcision. Was it
outward peace for themselves? Never had any set of men experienced
so little as the Apostles. Was it inward peace, a cessation of all fierce
war with evil, of all conflict? Surely not. For that which Christ
promised He must have realised Himself. They had heard the cry on
the Cross, and seen the agony in the garden; surely there never was a
more awful fight with evil than that which He had carried on. Above
all, they had forsaken Him themselves. If anything would add to their
sense that they had no peace, it would be that when they thought
they were ready to die for Him, they had left Him; the cross and
death did not divide Him from them so much as their unfaithfulness.
But all this showed that the peace which He promised could be no
outward peace; that it could not be felt till they were ready to give up
that. The sense of a friend, a deliverer, the revelation of a Father,
would give them really a peace which the world did not give, and
could not take away. I forget how it came in, but Mr. Maurice
mentioned Christ’s look to Peter which made him weep, and
contrasted that with Judas’s remorse. I would give you a better
account of this sermon, but I ought to have written it before. It is
now confused in my mind with Kingsley’s, the one I heard on
Wednesday, and with several things I have been reading.
We are not to execute our own designs for Ruskin, at any rate yet. I
have been doing his letters in the work hours.... About what you and
G. have been saying, I should answer, that I think you are quite right
in maintaining that, if the war is right, we must be right in praying to
God to help us in it; but I think there is a certain cowardice, a
shrinking from looking facts in the face, when people say that they
are not asking God to help them to kill men. That is not the end, but
it is the means. What I think we want to see is that all things are as
nothing in comparison with right; that we have no business to
calculate results; that we are to give up comfort, homes, those who
are dearest to us, life, everything, to defend right. I wish very much
to have time to think what a nationality is, that it should be worth so
much. I feel that it is worth everything. I suppose every nation has a
separate work to do, which would be left undone were it extinct. I
think a nation can never perish till it has so far neglected its mission
that its existence has no more meaning. If it has fulfilled its work it
will be given more to do; so with the Jews; they had borne witness to
a living Ruler, a King of the people; they had had glimpses that the
King would be more fully revealed; they believed that it was He who
had brought them out of captivity, had strengthened them in battle.
They had forgotten Him, and asked for a visible king like the other
nations, when their glory was to be different from them, those other
nations. The king was given; the prophet saw that there was a divine
meaning in the cry for one; but Saul was the representative of the
people, he was a mere general. He was wrecked; and yet there was a
meaning in the offer. The earthly king might set himself up, might
tyrannize over the people; but he was the continual witness of a
power, which he might recognize and bow before; life was as nothing
to the Israelites, nationality everything. And they did not fall because
they thought so little of life; they thought too much of it, if you look
upon life as merely the breath. But if life is the light of men, we have
no evidence, we can have none, that it is in the power of man to take
it away. They did not give it, and they cannot destroy it. If in Him
was the life, in Him it is, and ever will be; we may surely trust to Him
those whom He has made. The light which shined in the darkness
was surely that which has been in our soldiers, in the long-suffering
they have had; their breath, their bodies man can destroy; but that
which has given them strength is still theirs, when their last struggle
on earth has ended, and they go perhaps to a more awful fight; but
with a peace which cannot leave them. The Jews fell; they thought
they were different from all the world, when they were most like it.
They were boasting of their privileges, trusting in themselves; they
evidently thought the highest sign of godliness was utter selfishness.
They would have thought it a triumph for Christ, if He had saved
Himself. He died that death might have no more darkness for us, no
more loneliness; for He was light and life, that He might bear witness
that breath is not the most precious thing; that there is One Who is
always trying to destroy that higher life, but that it is His gift and He
will preserve it....
Mr. Maurice preaches next Sunday at Mile End.
It is very late, so good night.... Mr. Maurice asked very kindly how
you were. He does not appreciate the noble patience with which you
are waiting at Weybridge; but, if he does not understand it, we do
sympathise.

Ladies’ Guild,
April 19th, 1855.
Emily to Florence.

VISIT TO RUSKIN I have such a great deal to tell you that I


don’t know what to put first. You must know that Ruskin appointed
to see Mr. Pickard[19] at 2 o’clock at his house; and he was to take the
letters that they have done as specimens at about half past twelve.
Ockey came running into the workroom, half crying, half laughing,
and came and whispered something to Miranda who left the room
with her. Presently Miranda came back laughing, and saying that she
had succeeded.... It came out that this was the case.... Ockey had
wanted very much to go with Mr. Pickard; but he was going in his
cart; and Ockey could not go in an omnibus and meet him there,
because it would offend him; so Miranda persuaded Mama to let
Ockey go in the cart. She says that she enjoyed it so much; Mr.
Pickard was so kind and thoughtful. He did not drive up to the door
in the cart, but left it at some distance. Ruskin received them very
kindly and was very much pleased with the letters, and has given an
order for two more to be done. When they left Ruskin, Mr. Pickard
seemed determined that they should enjoy themselves. He wanted to
explore a pretty road that there was; and soon he set his heart on
going to the Crystal Palace; so he took Ockey there, and showed her
all over the gardens which she had never seen before, and led her
about from room to room.... At last Ockey began to fear that he
would never leave, and that she should be late for the meeting at the
Agency. However, she got back in time.

Ladies’ Guild,
July 6th, 1855.

To Miss Harrison.

We shall be very happy to see your friends and your uncle, who I
think I have had the pleasure of meeting at Mrs. Howitt’s.
It gives us very great pleasure to see anyone who is really
interested in our work. Sympathy is very precious, and the
knowledge that we are not working utterly alone; it is a wonderfully
interesting work, at times a difficult one; thrown so much together as
we all are, we have to ask ourselves what it is that unites us, now that
we have at last broken thro’ the wall of ice that has surrounded these
children’s hearts, threatening to shape them into machines, not to
educate them as human beings, having individuality, powers of
perception and reflection; tho’, thank God! it never could have
achieved its work entirely because they would always have had power
of loving, however blunted it might have been.... I do not think the
influence that the rich and poor might have upon one another has
been at all understood by either. I think we have all taken it too much
for granted—a great deal more than we should have done—that the
giving is all on one side, the receiving on the other.... I have had a
great success to-day, in destroying, I trust for ever, a six years’
quarrel between two of the children. But a long work lies before us;
and to-day’s victory is but a small emblem of what must be. There
must be many a cloud, and many a storm, and many an earthquake;
and yet we must rise victorious, to lead these children to love truth,
to realize it as more eternal, more real than any material substances;
to teach them that in the principle of a sacrifice lies all strength; to
open their hearts and eyes to all beauty; to bring out the principle of
obedience and sacrifice, as opposed to selfishness and lawlessness.
This is not a small work, and they must learn to do that which lies
before them, to look upon the fulfilment of the duties which God has
given them, in whatever position they may be, as that which will
open to them the Kingdom of Heaven. This is a work which we must
ask to be able to undertake in all humility, all energy, all earnestness,
all faith; feeling that our only strength, our sufficient strength is that
God is working with us.
I do not know whether I ought to apologise for writing such a long
letter; but I hardly remembered what I was doing.

CHILDREN’S
CONSCIENCES
Ladies’ Guild,
4, Russell Place,
Fitzroy Square,
July 16th, 1855.

To Miss Harrison.
It has given me much pleasure to receive your very kind letter. I
thank you in my own name and in that of the children for your
welcome invitation. It will give us very great pleasure to accept it....
Your letters have given me much pleasure because they are
assurances that we are not working utterly alone; because we want
this assurance; because the evil which is so great, and so near, is
almost crushing, without a consciousness of having fellow labourers.
It is such a very small number that can come within our reach; our
influence is so limited even on those with whom we have most to do;
there is so much in ourselves that hinders us from understanding
and loving these children as we should do; so much in them that
hinders them from caring for our love. Fancy appealing to a child’s
sense of duty to do something which will delay her work, prevent her
earning so much as she would otherwise have done, perhaps deprive
her of a meal, very often of a new pair of shoes! How strong her sense
of duty must be, how real right must seem to her (if she is to prevail),
to counterbalance the reality of the dinner and clothes! How dare I
hope, I very often ask myself, to awaken this sense? And yet I do go
on acting as if it were existing; appealing to it, and receiving proofs of
its existence continually. I dare not hope that I shall have the power
of creating it. I dare not disbelieve that I ought to be the agent in
awakening it. It is a very wonderful work in which we are engaged. It
is a very awful work, when you feel how easily you can reach their
hearts, how hard it is to reach their consciences; they will do
anything for you, they will do hardly anything because it is right. And
tho’ this is dangerous, because so false a ground to stand upon, yet
this inclination testifies of a precious truth. It might teach us, if we
would only learn, how much all human beings must crave for
personality; how cold, how dead, how distant are all abstractions. A
soul diffused thro’ nature, an ideal, an essence, a principle, may seem
to satisfy a comfortably situated philosopher. It is sufficient to dream
and speculate about; it is not enough to live upon. Even in his most
easy moments, there will be strange questionings in him as to what
connection this God of his bears to life; and there will come a time
when the ground beneath him shall be shaken; when he shall ask
what he is standing upon; when evil shall rise before him as
something very real, very near; then he will have to ask whether
there is nothing nearer, nothing more real; yes! in his old creeds (if
they deserve the name) there is an essence pervading all things. An
essence, when this is a real battle, when evil is gathered up in some
person, is felt to be most terribly personal. If evil is all vague, all
mysterious, and yet most real, is there no Person stronger than it,
mysterious through His divinity? Yes! then all history, all life will
testify there is such a one. Man has been trying to bow down even to
himself; he has longed to worship, but it must be something definite,
something eternal; such a one has been shown. Every man is to act as
if it were so. You are all to speak to those around you, as if they had
that in them which would recognise and reverence this Conqueror,
this Knight; and yet as if they knew that He could only be God’s
warrior, because He came not to crush but to raise; and yet that, just
because of this, He was bound to fight with evil, bound to destroy;
and I do hope we may be able to awaken in the hearts of these
children a knowledge that they are called soldiers of Christ, in
whatever place they may find themselves; that it is their duty not to
speak or act or think as if there were no evil; that it is no proof of
trust in God to shut their eyes. They do see evil, they do feel it in
themselves, they are bound to testify that God is stronger than the
devil, light than darkness, life than death. There is all danger of our
disbelieving this. I feel it in myself. I am frequently inclined to act as
if I believed that another than a righteous God was ruling, especially
in the hearts of others; as if there was nothing so strong as
selfishness, nothing so mighty as self interest; and yet I am bound to
claim for these children, to claim for all of us, the name of Christians,
children of God, inheritors of His Kingdom.

Ladies’ Guild,
July 24th, 1855.

To Miss Harrison.

... And now I must thank you all very very much for your kindness,
which I am sure we shall never any of us forget. I am sure you will be
glad to hear how much we all enjoyed the whole day. I am sure that it
was to many of us a revelation not only of beauty and comfort, but of
gentleness and generosity, which we have cause to be very grateful
for. The children have never ceased talking about it; the boat, the
water, the garden, the flowers are continual sources of delight. I
asked them to-day if they had any message to you, as I was going to
write. They seemed oppressed by a sense of wanting to say
something. One of them said she had plenty to say, if she was going
to write herself. There was an eager discussion in one corner as to
whether it would be proper to send their love; but they ended by
asking me to thank you all for them, as they did not know how. I felt
very much inclined to tell them how very little I knew how; except
that I thought the very love, which they seemed to think it would be
shocking to express, was the only thanks which you would care
anything about.
I have had a very sad day to-day. A scene with the children,
bringing up old quarrels, repeating unkind things which should have
been forgotten long ago; a recommencement of a feud, which I had
so rashly hoped was destroyed for ever. I spoke to them very
earnestly; there was not a dry eye in all the room; but I fear that very
little lasting good has been done. I do not see what to do about it.
HOW TO FIND I went yesterday to Epping Forest with both
OUR WORK the Tailors’ Associations. There were eighty of
us at tea; and, as they sat in the long room, covered with beech
boughs, some of us were called upon to sing “Now pray we for our
Country!” and I could not help thinking how real the prayers of the
workers are, because their lives are so much together. With no doubt
that the prayer would be answered, I could sing “Who blesseth her is
blessed,” and think of all those dear children at home, who are
trying, and will, I trust, try more to Bless England; and I could thank
God for such as you, because I am sure that, if England has not
devoted children, and faithful servants, she must perish; and I could
ask that such days as this may not be very rare, because the only
meaning of our life, like the only meaning of her life, is union.
On Saturday the children were talking about their visit to you; and
one of them said: “Ah! I should like to live there always.” “So should
I!” and “Oh that would be nice!” echoed round the room. They then
said to me, “Should you not like to live there always?”
I was conscious of a very strong impulse urging me to answer
“Yes.” An idea of quiet (which has lately been occasionally my ideal
of happiness) came over me, more especially a vision of your uncle’s
face, which always seemed to me to possess a divine expression of

You might also like