- Machine Learning with Spark(Second Edition)
- Rajdeep Dua Manpreet Singh Ghotra Nick Pentreath
- 277字
- 2021-07-09 21:07:40
SparkContext and SparkConf
The starting point of writing any Spark program is SparkContext (or JavaSparkContext in Java). SparkContext is initialized with an instance of a SparkConf object, which contains various Spark cluster-configuration settings (for example, the URL of the master node).
It is a main entry point for Spark functionality. A SparkContext is a connection to a Spark cluster. It can be used to create RDDs, accumulators, and broadcast variables on the cluster.
Only one SparkContext is active per JVM. You must call stop(), which is the active SparkContext, before creating a new one.
Once initialized, we will use the various methods found in the SparkContext object to create and manipulate distributed datasets and shared variables. The Spark shell (in both Scala and Python, which is unfortunately not supported in Java) takes care of this context initialization for us, but the following lines of code show an example of creating a context running in the local mode in Scala:
val conf = new SparkConf()
.setAppName("Test Spark App")
.setMaster("local[4]")
val sc = new SparkContext(conf)
This creates a context running in the local mode with four threads, with the name of the application set to Test Spark App. If we wish to use the default configuration values, we could also call the following simple constructor for our SparkContext object, which works in the exact same way:
val sc = new SparkContext("local[4]", "Test Spark App")
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book from any other source, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
- Mastering Mesos
- 會聲會影X5視頻剪輯高手速成
- Managing Mission:Critical Domains and DNS
- 基于LPC3250的嵌入式Linux系統(tǒng)開發(fā)
- Mastering D3.js
- SharePoint 2010開發(fā)最佳實(shí)踐
- Troubleshooting OpenVPN
- 電腦上網(wǎng)輕松入門
- FPGA/CPLD應(yīng)用技術(shù)(Verilog語言版)
- 網(wǎng)絡(luò)管理工具實(shí)用詳解
- AI的25種可能
- Learning ServiceNow
- 典型Hadoop云計(jì)算
- Photoshop CS4數(shù)碼照片處理入門、進(jìn)階與提高
- ADuC系列ARM器件應(yīng)用技術(shù)