-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.html
executable file
·628 lines (620 loc) · 27 KB
/
index.html
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>The Power and Elegance of Reflection</title>
<meta name="description" content="GopherCon 2016">
<meta name="author" content="Emily Gu">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<!-- favicon icons -->
<link rel="apple-touch-icon" sizes="57x57" href="favicon/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="favicon/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="favicon/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="favicon/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="favicon/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="favicon/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="favicon/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="favicon/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="favicon/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="favicon/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="favicon/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
<link rel="manifest" href="favicon/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="favicon/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<!-- end favicon code -->
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/beige.css" id="theme">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
});
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
<!-- these are my custom styles. remember that slide sizes scale, so try to use percentages. -->
<style>
p.alignLeft {
text-align: left;
}
span.orange, a.orange {
color: orange;
outline-color: gray;
}
div.innovation ul li {
margin-bottom:12px;
}
figcaption {
font-size:.8em;
}
p.miscItems {
font-size:1.2em;
}
.slides section h3 {
color: orange !important; outline: gray;
}
.slides img.shortened {
max-width: 80%;
max-height: 80%;
}
#upcoming-slide .label {
color: #444 !important
}
ul.credits li {
font-size: .6em;
}
</style>
<!-- Note: Make artboard sizes about 775px wide X 445px tall. If the image appears as a vertical navigation, add a class of "shortened" to the image element to reduce its size to 80% -->
</head>
<body>
<div class="reveal innovation">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>The Power and Elegance of <br/><span class="orange">Reflection</span></h1>
<h3><span style="color:black">GopherCon 2016</span></h3>
<p>
<small>Created by <a href="https://github.com/candysmurf">Emily Gu</a> / <a href="https://twitter.com/CandySmurfy">@CandySmurfy</a></small>
</p>
<p><small>https://candysmurf.github.io/GoReflectionTalk</small></p>
<aside class="notes">
<p>- I'm working at Intel SDI-X group</p>
<p>- My first time in GohpherCon.</p>
<p>- First time giving this presentation</p>
</aside>
</section>
<section>
<h2>Keyboard Shortcuts</h2>
<table>
<tr>
<td><b>Full Screen</b></td>
<td>F</td>
</tr>
<tr>
<td><b>Next Slide</b></td>
<td>Space bar</td>
</tr>
<tr>
<td><b>Slide Notes</b></td>
<td>S</td>
</tr>
<tr>
<td><b>Thumbnail View</b></td>
<td>Esc</td>
</tr>
</table>
<p><small>View online at <a href="https://github.com/candysmurf/GoReflectionTalk">https://github.com/candysmurf/GoReflectionTalk </a></small><br/>
<small><i><b>Note:</b> Some slides move down instead of to the side, so use the space bar to advance slides.</i></small></p>
<aside class="notes">
<p>This is the speaker notes view.</p>
<p>Notice the navigation arrows in the lower corner.</p>
</aside>
</section>
<section>
<h2>About Me</h2>
<h3 class="fragment">Today is about Reflection in Go</h3>
<p align="left">
I currently work for Intel Corporation as a cloud software engineer in the Software Defined Infrastructure (SDI-X) Emerging Tech group.
</p>
<p style="color:#1b91ff">
William Kennedy is my teacher for Go. His "mechanical sympathy" truly inspired me.
</p>
<p align="right" style="color:gray">
Prior to Go, I used Java, Spring Framework, RabbitMQ, Cassandra, Logstash, Elasticsearch...and worked on ECommerce, Big Data and Analytics.
</p>
</section>
<section>
<h2>Why I choose to talk about Reflection</h2>
<section>
<h3>My Project is Snap</h3>
<img src="media/gophers/snap-job.png" height="480"/>
</section>
<section>
<h3>Snap Plugin Framework</h3>
<img src="media/gophers/snap-plugin.png" height="400"/>
<aside class="notes">
<p>- Collector, Processor, Publishers.</p>
</aside>
</section>
<section>
<h3>Collector Challenges</h3>
<img src="media/gophers/problem.png" />
</section>
<section>
<h3>Sample JSON</h3>
<pre><code>
{
"cluster_name": "elasticsearch",
"nodes": {
"jhO6RS8ORjOKfNP6pvwaBw": {
"timestamp": 1467525122508,
"name": "Superia",
"transport_address": "10.0.2.15:9300",
"host": "10.0.2.15",
"os": {
"timestamp": 1467525122530,
"cpu_percent": 30,
"load_average": 0.42,
"mem": {
"total_in_bytes": 1044631552,
"free_in_bytes": 65638400,
"used_in_bytes": 978993152,
"free_percent": 6,
"used_percent": 94
},
"swap": {
"total_in_bytes": 1211777024,
"free_in_bytes": 1199104000,
"used_in_bytes": 12673024
}
},
"process": {
"timestamp": 1467525122530,
"open_file_descriptors": 151,
"max_file_descriptors": 1048576,
"cpu": {
"percent": 4,
"total_in_millis": 5690
},
"mem": {
"total_virtual_in_bytes": 3219476480
}
},
"jvm": {
"timestamp": 1467525122530,
"uptime_in_millis": 42797,
"mem": {
"heap_used_in_bytes": 55298680,
"heap_used_percent": 5,
"heap_committed_in_bytes": 259719168,
"heap_max_in_bytes": 1065025536,
"non_heap_used_in_bytes": 44241384,
"non_heap_committed_in_bytes": 45834240,
"pools": {
"young": {
"used_in_bytes": 36094712,
"max_in_bytes": 69795840,
"peak_used_in_bytes": 69795840,
"peak_max_in_bytes": 69795840
},
"survivor": {
"used_in_bytes": 8716280,
"max_in_bytes": 8716288,
"peak_used_in_bytes": 8716280,
"peak_max_in_bytes": 8716288
},
"old": {
"used_in_bytes": 10487688,
"max_in_bytes": 986513408,
"peak_used_in_bytes": 10487688,
"peak_max_in_bytes": 986513408
}
}
},
"threads": {
"count": 33,
"peak_count": 36
},
"gc": {
"collectors": {
"young": {
"collection_count": 4,
"collection_time_in_millis": 76
},
"old": {
"collection_count": 1,
"collection_time_in_millis": 16
}
}
},
"buffer_pools": {
"direct": {
"count": 13,
"used_in_bytes": 3022957,
"total_capacity_in_bytes": 3022957
},
"mapped": {
"count": 0,
"used_in_bytes": 0,
"total_capacity_in_bytes": 0
}
},
"classes": {
"current_loaded_count": 6603,
"total_loaded_count": 6603,
"total_unloaded_count": 0
}
}
}
}
</code></pre>
</section>
<section>
<h3>Sample Metrics</h3>
<pre><code>
/intel/es/node/*/mem/heap_used_in_bytes 55298680
/intel/es/node/*/mem/heap_max_in_bytes 1065025536
/intel/es/node/*/jvm/mem/pools/young/used_in_bytes 36094712
/intel/es/node/*/jvm/mem/pools/survivor/used_in_bytes 8716280
/intel/es/node/*/jvm/mem/pools/old/used_in_bytes 10487688
/intel/es/node/*/os/swap/total_in_bytes 1211777024
/intel/es/node/*/fs/data/total_in_bytes 19507089408
</code></pre>
<img class="fragment" src="media/gophers/generic-collector.png" width="90%"/>
</section>
</section>
<section>
<h2>Reflection</h2>
<section>
<h3>Definition</h3>
<blockquote>
Reflection in computing is the ability of a program to examine its own structure, particularly through types;
it's a form of metaprogramming.
<br/><br/>— Rob Pike at The Laws of Reflection
</blockquote>
<aside class="notes">
<p>- inspection of meta-data, struct, fields, values, maps, interfaces, methods, functions at runtime without knowing the names</p>
<p>- instantiation of new objects and invocation of methods</p>
</aside>
</section>
<section>
<h3>Quote</h3>
<blockquote>
It's a powerful tool that should be used with care and avoided unless strictly necessary.
<br/><br/>— Rob Pike at The Laws of Reflection
</blockquote>
</section>
</section>
<section>
<h2>Reflection</h2>
<h3>Should I use Reflection?</h3>
<img src="media/gophers/gopher-ok-no.png" />
<aside class="notes">
<p>- Reflection is perceived to not be used due to its performance.</p>
<p>- Raise your hand how many of you have used Reflection in your work.</p>
</aside>
</section>
<section>
<h2>Community</h2>
<h3>Quotes</h3>
<blockquote>"
Compared to a disk seek or network transfer, the cost of reflection will be negligible."
<br/><br/>— Dave Cheney
</blockquote>
<br/>
<blockquote style="color:#1b91ff">"
Integrity, Readability, Simplicity first!
"
<br/><br/>— William Kennedy
</blockquote>
<aside class="notes">
<p>- Do not even consider the performance before you have integrity, readability and simplicity.</p>
</aside>
</section>
<section>
<h2>Integrity</h2>
<h3 class="fragment">REFLECTION PROVIDES INTEGRITY</h3>
<ul>
<li>Read and write to memory with accuracy</li>
<li>Perform behavior with consistency</li>
</ul>
<br/>
<img src="media/gophers/address-bus.png" width="700" height="300"/>
<aside class="notes">
<p>- including authentication and authorization.</p>
</aside>
</section>
<section>
<h2>Readbility</h2>
<h3 class="fragment">Reflection provides Readability</h3>
<ul>
<li>Understanding what the code is doing</li>
<li>Understanding the cost of the code</li>
</ul>
<pre><code>
func MultiplyBy2(x int) int {
return x * 2
}
func FastMultiplyBy2(x int) int {
return x << 1
}
</code></pre>
<blockquote>
"Premature Optimizations and Programming Myths are The Root of all Evil"
<br/><small>— Alvaro Videla 2015</small>
</blockquote>
<aside class="notes">
<p>- No more no less but clear and readable</p>
<p>- Less LOC does not mean it's readable</p>
<p>- More lines of code could help to read</p>
</aside>
</section>
<section>
<h2>Simplicity</h2>
<h3 class="fragment">Reflection provides Simplicity</h3>
<ul>
<li>Algorithm Efficiency</li>
<li>Not Wasting Effort</li>
</ul>
<br/>
<img src="media/gophers/complexity.png" height="200" />
<blockquote class="fragment orange">
<span class="fragment highlight-blue">
Without Reflection, you'll have to write different code for every type when doing
data transformation or resource injection.
</span>
</blockquote>
<aside class="notes">
<p>- Reflection is the best tool for data transformation.</p>
<p>- I'm one kind of resources.</p>
</aside>
</section>
<section>
<section data-background="media/vectors/innovation_scalability.svg">
<h3>Reflection - Key Enabler</h3>
<ul>
<li>Object Relational Mapping (ORM)</li>
<li>Dependency Injection Framework (IoC)</li>
<li>Plugin Framework</li>
<li>Data Transformation</li>
<li>Testing Framework</li>
</ul>
<pre class="fragment"><code>
"fmt"
"encoding/json"
"encoding/xml"
"text/template"
"html/template"
</code></pre>
</section>
</section>
<section data-background="media/vectors/innovation_scalability.svg"/>
<h2>Dive into Reflection</h2>
<section>
<h3>Reflection Basics</h3>
<ul>
<li>Map</li>
<li>Pointer</li>
<li>Slice</li>
<li>Struct</li>
</ul>
<br/><br/>
<a target="blank" href="https://github.com/candysmurf/GoReflectionTalk"><img src="media/gophers/21.png" height="200px" width="350px"/></a></figcaption>
<aside class="notes">
<p>- Learn Go Reflection.</p>
</aside>
</section>
<section>
<h3>Reflection Interface</h3>
<ul>
<li>Map</li>
<li>Pointer</li>
<li>Slice</li>
<li>Struct</li>
</ul>
<br/><br/>
<a target="blank" href="https://github.com/candysmurf/GoReflectionTalk"><img src="media/gophers/19.png" height="200px" width="350px"/></a>
</section>
<section>
<h3>Reflection Inspection</h3>
<ul>
<li>Integer</li>
<li>Struct</li>
</ul>
<br/><br/>
<a target="blank" href="https://github.com/candysmurf/GoReflectionTalk"><img src="media/gophers/22.png" height="200px" width="350px"/></a>
</section>
<section>
<blockquote style="color:gray">
Go Reflection package provides robust operations on kinds and values during the run-time.
</blockquote>
<blockquote class="fragment" style="color:orange">
Readability and Simplicity
</blockquote>
<!--<blockquote class="fragment" style="color:gray">
An empty interface can hold any value and contains all the information about a value.
</blockquote>-->
<blockquote class="fragment" style="color:orange">
Integrity
</blockquote>
</section>
</section>
<section>
<h2>Reflection Case Study</h2>
<section data-background="media/vectors/innovation_code.svg">
<h3>snap-plugin-collector-redfish</h3>
<table>
<tr><td><a target="blank" href="http://redfish.dmtf.org/redfish/v1/mockup/199">Redfish API</a></td></tr>
</table>
<blockquote>
"DMTF’s Redfish™ is an open industry standard specification and schema that specifies a RESTful interface
and utilizes JSON and OData to help customers integrate solutions within their existing tool chains."
<br/><br/>— redfish.dmtf.org
</blockquote>
</section>
<section data-background="media/vectors/innovation_code.svg">
<h3>snap-plugin-collector-redfish</h3>
<table align="left">
<tr><td>/intel/redfish/v1/Systems/*/Processors/*/TotalCores</td></tr>
<tr><td>/intel/redfish/v1/Systems/*/ProcessorSummary/Count</td></tr>
<tr><td>/intel/redfish/v1/Chassis/*/Thermal/Temperatures/*/UpperThresholdNonCritical</td></tr>
<tr><td>/intel/redfish/v1/Chassis/*/Thermal/Temperatures/*/MinReadingRange</td></tr>
<tr><td>/intel/redfish/v1/Chassis/*/Thermal/Temperatures/*/UpperThresholdFatal</td></tr>
</table>
</section>
<section data-background="media/vectors/innovation_code.svg">
<h3>snap-plugin-collector-redfish</h3>
<table>
<tr>
<td><b>Reflection:</b></td>
<td><a target="blank", href="https://github.com/intelsdi-x/snap-plugin-collector-redfish/blob/master/redfish/client.go#L260">Code</a></td>
</tr>
</table>
<pre><code>
// traversal goes through all reachable pages and builds up the metrics
func (rc *redfishClient) traversal(uri string, data map[string]interface{}) error {
for k, v := range data {
// skips the null value
typ := reflect.TypeOf(v)
if typ == nil {
continue
}
switch typ.Kind() {
case reflect.String:
rc.AllPoints = append(rc.AllPoints, plugin.MetricType{
Namespace_: core.NewNamespace(strings.Split(Intel+uri+Slash+k, Slash)...),
Data_: v,
Unit_: typ.Kind().String(),
Timestamp_: time.Now(),
})
if k == APIKey {
val := reflect.ValueOf(v).String()
if _, ok := rc.visitedURIs[val]; !ok {
err := rc.drilldownMetricData(val)
if err != nil {
return err
}
}
}
case reflect.Slice:
s := reflect.ValueOf(v)
for i := 0; i < s.Len(); i++ {
switch reflect.TypeOf(s.Index(i)).Kind() {
case reflect.Struct:
if s.Index(i).Elem().Kind() == reflect.Map {
rc.traversal(uri+Slash+k+Slash+strconv.Itoa(i), s.Index(i).Interface().(map[string]interface{}))
} else {
rc.AllPoints = append(rc.AllPoints, plugin.MetricType{
Namespace_: core.NewNamespace(strings.Split(Intel+uri+Slash+k+Slash+strconv.Itoa(i), Slash)...),
Data_: s.Index(i).Interface(),
Unit_: typ.Kind().String(),
Timestamp_: time.Now(),
})
}
default:
redfishLogger.WithFields(log.Fields{
"_block": "traversal",
"key": k,
"data": v,
"type": s.Index(i).Type().Kind(),
}).Info("redfish client traversals reachable data points")
}
}
case reflect.Map:
rc.traversal(uri+"/"+k, v.(map[string]interface{}))
default:
rc.AllPoints = append(rc.AllPoints, plugin.MetricType{
Namespace_: core.NewNamespace(strings.Split(Intel+uri+Slash+k, Slash)...),
Data_: v,
Unit_: typ.Kind().String(),
Timestamp_: time.Now(),
})
}
}
return nil
}
</code></pre>
<aside class="notes">
<p>- Arbitrary representation.</p>
<p>- Changing representation.</p>
<p>- Runtime update.</p>
</aside>
</section>
</section>
<section>
<h2>Demo</h2>
<h3>Snap Data Transformation</h3>
<img src="media/gophers/snap-gophercon2016-demo.png" height="480"/>
</section>
<section>
<h2>The End</h2>
<h3>Use Reflection when it's the best tool for the job</h3>
<ul>
<li>Reflection provides integrity, readability, and simplicity.</li>
<li>Reflection is a perfect use case for transforming data into different formats.</li>
<li>Reducing complexity while preserving maintainability must always be a priority.</li>
<li class="fragment highlight-blue">You can learn reflection by writing your own plugins to Snap!</li>
</ul>
<aside class="notes">
<p>- The last thing you want is for everyone to think the same way.</p>
<p>- I would like you to benchmark solutions and see if the performance is acceptable</p>
</aside>
</section>
<section>
<h1>Thanks!</h1>
<section>
<h3>Contact info</h3>
<ul>
<li>Twitter: <a class="orange" href="https://twitter.com/CandySmurfy">@CandySmurfy</a></li>
<li>GitHub: <a class="orange" href="https://github.com/candysmurf/GoReflectionTalk">github.com/candysmurf/GoReflectionTalk</a></li>
<li>Email: <a class="orange" href="mailto:[email protected]">[email protected]</a></li>
</ul>
</section>
<section>
<h3>Acknowledgement</h3>
<ul>
<li>William Kennedy @goinggodotnet</li>
<li>Snap Team @github.com/intelsdi-x/snap</li>
<li>Images from http://intelsdi-x.github.io/snap</li>
<li>reveal.js template</li>
</ul>
</section>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: false,
slideNumber: true,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, condition: function() { return !!document.querySelector( 'pre code' ); }, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true },
{ src: 'plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>