
Tuple Spaces – Good Ideas Don't Always Win (2011) - panic
https://software-carpentry.org/blog/2011/03/tuple-spaces-or-good-ideas-dont-always-win.html
======
nostrademons
The CTO at my first job out of college was the chief architect for JavaSpaces.
I think we'd used it in an early version of the product but had migrated away
from it by the time I joined full-time.

Aside from the fairness issues that other commenters mention, tuple-spaces
work at an awkward level of abstraction. You can easily implement many other
distributed concurrency models with them - semaphores, message queues,
producer/consumer channels, broadcasts, even MVCC and transactions - but
oftentimes, _in the application_ it's more natural to just use the more
specific abstractions. For example, you could implement a message queue by
putting tuples of [type tag, sequence number, ...data] in and taking out the
next message of a given type - but usually you'd want guarantees that there
are no name collisions among type tags, and that sequence numbers are never
skipped, and a mechanism to resend missing messages if for whatever reason
they aren't produced correctly. At that point you'd rather just use golang-
style channels or a real message queue library rather than roll that on top of
the tuple-space.

There are relatively few problem domains I can think of that map _directly_ to
a tuple-space, without building some other concurrency abstraction on top of
it. Dependency graphs and workflows, perhaps, but there are other libraries to
handle that specific problem which also handle things like tracing, debugging,
and error correction.

~~~
ralphc
Early to mid 2000's a product I worked on had a messaging abstraction that you
could use JMS, MQSeries, MSMQ, etc. We tried, really tried, to use JavaSpaces
but it had no FIFO guarantee. You could theoretically add and get tuples and
one could stay in the space for days. A non-starter for that.

------
esfandia
It introduces a nice level of indirection between different actors, so that
they don't need to know about each other's existence in order to communicate
and solve problems together. The actors can be added and removed dynamically,
and so the problems to solve and the problem-solvers can evolve over time.
It's a pretty powerful and flexible idea! To use GoF terminology, it's like
having a Mediator for a bunch of asynchronous and fully decoupled pub-sub
Observers and Observables. It's a way to implement Barbara Hayes-Roth's
Blackboard model.

JavaSpaces, TSpaces emphasized the over-the-internet aspects of it, which
didn't matter to us for our project. We ended up finding and using something
much simpler called LighTS. With all the nice support for concurrency in Java
these days though, it wouldn't be much work to put one together from scratch.

------
yagyu
I used tuplespaces to implement a poor man's distributed computing for Matlab
back in 2009 or so.

It would simply put Matlab code and parameters in a tuple, a worker would pick
it up, compute, and put the results back. Used it to distribute the heavy
function evaluation in a genetic optimization.

It was very easy and trouble free..

Edit: mixed up the implementations, I used TSpaces by IBM
[http://www.almaden.ibm.com/cs/TSpaces/Version3/ClientProgrGu...](http://www.almaden.ibm.com/cs/TSpaces/Version3/ClientProgrGuide.html)

~~~
Immortalin
Sounds like the current Function-as-a-service trend?

~~~
DonHopkins
"Go Service Yourself" is the latest fad in Concurrent Micro-Managed Golang
Function-As-A-Service Oriented Architecture Implementing Robust Distributed
Parallel Y-Combinator Cloud Servers with Amazon Lambda, so other Amazon Lambda
Functions can recursively call Themselves without knowing Their own names.

------
DonHopkins
In the discussion of "X and NeWS History", I mentioned "PIX", which integrated
PostScript with tuple spaces on Transputers, in thread about how X-Windows is
actually just a terribly designed and implemented distributed database with
occasional visual side effects and pervasive race conditions:

[https://news.ycombinator.com/item?id=15327211](https://news.ycombinator.com/item?id=15327211)

Jon Steinhart: "Had he done some real design work and looked at what others
were doing he might have realized that at its core, X was a distributed
database system in which operations on some of the databases have visual side-
effects. I forget the exact number, but X includes around 20 different
databases: atoms, properties, contexts, selections, keymaps, etc. each with
their own set of API calls. As a result, the X API is wide and shallow like
the Mac, and full of interesting race conditions to boot. The whole thing
could have been done with less than a dozen API calls."

To that end, one of the weirder and cooler re-implementations of NeWS was
Cogent's PIX for transputers. It was basically a NeWS-like multiprocessing
PostScript interpreter for Transputers, with Linda "tuple spaces" as an
interprocess communication primitive:

[http://ieeexplore.ieee.org/document/301904/](http://ieeexplore.ieee.org/document/301904/)

The Cogent Research XTM is a desktop parallel computer based on the INMOS T800
transputer. Designed to expand from two to several hundred processors, the XTM
provides a transparent distributed computing environment both within a single
workstation and among a collection of workstations. Using Linda tuple spaces
as the basis for interprocess communication and synchronization, a Unix-
compatible, server-based OS was constructed. A graphic user interface is
provided by an interactive PostScript window server called PIX. All processors
see the same set of system services, and within protection limits, programs
capable of using many processors can spread out over a network of workstations
and resource servers, acquiring the services of unused processors.

[https://en.wikipedia.org/wiki/Transputer](https://en.wikipedia.org/wiki/Transputer)

[http://wiki.c2.com/?TupleSpace](http://wiki.c2.com/?TupleSpace)

[https://en.wikipedia.org/wiki/Tuple_space](https://en.wikipedia.org/wiki/Tuple_space)

~~~
wmleler
Another good article to read about this is "Linda Meets Unix", which was
published in IEEE Computer magazine.
[https://ieeexplore.ieee.org/document/44903/](https://ieeexplore.ieee.org/document/44903/)
(full disclosure: I wrote it).

------
toast0
This sounds interesting, but feels like magic. How do the tuples get to where
they're going? In my experience, computing bits that feel like magic have
hidden costs, that are usually rather high.

Contrast this approach with Erlang, there's still a lot of tuples, but you
have to (somehow) know where to send them at a (sometimes high) human cost to
developers, but usually low runtime cost.

~~~
makmanalp
It's better to think of tuple spaces as a concurrency / communications model
than an implementation. So it's more like "the actor model" rather than
Erlang's or Java/Akka's specific implementation of it. It's more about "if we
had this type of system with these constraints and these features, abstracting
away these details, what would we gain or lose?". You're right that in the end
a good or bad implementation can make or break things (take a look at this
paper: [https://arxiv.org/abs/1612.02979](https://arxiv.org/abs/1612.02979)),
but that's not the point, at least with the original paper.

The interesting thoughts from the paper as far as I can see were: 1) Tuple
spaces are programming language or architecture or program independent, and
vastly different programs can communicate with each other 2) You don't
communicate directly to other agents by address, you write to a topic and read
from a topic, which is a form of decoupling producers and consumers 3) The
"block when nothing to read in this topic" idea, which makes programming
coordination SO easy. I guess it's a bit like unix pipes.

If tuple spaces don't seem that interesting and novel, it's probably because
of the benefit of hindsight and that a lot of these ideas are so subsumed into
the tools of today. I can't definitively make the claim that Linda is the
cause of this, but I suspect it had some effect. I think the original author
also had a lot of wacky ideas around "cyberspace" and all that, but that's
another deal and I don't think it's why people find the Linda paper
interesting now. The closest useful descendants of Linda to be seem to be
modern Pub / Sub systems or coordination databases like RabbitMQ, Kafka,
Zookeeper.

~~~
toast0
I can't run my service on a model, I have to run it on an implementation. When
people try to abstract away the hard parts of the problems, it usually leads
to bad results. For examples, SQL let's you express all sorts of interesting
queries, very few of which are a wise idea to run thousands of time per
second; ORMs make this even worse -- how data is stored and how data is
queried really need to be determined in concert in order to make data storage
and retrieval work, assuming you have sufficient data and query volumes to
care -- if you've got only a few thousand pieces of data, it barely matters.
That's not to say SQL isn't useful, or interesting, it's just not enough.

In this case, the mechanism seems too general -- if I want to read all the
outstadning tuples with 2 as the second elememt, that's possible, but seems
rather hard. If it's really about consuming tuples within a named channel, I
want to know more about the expected or desired properties of distribution --
how is it determined which agent gets to consume a tuples when multiple
request a matching tuple simultaneously, which tuple is consumed when many
tuples exist that match. What guarantees are needed to ensure progress, what
guarantees are hard to provide, what guarantees are useful, but not required
etc. Is this the most basic abstraction for distribution, upon which other
useful abstractions can be built -- or are there other underlying basic
abstractions that are needed, are there useful abstractions which cannot be
built upon this, etc.

~~~
naasking
> In this case, the mechanism seems too general -- if I want to read all the
> outstadning tuples with 2 as the second elememt, that's possible, but seems
> rather hard

How is this any different than an SQL query with 2 in the second column? Tuple
spaces seem like a RDBMS with a more restricted query model.

------
protomyth
If you are interested in tuple spaces then I recommend reading David
Gelernter’s “Mirror Worlds: or the Day Software Puts the Universe in a
Shoebox...How It Will Happen and What It Will Mean” and any Jini documentation
you can get.

~~~
jarpineh
Huh. That's interesting. I remember reading Wired article about Jini as a
pudding programmer and thinking "Yes, this can't happen soon enough". And I
can still continue thinking...

Article is from 1998 and mentions (among other things) Tuple Spaces:

[https://www.wired.com/1998/08/jini/](https://www.wired.com/1998/08/jini/)

I wonder what ultimately decided Jini's fate.

------
sitkack
A few jumping off points if you like this sort of thing

LuaTS — A Reactive Event-Driven Tuple Space
[https://pdfs.semanticscholar.org/91cb/8c359920682fda35abd9c2...](https://pdfs.semanticscholar.org/91cb/8c359920682fda35abd9c211515feb6a4362.pdf)

[https://redis.io/](https://redis.io/) (uses Lua for scripting)

[https://en.wikipedia.org/wiki/Comparison_of_triplestores](https://en.wikipedia.org/wiki/Comparison_of_triplestores)

Comet: An Active Key Value Store

[https://vanish.cs.washington.edu/pubs/osdi2010comet.pdf](https://vanish.cs.washington.edu/pubs/osdi2010comet.pdf)

[https://vanish.cs.washington.edu/pubs/osdi2010comet_presenta...](https://vanish.cs.washington.edu/pubs/osdi2010comet_presentation.pdf)

ZeroMQ [http://zeromq.org/](http://zeromq.org/)

I'd love to hear to distributed languages with first class support for tuple
space type operations (not Erlang).

------
carapace
See also "chemical" programming

[http://chemist.io/chymyst01.html](http://chemist.io/chymyst01.html)

[https://en.wikipedia.org/wiki/Join-
calculus](https://en.wikipedia.org/wiki/Join-calculus)

~~~
isthatart
Or chemlambda [https://github.com/chorasimilarity/chemlambda-gui/blob/gh-
pa...](https://github.com/chorasimilarity/chemlambda-gui/blob/gh-
pages/dynamic/README.md)

~~~
DonHopkins
And if that's not weird and robust enough for you, try "Programming the
Movable Feast Machine with λ-Codons":

[https://www.youtube.com/watch?v=DauJ51CTIq8](https://www.youtube.com/watch?v=DauJ51CTIq8)

Or "Intercellular Transport in the Movable Feast Machine":

[https://www.youtube.com/watch?v=6YucCpYCWpY](https://www.youtube.com/watch?v=6YucCpYCWpY)

And especially "Robust-first Computing: Distributed City Generation":

[https://www.youtube.com/watch?v=XkSXERxucPc](https://www.youtube.com/watch?v=XkSXERxucPc)

[http://www.cs.unm.edu/~ackley/papers/paper_tsmall1_11_24.pdf](http://www.cs.unm.edu/~ackley/papers/paper_tsmall1_11_24.pdf)

------
riffraff
Ruby had a bundled distributed tuplespace implementation (Rinda) for many
years, built on top of druby.

I remember playing with it, and wondering why it wasn't more popular.

------
mpweiher
"And compile-time analysis of tuple in/out patterns can make it run
efficiently in most cases; adhering to some simple patterns can help too."

Sounds like it might be overly generalized, with the developer having to
implement actual mechanisms ("simple patterns") on top and the
compiler/runtime having to figure out efficient implementations by presumably
sophisticated analysis, all the time hoping that the two align.

------
lukego
Nix reminds me of tuplespaces. Each derivation in the store is a tuple
describing how to evaluate a result. Active evaluations also activate their
dependencies.

------
macintux
Somewhere I should still have an old JavaSpaces book I picked up specifically
because I found tuplespaces such a compelling idea. I’ve tried to find a good
way to use it over the years, but it’s never quite matched any problem I was
trying to solve.

I seriously considered it as a way to share monitoring events between various
systems that might be interested in consuming them: logging, billing,
alerting, etc.

------
mcguire
The paper mentioned in the article, "Generative communication in Linda" by
David Gelernter is available from citeseer:
://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.113.9679

With broken links. Nice. Try
[http://signallake.com/innovation/p80-gelernter.pdf](http://signallake.com/innovation/p80-gelernter.pdf)

~~~
DonHopkins
Author of the visionary and flamboyantly named book "Mirror Worlds or the Day
Software Puts the Universe in a Shoebox...How It Will Happen and What It Will
Mean (1992)", and unfortunate target of the Unibomber.

[https://en.wikipedia.org/wiki/David_Gelernter](https://en.wikipedia.org/wiki/David_Gelernter)

[https://en.wikipedia.org/wiki/Mirror_Worlds](https://en.wikipedia.org/wiki/Mirror_Worlds)

------
mhd
One does wonder how tuple spaces would've fared without the influence of the
unabomber…

~~~
sulam
I wonder more how it would have fared if DG weren’t kind of an asshole.

~~~
wmleler
I spent several days with DG when we were working on PIX and QIX, and I found
him to be a smart, helpful person. Of course, he was on a crusade for tuple
spaces, but you shouldn't hold that against him. Also, that was before he had
several fingers blown off.

~~~
sulam
He named Linda before he had several fingers blown off too. I believe his
crusade against the 90-something percent of climate scientists that believe in
anthropogenic climate change is after he lost the fingers. I’m very sad he
lost them, no one should have to deal with that. He was kind of an asshole
before -and- after. And fwiw I’m using a broad definition of asshole, one that
explicitly includes both people who name languages after porn stars because
they were offended by Ada and people who deny established science outside of
their field which has the not-inconsequential likelihood of causing mass
extinctions.

------
dangoor
I worked at a company in 2002 that used tuplespaces for managing distribution
of searches to worker machines. It worked really well! I don't remember us
ever having trouble with that part of our system.

------
aghillo
Gosh, for my Bachelor’s final year dissertation in 1990 I implemented a
distributed version of Linda / Tuplespace in C++ across Ansaware and
Tanenbaum’s Amoeba OS. Seems a lifetime ago!

------
jmount
With JavaSpaces I remember really getting burned by the lack of queuing
fairness guarantees. The ideas were nice- but execution was very laggy.

------
galaxyLogic
This would still run on top of threads or something. So how could a basic Java
-based wen-server be better if it took advantage of JavaSpaces?

~~~
klodolph
Could we equally ask, “how something written in machine code be better if it
took advantage of the JVM, because the JVM is implemented in machine code?”

------
DonHopkins
The Linda programming language was named as a pun on Ada.

[https://en.wikipedia.org/wiki/Linda_(coordination_language)#...](https://en.wikipedia.org/wiki/Linda_\(coordination_language\)#Name)

------
DrJosiah
Built a python tuplespace around '06\. Realized it was really just a task
queue and / or RPC abstraction with a database.

Now mostly just use RPCs and queues directly, depending on whether I need
something now, or later.

------
sometimesijust
I don't get it. Isn't this just a threadsafe schemaless database?

~~~
panic
The main difference is that you can have code waiting for a query to yield
results. Imagine a chat service which has a separate process for each user’s
TCP connection. Normally, when a new message arrives, you have to tell each
user’s connection process to send the message over the network. In a tuple
space system, each connection process can wait for new messages to be added to
the database and send them automatically.

------
zubairq
Eve language was actually a good tuple spaces implementation which had a lot
of fans

