Download ebooks file The dRuby Book Distributed and Parallel Computing with Ruby 1st Edition Masatoshi Seki all chapters
Download ebooks file The dRuby Book Distributed and Parallel Computing with Ruby 1st Edition Masatoshi Seki all chapters
https://ebookultra.com
https://ebookultra.com/download/the-druby-book-
distributed-and-parallel-computing-with-ruby-1st-
edition-masatoshi-seki/
https://ebookultra.com/download/mobile-intelligence-wiley-series-on-
parallel-and-distributed-computing-1st-edition-laurence-t-yang/
ebookultra.com
https://ebookultra.com/download/distributed-computing-principles-and-
applications-m-l-liu/
ebookultra.com
https://ebookultra.com/download/elements-of-parallel-computing-1st-
edition-eric-aubanel/
ebookultra.com
https://ebookultra.com/download/introduction-to-parallel-
computing-2nd-edition-ananth-grama/
ebookultra.com
https://ebookultra.com/download/introduction-to-parallel-
computing-2nd-edition-ananth-grama-2/
ebookultra.com
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
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
This English translation, revised for Ruby 1.9, is copyright © 2012 Pragmatic Programmers, LLC.
All rights reserved.
Acknowledgments . . . . . . . . . . . xi
Preface . . . . . . . . . . . . . . xiii
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
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.
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.
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.
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!
• Interested in finding out about the benefits of writing apps using dRuby
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).
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 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.
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.
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.
1. http:// pragprog.com/titles/sidruby
Introducing dRuby
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.
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).
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()
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.
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.
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.
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.
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.
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.
Puts
Client
puts('Hello, World.')
puts()
puts00.rb irb
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.
uri = ARGV.shift
there = DRbObject.new_with_uri(uri)
there.puts('Hello, World.')
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
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.
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)
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.
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.
Application
foo()
bar()
Front
Client
Foo foo()
Object
Object
Bar
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
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).
Reminder
item
serial
add r
delete
to_a
Terminal 1 Terminal 2
Terminal 3
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"]
]
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.
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
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!
Reminder CUI
item model
serial add
add delete
delete list
to_a show
Terminal 1 Terminal 3
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.
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.
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.')
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.
• 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.
• Each DRbServer object can associate with one object to expose it to the
public.
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.
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.
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.
implementation of func
calling func()
func() { ... }
y = func(x) func(x)
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.
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).
call
Object
foo(x)
marshalling unmarshalling
Network
Figure 6—How RMI works: Client -> Stub -> Network -> Stub -> Server
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).
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.
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.
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
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.
IDL
Generated by IDL
Link Link
Client Server
App App
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.
• Limited to Ruby
• 100 percent written in Ruby
• No IDL required
Application
dRuby
Ruby
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.
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.
RWiki Div
Ring Dip
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.
In Ruby, objects are all exchanged by reference when you pass or receive
method arguments, return values, or exceptions.
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
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
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
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
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.
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
swap with more specialized middleware as their systems grow. For inspiration,
the following are some real-world examples of dRuby systems.
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
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.
5. http:// www.extremeprogramming.org/rules/userstories.html
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.
Understanding dRuby
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.
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.
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
def initialize
@account = ''
@customer = ''
@items = []
end
attr_accessor :account, :customer, :items
def to_s
str = <<EOS
Dear #{customer}
-----------------------------------------
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
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.
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).
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.
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:
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.
Ladies’ Guild,
July 27th, 1852.
To Gertrude.
Ladies’ Guild,
July 13th, /53.
To Gertrude.
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....
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.
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.
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.)
INFLUENCE OF
RUSKIN AND F. D.
September 17th, 1854.
MAURICE
To Miranda.
(In the Lake Country.)
INFLUENCE OF
RUSKIN
Ladies’ Guild,
March 14th, 1855.
To Emily.
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.
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.
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