-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslideshow.nest
296 lines (253 loc) · 11.3 KB
/
slideshow.nest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!--[if lt IE 9]>
<script src="lib/html5shim.js"></script>
<![endif]-->
<!-- These are some core styles the slideshow app requires -->
<link rel="stylesheet" href="lib/styles.css" />
<!-- These are the styles you'll add to make the slides look great -->
<link rel="stylesheet" href="css/styles.css" />
<title>Go @ Barcamp Saigon</title>
</head>
<body>
<header>
<h1>Go @ Barcamp Saigon</h1>
<nav>
<ul>
<li><button id="prev-btn" title="Previous slide">Previous Slide</button></li>
<li><span id="slide-number"></span>/<span id="slide-total"></span></li>
<li><button id="next-btn" title="Next Slide">Next Slide</button></li>
</ul>
</nav>
</header>
<div id="deck">
<section>
\hgroup:
\h1 Concurrent programming with Go
\img[src=images/gophercolor.png class=mascot]
\p[class=center]:
"Using the websocket package, [...] was able to add the web
viewer on his train ride home."
\p[class=center]:
"We wrote [...] in two or three beers."
<footer>
\p July 24, 2011
\p by Trịnh Hải Anh, Web Server Engineer
\p <a href="http://twitter.com/chickamade">@chickamade</a> <a href="http://search.twitter.com/search?q=%23barcampsaigon">#barcampsaigon</a>
\p \a[href="http://skunkworks.vn" class=green] Skunkworks.vn
</footer>
</section>
<section>
\hgroup:
\h1 What is Go?
<ul>
\li Started at Google by Ken Thompson, Rob Pike, ...
\li Design philosophy: \span[class=green] less is more
\li Attractive model to write <span class=green>concurrent programs</span>
\li Originally focused on system projects: databases, networking servers
\li Has become a general purpose language
\li Makes programming sensible and fun!
</ul>
</section>
<section>
<hgroup>
\h1 Why Go?
\h2 Concurrency!
</hgroup>
<ul>
\li Writing multi-threaded programs is hard
\li Too much emphasis on low-level details: locks, mutexes, ...
\li Asynchronous event callbacks are just a crippled API, where your code run single-threaded :(
</ul>
</section>
<section>
\hgroup \h1 CSP
<ul>
<li>
In 1978, Tony Hoare introduced the theory of "Communicating Sequential Processes"
\blockquote \em Input, output, and concurrency should be regarded as primitives of programming
\blockquote \em Composition of communicating sequential processes is a fundamental program structuring method.
</li>
\li Occam and Erlang are two well-known languages that stem from CSP
</ul>
</section>
<section>
\hgroup \h1 Goroutines
<ul>
\li Goroutines are functions and methods executing concurrently in the same address space
\li It is practical to create hundreds of thousands of goroutines (each cost a few KB initially)
\li Goroutines are multiplexed onto a set of system threads
\li When a goroutine blocks, such as in a system call, the Go runtime automatically moves other goroutines to a spare thread
</ul>
</section>
<section>
\hgroup \h1 Channels
<ul>
\li Goroutines communicate via channels
\li Channel is the way of synchronization: the sender and receiver both unblocks at the rendezvous moment to exchange a datum
</ul>
</section>
<section>
\hgroup \h1 Concurrency primitives demo
<pre>
func main() {
c := make(chan string)
d := make(chan string)
go func() {
for {
c <- "msg" // sending blocks until there is a receiver
}
}()
go func() {
for {
d <- ("relayed " + <-c) // process received value, then send it out
}
}()
for {
select {
case val := <-c:
println(val)
case val := <-d:
println(val)
}
}
}
</pre>
\footer \a[target=_blank href="http://golang.org/doc/play/#package%20main%0A%0Afunc%20main%28%29%20%7B%0A%20%20%20%20%20%20c%20%3A%3D%20make%28chan%20string%29%0A%20%20%20%20%20%20d%20%3A%3D%20make%28chan%20string%29%0A%0A%20%20%20%20%20%20go%20func%28%29%20%7B%0A%20%20%20%20%20%20%20%20%20%20for%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20c%20%3C-%20%22msg%22%20//%20sending%20blocks%20until%20there%20is%20a%20receiver%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%28%29%0A%20%20%20%20%20%20go%20func%28%29%20%7B%0A%20%20%20%20%20%20%20%20%20%20for%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20d%20%3C-%20%28%22relayed%20%22%20%2B%20%3C-c%29%20//%20process%20received%20value%2C%20then%20send%20it%20out%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%28%29%0A%0A%20%20%20%20%20%20for%20%7B%0A%20%20%20%20%20%20%20%20%20%20select%20%7B%0A%20%20%20%20%20%20%20%20%20%20case%20val%20%3A%3D%20%3C-c%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20println%28val%29%0A%20%20%20%20%20%20%20%20%20%20case%20val%20%3A%3D%20%3C-d%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20println%28val%29%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%7D%0A"] Try this example in the Go playground!
</section>
<section>
\hgroup \h1 Select
<pre>
select {
case x = <-c:
// x was received from c
case d <- y:
// y was sent to d
default:
// non-blocking case
}
</pre>
<ul>
\li Every case must be a communication
\li If any communication can proceed, it does; others are ignored
\li If multiple cases are ready, one is selected to proceed at random, fairly
\li If there is no default case, the select statement blocks until one case can proceed
</ul>
</section>
<section>
\hgroup \h1 The Go Way
\blockquote \em Do not communicate by sharing memory. <br /> Instead, share memory by communicating.
<ul>
\li Shared values should be passed around on channels
\li Channel (or set of channels) defines a protocol of interaction with a given resource
\li E.g. Rob Pike built a concurrent window system represented by 3 channels: graphics, keyboard, mouse. The window system can run recursively on itself to implement a multi-window text editors
</section>
<section>
\hgroup \h1 A concurrent windows system
\img[src=images/cws.png style="margin: 20px 0 0 380px"]
\footer \p[class=small] Rob Pike, <a href="http://swtch.com/~rsc/thread/cws.pdf">"A Concurrent Window System,"</a> Computing Systems, 2(2)
</section>
<section>
\hgroup \h1 A TCP echo server
\p spawns multiple goroutines and also does informative logging :)
\pre
import ("net"; "io"; "os"; "log")
func die(err os.Error) {
if err != nil { log.Fatal(err) }
}
func main() {
server, err := net.Listen("tcp", "127.0.0.1:3640"); die(err)
for {
conn, err := server.Accept(); die(err)
go func() {
defer conn.Close()
n, err := io.Copy(conn, conn)
log.Printf("echoed %d byte to %s\\n", n, conn.RemoteAddr())
if err != nil {
log.Printf("error: %s", err)
}
}()
}
}
</pre>
\footer \a[target=_blank href=http://github.com/aht/barcamp2011-gonuts/blob/master/echosrv.go] http://github.com/aht/barcamp2011-gonuts/blob/master/echosrv.go
</section>
<section>
\hgroup \h1 Sequential goroutine but non-blocking I/O
<ul>
\li <code>epoll/kqueue</code> are kernel optimizations to deal with accepting ten thousands of connections (the C10K problem)
\li Many languages implement these system calls as libraries and expose to client a crippled callback API, leading to inefficient single-threaded spaghetti code
\li Go networking code use <code>epoll/kqueue</code> under the hood: server with goroutines can handle 10K concurrent clients
</ul>
\footer \a[href=http://www.kegel.com/c10k.html] http://www.kegel.com/c10k.html
</section>
<section>
\hgroup \h1 Go is a lot more than concurrency
<ul>
\li Duck typing: feels like Python
\li Segmented stack: stack overflow not possible
\li Static compilation, single binary deployment
\li Call C/C++ code
\li Run on bare hardware without OS
\li Tools: IDEs, goroutine-aware debugger, profiler, code formatter
\li Standard libraries: zip, jpeg, json, mime/multipart, utf8, websocket, ...
\li Package management: <code>goinstall github.com/user/project</code>
</ul>
</section>
<section>
\hgroup \h1 A few bits of history
<ul>
\li <em>1978</em>, C. A. R. Hoare, "Communicating Sequential Processes," Communications of the ACM 21(8)
\li <em>1983</em>, Occam, the first CSP language, runs on dedicated Transputer chip
\li <em>1985 – 1995</em>, Rob Pike & Ken Thompson worked on the Plan 9 OS (Unix's supposed successor) and several CSP-based languages
\li <em>1998</em>, Erlang open-source release
\li <em>2006</em>, Erlang gained support for SMP scheduling
\li <em>2009</em>, Go went nuts!
\li <em>July 2010</em>, an implementation of <code>select</code> was prototyped for the Stackless Python module in PyPy
</ul>
</section>
<section>
\hgroup \h1 Where to go from here?
<ul>
\li \a[href=http://golang.org/doc/go_tutorial.html] The official Go language tutorial
\li \a[href=http://golang.org/doc/codewalk/] Go codewalks
<li> <a href=http://groups.google.com/group/golang-nuts>golang-nuts</a> — the official mailing list
\li <a href=irc://freenode.org:6666/#go-nuts>#go-nuts</a> — IRC channel on freenode.org
</ul>
</section>
<section>
\hgroup \h1 Thank you! Questions?
<div class=twitter>
\img[src=images/followme.png]
\span[class=green] \a[href="http://twitter.com/chickamade" class=green] @chickamade
</div>
\p[class=padded\ center\ big] For more information about our company, visit <a href="http://skunkworks.vn/" class=green>Skunkworks.vn.</a> We are hiring!
\a[href=http://skunkworks.vn/] \img [src=images/skunkworks.png class=logo]
</section>
</div>
<!-- /deck -->
<script src="lib/jquery-1.5.2.min.js"></script>
<script src="lib/jquery.jswipe-0.1.2.js"></script>
<script src="lib/htmlSlides.js"></script>
<script>
//Do our business when the DOM is ready for us
$(function() {
//You can trigger Javascript based on the slide number like this:
$('html').bind('newSlide', function(e, id) {
switch(id) {
case 1:
case 10: $('body').removeClass('roctopus').addClass('loctopus');
break;
case 16: $('body').removeClass('loctopus roctopus');
break;
default: $('body').removeClass('loctopus').addClass('roctopus');
}
});
//One little option: hideToolbar (boolean; default = false)
htmlSlides.init({ hideToolbar: true });
});
</script>
</body>
</html>