{"rsdb":{"rid":"309137","subhead":"","postdate":"0","aid":"224299","fid":"116","uid":"1","topic":"1","content":"
\n \n \n
\n
\n\t\t

\n\t\t\tSpark\u4e4b Spark Streaming\u6d41\u5f0f\u5904\u7406<\/a>\n\t\t<\/h1>\n\t\t
<\/div>\n\t\t
\n\t\t\t

SparkStreaming<\/h2>\n

\u3000\u3000Spark Streaming\u7c7b\u4f3c\u4e8eApache Storm\uff0c\u7528\u4e8e\u6d41\u5f0f\u6570\u636e\u7684\u5904\u7406\u3002Spark Streaming\u6709\u9ad8\u541e\u5410\u91cf\u548c\u5bb9\u9519\u80fd\u529b\u5f3a\u7b49\u7279\u70b9\u3002Spark Streaming\u652f\u6301\u7684\u6570\u636e\u6e90\u6709\u5f88\u591a\uff0c\u4f8b\u5982\uff1aKafka\u3001Flume\u3001Twitter\u3001ZeroMQ\u548c\u7b80\u5355\u7684TCP\u5957\u63a5\u5b57\u7b49\u7b49\u3002\u6570\u636e\u8f93\u5165\u540e\u53ef\u4ee5\u7528Spark\u7684\u9ad8\u5ea6\u62bd\u8c61\u64cd\u4f5c\u5982\uff1amap\u3001reduce\u3001join\u3001window\u7b49\u8fdb\u884c\u8fd0\u7b97\u3002\u800c\u7ed3\u679c\u4e5f\u80fd\u4fdd\u5b58\u5728\u5f88\u591a\u5730\u65b9\uff0c\u5982HDFS\uff0c\u6570\u636e\u5e93\u7b49\u3002<\/p>\n

\"\"<\/p>\n

\u7279\u6027<\/h3>\n
\n
1\u3001\u6613\u7528\u6027\n\u53ef\u4ee5\u50cf\u7f16\u5199\u79bb\u7ebf\u6279\u5904\u7406\u4e00\u6837\u53bb\u5f00\u53d1\u6d41\u5f0f\u7684\u5904\u7406\u7a0b\u5e8f\uff0c\u5e76\u4e14\u53ef\u4ee5\u4f7f\u7528java<\/a><\/span>\/scala\/Python\u8bed\u8a00\u8fdb\u884c\u4ee3\u7801\u5f00\u53d1\n<\/span>2\u3001\u5bb9\u9519\u6027\nSparkStreaming\u5728\u6ca1\u6709\u989d\u5916\u4ee3\u7801\u548c\u914d\u7f6e\u7684\u60c5\u51b5\u4e0b\u53ef\u4ee5\u6062\u590d\u4e22\u5931\u7684\u5de5\u4f5c\u3002\n<\/span>3\u3001\u53ef\u4ee5\u878d\u5408\u5230spark\u751f\u6001\u7cfb\u7edf\nsparkStreaming\u6d41\u5f0f\u5904\u7406\u53ef\u4ee5\u8ddf\u6279\u5904\u7406\u548c\u4ea4\u4e92\u5f0f\u67e5\u8be2\u76f8\u7ed3\u5408<\/span><\/pre>\n<\/div>\n


\u4e0estorm\u5bf9\u6bd4<\/h3>\n

storm\u662f\u6765\u4e00\u6761\u6570\u636e\u5904\u7406\u4e00\u6761\u6570\u636e\uff0cSparkStreaming\u662f\u4ee5\u67d0\u4e00\u65f6\u95f4\u95f4\u9694\u6279\u91cf\u5904\u7406\u6570\u636e\u3002<\/p>\n

<\/p>\n

SparkStreaming\u539f\u7406<\/h3>\n

Spark Streaming \u662f\u57fa\u4e8espark\u7684\u6d41\u5f0f\u6279\u5904\u7406\u5f15\u64ce\uff0c\u5176\u57fa\u672c\u539f\u7406\u662f\u628a\u8f93\u5165\u6570\u636e\u4ee5\u67d0\u4e00\u65f6\u95f4\u95f4\u9694\u6279\u91cf\u7684\u5904\u7406\uff0c\u5f53\u6279\u5904\u7406\u95f4\u9694\u7f29\u77ed\u5230\u79d2\u7ea7\u65f6\uff0c\u4fbf\u53ef\u4ee5\u7528\u4e8e\u5904\u7406\u5b9e\u65f6\u6570\u636e\u6d41\u3002<\/p>\n

\u8ba1\u7b97\u6d41\u7a0b<\/p>\n

\n
Spark Streaming\u662f\u5c06\u6d41\u5f0f\u8ba1\u7b97\u5206\u89e3\u6210\u4e00\u7cfb\u5217\u77ed\u5c0f\u7684\u6279\u5904\u7406\u4f5c\u4e1a\u3002\u8fd9\u91cc\u7684\u6279\u5904\u7406\u5f15\u64ce\u662fSpark Core\uff0c\u4e5f\u5c31\u662f\u628aSpark Streaming\u7684\u8f93\u5165\u6570\u636e\u6309\u7167batch size\uff08\u59821\u79d2\uff09\u5206\u6210\u4e00\u6bb5\u4e00\u6bb5\u7684\u6570\u636e\uff08Discretized Stream\uff09\uff0c
\u6bcf\u4e00\u6bb5\u6570\u636e\u90fd\u8f6c\u6362\u6210Spark\u4e2d\u7684RDD\uff08Resilient Distributed Dataset\uff09\uff0c\u7136\u540e\u5c06Spark Streaming\u4e2d\u5bf9DStream\u7684Transformation\u64cd\u4f5c\u53d8\u4e3a\u9488\u5bf9Spark\u4e2d\u5bf9RDD\u7684Transformation\u64cd\u4f5c\uff0c
\u5c06RDD\u7ecf\u8fc7\u64cd\u4f5c\u53d8\u6210\u4e2d\u95f4\u7ed3\u679c\u4fdd\u5b58\u5728\u5185\u5b58\u4e2d\u3002\u6574\u4e2a\u6d41\u5f0f\u8ba1\u7b97\u6839\u636e\u4e1a\u52a1\u7684\u9700\u6c42\u53ef\u4ee5\u5bf9\u4e2d\u95f4\u7684\u7ed3\u679c\u8fdb\u884c\u7f13\u5b58\u6216\u8005\u5b58\u50a8\u5230\u5916\u90e8\u8bbe\u5907\u3002\u4e0b\u56fe\u663e\u793a\u4e86Spark Streaming\u7684\u6574\u4e2a\u6d41\u7a0b\u3002<\/span><\/pre>\n<\/div>\n

\"\"<\/p>\n

<\/p>\n

\u5bb9\u9519\u6027<\/p>\n

\n
\u5bf9\u4e8e\u6d41\u5f0f\u8ba1\u7b97\u6765\u8bf4\uff0c\u5bb9\u9519\u6027\u81f3\u5173\u91cd\u8981\u3002\u9996\u5148\u6211\u4eec\u8981\u660e\u786e\u4e00\u4e0bSpark\u4e2dRDD\u7684\u5bb9\u9519\u673a\u5236\u3002\u6bcf\u4e00\u4e2aRDD\u90fd\u662f\u4e00\u4e2a\u4e0d\u53ef\u53d8\u7684\u5206\u5e03\u5f0f\u53ef\u91cd\u7b97\u7684\u6570\u636e\u96c6\uff0c\u5176\u8bb0\u5f55\u7740\u786e\u5b9a\u6027\u7684\u64cd\u4f5c\u7ee7\u627f\u5173\u7cfb\uff08lineage\uff09\uff0c
\u6240\u4ee5\u53ea\u8981\u8f93\u5165\u6570\u636e\u662f\u53ef\u5bb9\u9519\u7684\uff0c\u90a3\u4e48\u4efb\u610f\u4e00\u4e2aRDD\u7684\u5206\u533a\uff08Partition\uff09\u51fa\u9519\u6216\u4e0d\u53ef\u7528\uff0c\u90fd\u662f\u53ef\u4ee5\u5229\u7528\u539f\u59cb\u8f93\u5165\u6570\u636e\u901a\u8fc7\u8f6c\u6362\u64cd\u4f5c\u800c\u91cd\u65b0\u7b97\u51fa\u7684\u3002<\/pre>\n<\/div>\n

\u5b9e\u65f6\u6027<\/p>\n

\n
\u5bf9\u4e8e\u5b9e\u65f6\u6027\u7684\u8ba8\u8bba\uff0c\u4f1a\u7275\u6d89\u5230\u6d41\u5f0f\u5904\u7406\u6846\u67b6\u7684\u5e94\u7528\u573a\u666f\u3002Spark Streaming\u5c06\u6d41\u5f0f\u8ba1\u7b97\u5206\u89e3\u6210\u591a\u4e2aSpark Job\uff0c\u5bf9\u4e8e\u6bcf\u4e00\u6bb5\u6570\u636e\u7684\u5904\u7406\u90fd\u4f1a\u7ecf\u8fc7Spark DAG\u56fe\u5206\u89e3\u4ee5\u53caSpark\u7684\u4efb\u52a1\u96c6\u7684\u8c03\u5ea6\u8fc7\u7a0b\u3002
\u5bf9\u4e8e\u76ee\u524d\u7248\u672c\u7684Spark Streaming\u800c\u8a00\uff0c\u5176\u6700\u5c0f\u7684Batch Size\u7684\u9009\u53d6\u57280.5~2\u79d2\u949f\u4e4b\u95f4\uff08Storm\u76ee\u524d\u6700\u5c0f\u7684\u5ef6\u8fdf\u662f100ms\u5de6\u53f3\uff09\uff0c
\u6240\u4ee5Spark Streaming\u80fd\u591f\u6ee1\u8db3\u9664\u5bf9\u5b9e\u65f6\u6027\u8981\u6c42\u975e\u5e38\u9ad8\uff08\u5982\u9ad8\u9891\u5b9e\u65f6\u4ea4\u6613\uff09\u4e4b\u5916\u7684\u6240\u6709\u6d41\u5f0f\u51c6\u5b9e\u65f6\u8ba1\u7b97\u573a\u666f\u3002<\/pre>\n<\/div>\n

<\/p>\n

DStream<\/h3>\n

\u3000\u3000Discretized Stream\u662fSpark Streaming\u7684\u57fa\u7840\u62bd\u8c61\uff0c\u4ee3\u8868\u6301\u7eed\u6027\u7684\u6570\u636e\u6d41\u548c\u7ecf\u8fc7\u5404\u79cdSpark\u7b97\u5b50\u64cd\u4f5c\u540e\u7684\u7ed3\u679c\u6570\u636e\u6d41\u3002\u5728\u5185\u90e8\u5b9e\u73b0\u4e0a\uff0cDStream\u662f\u4e00\u7cfb\u5217\u8fde\u7eed\u7684RDD\u6765\u8868\u793a\u3002\u6bcf\u4e2aRDD\u542b\u6709\u4e00\u6bb5\u65f6\u95f4\u95f4\u9694\u5185\u7684\u6570\u636e\uff0c\u5982\u4e0b\u56fe\uff1a<\/p>\n

\"\"<\/p>\n

\u5bf9\u6570\u636e\u7684\u64cd\u4f5c\u4e5f\u662f\u6309\u7167RDD\u4e3a\u5355\u4f4d\u6765\u8fdb\u884c\u7684<\/p>\n

\"\"<\/p>\n

\u3000\u3000Spark Streaming\u4f7f\u7528\u6570\u636e\u6e90\u4ea7\u751f\u7684\u6570\u636e\u6d41\u521b\u5efaDStream\uff0c\u4e5f\u53ef\u4ee5\u5728\u5df2\u6709\u7684DStream\u4e0a\u4f7f\u7528\u4e00\u4e9b\u64cd\u4f5c\u6765\u521b\u5efa\u65b0\u7684DStream\u3002<\/p>\n

\u3000\u3000\u5b83\u7684\u5de5\u4f5c\u6d41\u7a0b\u50cf\u4e0b\u9762\u7684\u56fe\u6240\u793a\u4e00\u6837\uff0c\u63a5\u53d7\u5230\u5b9e\u65f6\u6570\u636e\u540e\uff0c\u7ed9\u6570\u636e\u5206\u6279\u6b21\uff0c\u7136\u540e\u4f20\u7ed9Spark Engine\u5904\u7406\u6700\u540e\u751f\u6210\u8be5\u6279\u6b21\u7684\u7ed3\u679c\u3002<\/p>\n

\"\"<\/p>\n

DStream\u76f8\u5173\u64cd\u4f5c<\/h3>\n

\u3000\u3000DStream\u4e0a\u7684\u64cd\u4f5c\u4e0eRDD\u7684\u7c7b\u4f3c\uff0c\u5206\u4e3aTransformations\uff08\u8f6c\u6362\uff09\u548cOutput Operations\uff08\u8f93\u51fa\uff09\u4e24\u79cd\uff0c\u6b64\u5916\u8f6c\u6362\u64cd\u4f5c\u4e2d\u8fd8\u6709\u4e00\u4e9b\u6bd4\u8f83\u7279\u6b8a\u7684\u64cd\u4f5c\uff0c\u5982\uff1aupdateStateByKey()\u3001transform()\u4ee5\u53ca\u5404\u79cdWindow\u76f8\u5173\u7684\u64cd\u4f5c\u3002<\/p>\n

Transformations on DStreams<\/h3>\n
\n

Transformation<\/strong><\/p>\n<\/td>\n

\n

Meaning<\/strong><\/p>\n<\/td>\n<\/tr>

\n

map(func)<\/p>\n<\/td>\n

\n

\u5bf9DStream\u4e2d\u7684\u5404\u4e2a\u5143\u7d20\u8fdb\u884cfunc\u51fd\u6570\u64cd\u4f5c\uff0c\u7136\u540e\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684DStream<\/p>\n<\/td>\n<\/tr>

\n

flatMap(func)<\/p>\n<\/td>\n

\n

\u4e0emap\u65b9\u6cd5\u7c7b\u4f3c\uff0c\u53ea\u4e0d\u8fc7\u5404\u4e2a\u8f93\u5165\u9879\u53ef\u4ee5\u88ab\u8f93\u51fa\u4e3a\u96f6\u4e2a\u6216\u591a\u4e2a\u8f93\u51fa\u9879<\/p>\n<\/td>\n<\/tr>

\n

filter(func)<\/p>\n<\/td>\n

\n

\u8fc7\u6ee4\u51fa\u6240\u6709\u51fd\u6570func\u8fd4\u56de\u503c\u4e3atrue\u7684DStream\u5143\u7d20\u5e76\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684DStream<\/p>\n<\/td>\n<\/tr>

\n

repartition(numPartitions)<\/p>\n<\/td>\n

\n

\u589e\u52a0\u6216\u51cf\u5c11DStream\u4e2d\u7684\u5206\u533a\u6570\uff0c\u4ece\u800c\u6539\u53d8DStream\u7684\u5e76\u884c\u5ea6<\/p>\n<\/td>\n<\/tr>

\n

union(otherStream)<\/p>\n<\/td>\n

\n

\u5c06\u6e90DStream\u548c\u8f93\u5165\u53c2\u6570\u4e3aotherDStream\u7684\u5143\u7d20\u5408\u5e76\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684DStream.<\/p>\n<\/td>\n<\/tr>

\n

count()<\/p>\n<\/td>\n

\n

\u901a\u8fc7\u5bf9DStream\u4e2d\u7684\u5404\u4e2aRDD\u4e2d\u7684\u5143\u7d20\u8fdb\u884c\u8ba1\u6570\uff0c\u7136\u540e\u8fd4\u56de\u53ea\u6709\u4e00\u4e2a\u5143\u7d20\u7684RDD\u6784\u6210\u7684DStream<\/p>\n<\/td>\n<\/tr>

\n

reduce(func)<\/p>\n<\/td>\n

\n

\u5bf9\u6e90DStream\u4e2d\u7684\u5404\u4e2aRDD\u4e2d\u7684\u5143\u7d20\u5229\u7528func\u8fdb\u884c\u805a\u5408\u64cd\u4f5c\uff0c\u7136\u540e\u8fd4\u56de\u53ea\u6709\u4e00\u4e2a\u5143\u7d20\u7684RDD\u6784\u6210\u7684\u65b0\u7684DStream.<\/p>\n<\/td>\n<\/tr>

\n

countByValue()<\/p>\n<\/td>\n

\n

\u5bf9\u4e8e\u5143\u7d20\u7c7b\u578b\u4e3aK\u7684DStream\uff0c\u8fd4\u56de\u4e00\u4e2a\u5143\u7d20\u4e3a\uff08K,Long\uff09\u952e\u503c\u5bf9\u5f62\u5f0f\u7684\u65b0\u7684DStream\uff0cLong\u5bf9\u5e94\u7684\u503c\u4e3a\u6e90DStream\u4e2d\u5404\u4e2aRDD\u7684key\u51fa\u73b0\u7684\u6b21\u6570<\/p>\n<\/td>\n<\/tr>

\n

reduceByKey(func, [numTasks])<\/p>\n<\/td>\n

\n

\u5229\u7528func\u51fd\u6570\u5bf9\u6e90DStream\u4e2d\u7684key\u8fdb\u884c\u805a\u5408\u64cd\u4f5c\uff0c\u7136\u540e\u8fd4\u56de\u65b0\u7684\uff08K\uff0cV\uff09\u5bf9\u6784\u6210\u7684DStream<\/p>\n<\/td>\n<\/tr>

\n

join(otherStream, [numTasks])<\/p>\n<\/td>\n

\n

\u8f93\u5165\u4e3a\uff08K,V)\u3001\uff08K,W\uff09\u7c7b\u578b\u7684DStream\uff0c\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\uff08K\uff0c\uff08V\uff0cW\uff09\uff09\u7c7b\u578b\u7684DStream<\/p>\n<\/td>\n<\/tr>

\n

cogroup(otherStream, [numTasks])<\/p>\n<\/td>\n

\n

\u8f93\u5165\u4e3a\uff08K,V)\u3001\uff08K,W\uff09\u7c7b\u578b\u7684DStream\uff0c\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684 (K, Seq[V], Seq[W]) \u5143\u7ec4\u7c7b\u578b\u7684DStream<\/p>\n<\/td>\n<\/tr>

\n

transform(func)<\/p>\n<\/td>\n

\n

\u901a\u8fc7RDD-to-RDD\u51fd\u6570\u4f5c\u7528\u4e8eDStream\u4e2d\u7684\u5404\u4e2aRDD\uff0c\u53ef\u4ee5\u662f\u4efb\u610f\u7684RDD\u64cd\u4f5c\uff0c\u4ece\u800c\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684RDD<\/p>\n<\/td>\n<\/tr>

\n

updateStateByKey(func)<\/p>\n<\/td>\n

\n

\u6839\u636ekey\u7684\u4e4b\u524d\u72b6\u6001\u503c\u548ckey\u7684\u65b0\u503c\uff0c\u5bf9key\u8fdb\u884c\u66f4\u65b0\uff0c\u8fd4\u56de\u4e00\u4e2a\u65b0\u72b6\u6001\u7684DStream<\/p>\n<\/td>\n<\/tr><\/tbody><\/table>

\u7279\u6b8a\u7684Transformations:<\/strong><\/p>\n

updateStateByKey\u7528\u4e8e\u8bb0\u5f55\u5386\u53f2\u8bb0\u5f55\uff0c\u4fdd\u5b58\u4e0a\u6b21\u7684\u72b6\u6001<\/p>\n

reduceByKeyAndWindow \u5f00\u7a97\u51fd\u6570<\/p>\n

<\/p>\n

Output Operations on DStreams<\/h3>\n

\u76f8\u5f53\u4e8erdd\u7684action\u7684\u4f5c\u7528\uff0ctransformation\u4e0d\u4f1a\u7acb\u5373\u6267\u884c\uff0c\u5230\u8fd9\u624d\u4f1a\u6267\u884c<\/p>\n
\n

Output Operation<\/span><\/p>\n<\/td>\n

\n

Meaning<\/span><\/p>\n<\/td>\n<\/tr>

\n

print()<\/span><\/p>\n<\/td>\n

\n

\u6253\u5370\u5230\u63a7\u5236\u53f0<\/span><\/p>\n<\/td>\n<\/tr>

\n

saveAsTextFiles(prefix, [suffix])<\/span><\/p>\n<\/td>\n

\n

\u4fdd\u5b58\u6d41\u7684\u5185\u5bb9\u4e3a\u6587\u672c\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u4e3a<\/span><\/p>\n

\"prefix-TIME_IN_MS[.suffix]\".<\/span><\/p>\n<\/td>\n<\/tr>

\n

saveAsObjectFiles(prefix, [suffix])<\/span><\/p>\n<\/td>\n

\n

\u4fdd\u5b58\u6d41\u7684\u5185\u5bb9\u4e3a<\/span>SequenceFile<\/span>\uff0c\u6587\u4ef6\u540d\u4e3a<\/span><\/p>\n

\"prefix-TIME_IN_MS[.suffix]\". <\/span><\/p>\n<\/td>\n<\/tr>

\n

saveAsHadoopFiles(prefix, [suffix])<\/span><\/p>\n<\/td>\n

\n

\u4fdd\u5b58\u6d41\u7684\u5185\u5bb9\u4e3a<\/span>hadoop<\/span>\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u4e3a<\/span><\/p>\n

\"prefix-TIME_IN_MS[.suffix]\". <\/span><\/p>\n<\/td>\n<\/tr><\/tbody><\/table>

<\/span><\/strong><\/p><\/div>

<\/div>\n
<\/div>\n
\n
<\/div>\n
<\/div>\n
\n<\/div>\n
<\/div>\n
<\/div>\n<\/div>\n\n\n\t\t<\/div>\n\t\t
posted @ 2018-04-05 18:55<\/span> \u9752\u886b\u4ed7\u5251<\/a> \u9605\u8bfb(...<\/span>) \u8bc4\u8bba(...<\/span>) \u7f16\u8f91<\/a> \u6536\u85cf<\/a><\/div>\n\t<\/div> <\/div>\n <\/div>","orderid":"0","title":"Spark\u4e4b   Spark Streaming\u6d41\u5f0f\u5904\u7406","smalltitle":"","mid":"0","fname":"Spark","special_id":"0","bak_id":"0","info":"0","hits":"543","pages":"1","comments":"0","posttime":"2019-05-16 01:17:40","list":"1557940660","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"Spark<\/A>  <\/A> Streaming<\/A> \u6d41\u5f0f<\/A> \u5904\u7406<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";s:4:\"head\";s:0:\"\";}","target":"0","ip":"47.106.78.186","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":" Spark\u4e4b Spark Streaming\u6d41\u5f0f\u5904\u7406SparkStreaming\u3000\u3000Spark Streaming\u7c7b\u4f3c\u4e8eApache Storm\uff0c\u7528\u4e8e\u6d41\u5f0f\u6570\u636e\u7684\u5904\u7406\u3002Spark Streaming\u6709\u9ad8\u541e\u5410\u91cf\u548c\u5bb9\u9519\u80fd\u529b\u5f3a\u7b49\u7279\u70b9\u3002Spark Streaming\u652f\u6301\u7684\u6570\u636e\u6e90\u6709\u5f88..","lastview":"1719085609","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}