Sams Teach Yourself Spark in 24 Hours

2,287 491 43MB

English Pages 1229

Report DMCA / Copyright

DOWNLOAD FILE

Sams Teach Yourself Spark in 24 Hours

Table of contents :
About This E-Book......Page 2
Title Page......Page 3
Copyright Page......Page 4
Contents at a Glance......Page 6
Table of Contents......Page 8
Why Should I Learn Spark?......Page 16
Conventions Used in This Book......Page 17
About the Author......Page 19
Dedication......Page 20
Acknowledgments......Page 21
We Want to Hear from You......Page 22
Reader Services......Page 23
Part I: Getting Started with Apache Spark......Page 24
What Is Spark?......Page 25
Spark Is Fast, Efficient, and Scalable......Page 26
Programming Interfaces to Spark......Page 27
Ways to Use Spark......Page 29
Interactive Use......Page 30
Summary......Page 31
Quiz......Page 32
Answers......Page 33
Hadoop and a Brief History of Big Data......Page 34
Hadoop Explained......Page 35
HDFS Overview......Page 36
HDFS Architecture......Page 37
What Is YARN?......Page 43
Running an Application on YARN......Page 44
Anatomy of a Hadoop Cluster......Page 46
HDFS as a Data Source for Spark......Page 47
Summary......Page 48
Quiz......Page 49
Answers......Page 50
Spark Deployment Modes......Page 51
Getting Spark......Page 52
Installing a Multi-node Spark Standalone Cluster......Page 61
Exploring the Spark Install......Page 63
Deploying Spark on Hadoop......Page 64
Installing Manually......Page 65
Q&A......Page 68
Answers......Page 69
Exercises......Page 70
Anatomy of a Spark Application......Page 71
The Spark Context......Page 72
Application Scheduling......Page 73
Spark Executors and Workers......Page 74
Spark Master and Cluster Manager......Page 75
Spark Master......Page 76
ResourceManager as the Cluster Manager......Page 77
ApplicationsMaster as the Spark Master......Page 78
yarn-cluster Mode......Page 79
yarn-client Mode......Page 80
Local Mode......Page 82
Summary......Page 84
Quiz......Page 85
Answers......Page 86
Elastic Compute Cloud (EC2)......Page 87
AWS Pricing and Getting Started......Page 89
Spark on EC2......Page 90
Spark on EMR......Page 100
Hosted Spark with Databricks......Page 110
Summary......Page 119
Quiz......Page 120
Answers......Page 121
Part II: Programming with Apache Spark......Page 122
Introduction to RDDs......Page 123
Creating an RDD from a File or Files......Page 125
Creating an RDD from a Datasource......Page 133
Creating an RDD Programatically......Page 139
Operations on RDDs......Page 140
Transformations, Actions, and Lazy Evaluation......Page 141
RDD Persistence and Re-use......Page 142
RDD Lineage......Page 143
Fault Tolerance with RDDs......Page 145
Types of RDDs......Page 146
Summary......Page 147
Quiz......Page 148
Answers......Page 149
The Motivation for MapReduce......Page 150
Records and Key Value Pairs......Page 152
Key Value Pairs and Records......Page 153
MapReduce Explained......Page 154
Map Phase......Page 155
Partitioning Function......Page 156
Reduce Phase......Page 157
Combiner Functions......Page 158
Asymmetry and Speculative Execution......Page 159
Map-only MapReduce Applications......Page 160
An Election Analogy for MapReduce......Page 161
Why Count Words?......Page 162
How It Works......Page 163
Map and Reduce Functions in Spark......Page 165
Summary......Page 171
Quiz......Page 172
Answers......Page 173
Scala Beginnings......Page 174
Scala’s Compile Time and Run Time Architecture......Page 175
Variables and Primitives in Scala......Page 179
Data Structures in Scala......Page 181
Control Structures in Scala......Page 186
Classes and Inheritance......Page 191
Mixin Composition......Page 192
Singleton Objects......Page 193
Polymorphism......Page 194
Anonymous Functions......Page 195
Closures......Page 196
Lazy Evaluation......Page 197
Spark Programming in Scala......Page 198
Summary......Page 200
Workshop......Page 201
Answers......Page 202
Python Background......Page 203
Python Runtime Architecture......Page 204
Lists......Page 208
Tuples......Page 209
Dictionaries......Page 211
Python Object Serialization......Page 213
Anonymous Functions and lambda......Page 217
Higher-order Functions......Page 218
Short-circuiting......Page 219
Closures in Python......Page 220
IPython History and Background......Page 221
Using IPython with Spark......Page 223
Jupyter, the IPython Notebook......Page 226
Summary......Page 233
Quiz......Page 234
Answers......Page 235
RDD Refresher......Page 236
Data Sampling with Spark......Page 237
Functional Transformations......Page 238
Grouping, Sorting, and Distinct Functions......Page 241
Set Operations......Page 244
The collect, take, top, and first Actions......Page 246
The reduce and fold Actions......Page 248
The foreach Action......Page 250
Key Value Pair RDD Dictionary Functions......Page 251
Functional Key Value Pair RDD Transformations......Page 252
Grouping, Aggregation, Sorting, and Set Operations......Page 255
Join Transformations......Page 260
mean()......Page 272
variance()......Page 273
Summary......Page 274
Q&A......Page 275
Answers......Page 276
RDD Lineage Revisited......Page 277
RDD Storage Levels......Page 279
Caching RDDs......Page 281
Persisting RDDs......Page 282
Checkpointing RDDs......Page 285
Saving RDD Output......Page 289
Storage Formats......Page 290
Alluxio Architecture......Page 297
Alluxio as a Filesystem......Page 298
Alluxio for Off Heap RDD Persistence......Page 299
Summary......Page 300
Quiz......Page 301
Answers......Page 302
Broadcast Variables......Page 303
Broadcast Variable Creation and Usage......Page 304
Advantages of Broadcast Variables......Page 307
Accumulators......Page 309
Using Accumulators......Page 310
Custom Accumulators......Page 311
Uses for Accumulators......Page 312
Partitioning Overview......Page 315
Controlling Partitions......Page 316
Repartitioning Functions......Page 318
Partition-specific API Methods......Page 321
pipe()......Page 323
Summary......Page 324
Q&A......Page 325
Answers......Page 326
Part III: Extensions to Spark......Page 327
Background......Page 328
Hive Overview......Page 329
SQL on Hadoop......Page 334
Spark SQL Architecture......Page 335
HiveContext and SQLContext......Page 337
Creating a DataFrame from an Existing RDD......Page 339
Creating a DataFrame from a Hive Table......Page 340
Creating a DataFrame from JSON Objects......Page 341
Creating DataFrames from Files Using the DataFrameReader......Page 343
Converting DataFrames to RDDs......Page 346
DataFrame Schemas......Page 347
DataFrame Metadata Operations......Page 350
Basic DataFrame Operations......Page 351
DataFrame Built-in Functions and UDFs......Page 356
DataFrame Set Operations......Page 357
Caching, Persisting, and Repartitioning DataFrames......Page 360
Saving DataFrame Output Using the DataFrameWriter......Page 361
Accessing Spark SQL......Page 362
Running the Thrift JDBC/ODBC server......Page 363
Q&A......Page 367
Quiz......Page 368
Answers......Page 369
Streaming, Spark Style......Page 370
Spark Streaming Architecture......Page 371
The StreamingContext......Page 372
Using DStreams......Page 373
DStream Sources......Page 374
DStream Transformations......Page 376
DStream Output Operations......Page 379
updateStateByKey()......Page 383
Sliding Window Operations......Page 384
window()......Page 385
reduceByKeyAndWindow()......Page 386
Summary......Page 387
Quiz......Page 388
Answers......Page 389
Introduction to R......Page 390
Getting Started with the R Language......Page 391
The SparkR Shell......Page 397
Creating Data Frames in SparkR......Page 399
Building Predictive Models with SparkR......Page 402
Using SparkR with RStudio......Page 406
Summary......Page 408
Quiz......Page 409
Answers......Page 410
Machine Learning Primer......Page 411
Classification Using Spark MLlib......Page 415
Decision Trees......Page 416
Naive Bayes......Page 420
Collaborative Filtering Using Spark MLlib......Page 421
k-means Clustering......Page 424
Summary......Page 426
Q&A......Page 427
Answers......Page 428
H2O Deep Learning......Page 429
H2O Flow......Page 430
H2O Architecture......Page 431
Running H2O on Hadoop......Page 432
Sparkling Water—H2O on Spark......Page 435
Sparkling Water Architecture......Page 436
Summary......Page 445
Q&A......Page 446
Answers......Page 447
Introduction to Graphs......Page 448
Google, Pregel, and PageRank......Page 451
GraphX: Spark’s Graph Processing System......Page 452
Accessing the GraphFrames Library......Page 455
Creating a GraphFrame......Page 456
GraphFrame Operations......Page 457
Using Graphing Algorithms with GraphFrames......Page 460
Summary......Page 462
Q&A......Page 463
Answers......Page 464
Bigtable: The Beginnings of the NoSQL Movement......Page 466
NoSQL System Characteristics......Page 467
Types of NoSQL Systems......Page 468
HBase Data Model and Shell......Page 469
Data Distribution in HBase......Page 471
HBase and Spark......Page 472
Cassandra Data Model......Page 475
Cassandra Query Language (CQL)......Page 476
Accessing Cassandra Using Spark......Page 477
Using Spark with DynamoDB and More......Page 478
Amazon DynamoDB......Page 479
Summary......Page 480
Quiz......Page 481
Answers......Page 482
Overview of Messaging Systems......Page 483
Pub-Sub Messaging Exchange Pattern......Page 484
Kafka Overview......Page 485
Spark and Kafka......Page 487
Spark, MQTT, and the Internet of Things......Page 494
MQTT Overview......Page 495
Using Spark with MQTT......Page 496
Using Spark with Amazon Kinesis......Page 497
Kinesis Streams......Page 498
Using Spark with Kinesis......Page 500
Summary......Page 502
Q&A......Page 503
Answers......Page 504
Part IV: Managing Spark......Page 505
Spark Environment Variables......Page 506
Spark Configuration......Page 511
Administering Spark Standalone......Page 515
Spark Standalone Revisited......Page 516
Deploying Spark Standalone Clusters......Page 517
Scheduling with Spark Standalone......Page 525
Spark on YARN Revisited......Page 527
Deploying Spark on YARN......Page 528
Managing Spark Applications Running on YARN......Page 529
YARN Scheduling......Page 531
Summary......Page 532
Q&A......Page 533
Answers......Page 534
Exploring the Spark Application UI......Page 535
Jobs......Page 536
Stages......Page 538
Storage......Page 540
Environment......Page 541
Executors......Page 542
Spark History Server......Page 543
Exploring the Spark History Server UI......Page 544
Spark History Server API Access......Page 545
Spark Metrics......Page 546
Logging in Spark......Page 548
Log4j......Page 549
Q&A......Page 555
Quiz......Page 556
Answers......Page 557
Isolating Spark......Page 558
Perimeter Security......Page 559
Authentication and Authorization......Page 560
Spark Authentication Using a Shared Secret......Page 561
Encrypting Spark Communication......Page 563
Securing the Spark Web UI......Page 568
Kerberos Overview......Page 570
Kerberos with Hadoop......Page 572
Kerberos Configuration with Spark......Page 573
Q&A......Page 574
Quiz......Page 575
Answers......Page 576
Benchmarks......Page 577
Performance Monitoring Solutions......Page 583
Application Development Optimizations......Page 584
System, Configuration, or Job Submission Optimizations......Page 589
Inefficient Partitioning......Page 592
Using the Application UI to Diagnose Performance Issues......Page 594
Summary......Page 597
Q&A......Page 598
Answers......Page 599
Index......Page 600
Code Snippets......Page 689

Polecaj historie