aboutsummaryrefslogtreecommitdiff
path: root/comparison.html
diff options
context:
space:
mode:
authorPeter Drahoš <drahosp@gmail.com>2010-10-01 03:22:32 +0200
committerPeter Drahoš <drahosp@gmail.com>2010-10-01 03:22:32 +0200
commit3fe8732f32e3675c62a46fcb70fb95ef936376a5 (patch)
tree98e1c640667bbb3f64fff664faf6f7d59ef0fe91 /comparison.html
downloadlanes-3fe8732f32e3675c62a46fcb70fb95ef936376a5.tar.gz
lanes-3fe8732f32e3675c62a46fcb70fb95ef936376a5.tar.bz2
lanes-3fe8732f32e3675c62a46fcb70fb95ef936376a5.zip
Import to git
Diffstat (limited to 'comparison.html')
-rw-r--r--comparison.html297
1 files changed, 297 insertions, 0 deletions
diff --git a/comparison.html b/comparison.html
new file mode 100644
index 0000000..84ef9ca
--- /dev/null
+++ b/comparison.html
@@ -0,0 +1,297 @@
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2<!--
3 Comparison of Lua Lanes with other approaches
4-->
5
6<html>
7<head>
8 <meta name="description" content="Lua Lanes - Comparison" />
9 <meta name="keywords" content="Lua, Library, Multithreading, Threads, Rocks" />
10
11 <title>Lua Lanes - Comparison</title>
12</head>
13
14<body>
15
16<!-- comparisons +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
17<hr/>
18<h2 id="comparisons">Comparisons to other threading kits</h2>
19
20<p>
21A short comparison of Lanes with other existing Lua multithreading kits.
22</p>
23
24<table><tr><td width=40>
25 <td bgcolor="#ffffe0">
26<pre>
27=============
28 Lua Lanes
29=============
30
31With the introduction of Lindas (Jun-2008), Lua Lanes simplifies its API while
32simultaneously adding more power and speed.
33
34Pros:
35 - regular Lua 5.1 module
36 - completely separate Lua states, one per OS thread
37 - message passing, or shared data using Lindas
38 - no application level locking, ever
39 - scales well, up to 1000's of threads
40 - priorities (-2..+2) for launched threads
41 - threads are cancellable (with complete cleanup)
42 - timeouts on all pending operations
43 - thread contents are given as regular Lua functions; syntax checked early on,
44 syntax highlighting works
45 - standard libraries opened to subthreads can be granually selected
46 - fast stack-to-stack copies, via hidden "keeper states". No serialization needed.
47 - protects calls to 'require', allowing wide compatibility with existing
48 modules (and all, with minor changes)
49
50Cons:
51 - requires OS threads
52 - not utilizing network parallelism (all threads on one CPU)
53
54Sample:
55<<
56 require "lanes"
57
58 local function calculate(a,b,c)
59 if not a then
60 error "sample error; propagated to main lane when reading results"
61 end
62 return a+b+c
63 end
64
65 local h1= lanes.new(calculate)(1,2,3)
66 local h2= lanes.new(calculate)(10,20,30)
67 local h3= lanes.new(calculate)(100,200,300)
68
69 print( h1[1], h2[1], h3[1] ) -- pends for the results, or propagates error
70<<
71
72
73==================
74 Lua coroutines (by Lua authors)
75==================
76
77<A HREF="http://www.lua.org/manual/5.1/manual.html#2.11">http://www.lua.org/manual/5.1/manual.html#2.11</A>
78<A HREF="http://lua-users.org/wiki/CoroutinesTutorial">http://lua-users.org/wiki/CoroutinesTutorial</A>
79
80Lua coroutines is an integral part of Lua 5 itself. It is listed here, since
81it should be the _first_ multitasking mechanism to consider. It can also be
82used together with Lanes, or the other mechanisms listed below.
83
84Coroutines are very usable in provider/consumer situations, allowing you to
85queue Lua functions on an as-needed dataflow basis with each other.
86
87Pros:
88 - works with plain Lua (no extensions)
89 - works on any platform
90 - lightweight (no OS level threading or locking involved)
91
92Cons:
93 - co-operative, meaning your code will need to decide, who gets to run
94 - does not utilize multiple CPUs/cores
95
96Sample:
97
98 ..TBD: sample code doing the "child" "parent" output here (see below)..
99
100
101=============
102 LuaThread (by Diego Nehab)
103=============
104
105<A HREF="http://www.cs.princeton.edu/~diego/professional/luathread/">http://www.cs.princeton.edu/~diego/professional/luathread/</A>
106
107LuaThread provides thread creation, mutexes, condition variables, and inter-
108thread queues to the Lua scripts. It takes a C-kind of approach, where Lua
109globals are shared by the threads running, and need therefore to be guarded
110against multithreading conflicts.
111
112Whether this is exactly what you want, or whether a more loosely implemented
113multithreading (s.a. Lanes) would be better, is up to you. One can argue that
114a loose implementation is easier for the developer, since no application level
115lockings need to be considered.
116
117Pros:
118 - no marshalling overhead, since threads share the same Lua state
119
120Cons:
121 - requires a modified Lua core
122 - application level locking required
123
124Sample:
125&lt;&lt;
126 local function flood(output, word)
127 while 1 do
128 output:lock()
129 io.write(word, ", ")
130 output:unlock()
131 end
132 end
133
134 local output = thread.newmutex()
135 thread.newthread(flood, {output, "child"})
136 flood(output, "parent")
137&lt;&lt;
138
139
140=============
141 Lua Rings (by Roberto Ierusalimschy &amp; Tom&aacute;s Guisasola)
142=============
143
144<A HREF="http://www.keplerproject.org/rings/">http://www.keplerproject.org/rings/</A>
145
146".. library which provides a way to create new Lua states from within Lua.
147It also offers a simple way to communicate between the creator (master) and
148the created (slave) states."
149
150".. master can execute code in any of its slaves but each slave only has
151access to its master (or its own slaves)."
152
153Rings offers separate Lua states, but no multithreading. This makes it simple,
154but it won't use more than one CPU core. Other differences include:
155
156 - opens all Lua standard libraries for subthreads
157 (Lanes opens the needed ones)
158
159 - marshalls numbers, strings, booleans, userdata
160 (Lanes marshalls also non-cyclic tables)
161
162 - "remotedostring" allows executing code in the master state
163 (Lanes does _not_ allow subthreads to trouble/modify master automatically,
164 to allow effective sandboxing. The same can be achieved by sending code
165 between the threads, but master needs to explicitly allow this = receive
166 a function and execute it)
167
168 - offers "Stable, a very simple API to manage a shared table at the master
169 state"
170 (Lanes 2008 offers keeper tables)
171
172Pros:
173 - "offers Stable, a very simple API to manage a shared table at the master
174 state"
175
176Cons:
177 - thread contents defined as strings, not Lua source as such; does not
178 give syntax check at file parsing, does not allow syntax highlight
179
180Sample:
181&lt;&lt;
182 require"rings"
183 S = rings.new ()
184
185 data = { 12, 13, 14, }
186 print (S:dostring ([[
187 aux = {}
188 for i, v in ipairs (arg) do
189 table.insert (aux, 1, v)
190 end
191 return unpack (aux)]], unpack (data))) -- true, 14, 13, 12
192
193 S:close ()
194&lt;&lt;
195
196
197==========================
198 Helper Threads Toolkit (by Javier Guerra G.)
199==========================
200
201<A HREF="http://luaforge.net/projects/helper-threads/">http://luaforge.net/projects/helper-threads/</A>
202
203"Provides a consistent framework to write non-blocking C libraries, with a Lua
204interface for starting tasks and managing the Futures, Queues and Threads."
205
206This seems like a companion of the "occasional threading" model (see below);
207Lua side is kept clear of multithreading, while C side can be "spawn" off to
208do things on the background.
209
210Pros:
211 - provides an "update" mechanism, allowing the (C) thread and controlling
212 Lua to interact during execution of the thread
213 - ...
214
215Cons:
216 - thread is "only for C code and it can't touch or access the Lua state",
217 in other words there is no Lua-side multithreading concept (by design)
218
219
220========================
221 Occasional threading (by Russ Cox)
222========================
223
224<A HREF="http://lua-users.org/lists/lua-l/2006-11/msg00368.html">http://lua-users.org/lists/lua-l/2006-11/msg00368.html</A>
225
226".. able to have certain C calls run in parallel with the [Lua] VM, but
227otherwise keep the VM single-threaded."
228
229That pretty much says it all.
230
231Pros:
232 - simple, yet providing for the "occasional" need to run really multithreaded
233 - can be made into a loadable module (says the message)
234
235Cons:
236 - only for occasional usage, the programming paradigm is still essentially
237 singlethreaded (by definition)
238 - not a real project, just a message on the Lua list (but a good one!)
239
240
241=================
242 ConcurrentLua
243=================
244
245<A TARGET="_blank" HREF="http://concurrentlua.luaforge.net/index.html"
246>http://concurrentlua.luaforge.net/index.html</A>
247
248ConcurrentLua is based on the Lua model for concurrency, namely coroutines, and
249extends this model by providing message-passing primitives.
250
251".. implementation of the share-nothing asynchronous message-passing model"
252
253".. process can check its mailbox for new messages at any time, and if there
254are any, they can be read in the order of arrival."
255
256".. processes in the system are implemented with Lua coroutines"
257
258".. still based on the cooperative multithreading model that Lua uses"
259
260Recent, released on 21 June 2008.
261
262Pros:
263 - From ground up designed for distributed computing (multiple computers,
264 not only CPU cores)
265 - Does not require a pre-emptive operating system
266
267Cons:
268 - Serialization must degrade raw performance in one-computer scenarios
269 (vs. stack-to-stack copying ala Lanes)
270 - Depends on LuaSocket and Copas modules.
271 - Each thread has a single mailbox tied to it (vs. separating threads and
272 connection resources)
273
274</pre>
275</td></tr></table>
276
277
278<!-- footnotes +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
279<hr/>
280
281<p>For feedback, questions and suggestions:
282<UL>
283 <li><A HREF="http://luaforge.net/projects/lanes">Lanes @ LuaForge</A></li>
284 <li><A HREF="mailto:akauppi@gmail.com">the author</A></li>
285</UL>
286</p>
287
288<!--
289<font size="-1">
290<p>
2911) ...
292</p>
293</font>
294-->
295
296</body>
297</html>