欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

updateStateByKey與mapwithstate怎么實(shí)現(xiàn)

這篇文章主要講解了“updateStateByKey與mapwithstate怎么實(shí)現(xiàn)”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“updateStateByKey與mapwithstate怎么實(shí)現(xiàn)”吧!

成都創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比清徐網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式清徐網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋清徐地區(qū)。費(fèi)用合理售后完善,十多年實(shí)體公司更值得信賴。

updateStateByKey與mapwithstate 這兩個(gè)方法在Dstream中是找不到的,他們是通過隱式轉(zhuǎn)換來進(jìn)行實(shí)現(xiàn)的

updateStateByKey與mapwithstate怎么實(shí)現(xiàn)

由此可以看到,最終是通過PairDStreamFunctions來實(shí)現(xiàn)這兩個(gè)方法的。

updateStateByKey

updateStateByKey與mapwithstate怎么實(shí)現(xiàn)

newUpdateFunc 方法是在原有基礎(chǔ)上如何進(jìn)行更新的方法

defaultPartitioner()獲得默認(rèn)的分區(qū)數(shù)

updateStateByKey與mapwithstate怎么實(shí)現(xiàn)

如下代碼出現(xiàn)了一個(gè)非常關(guān)鍵的地方

new StateDStream(self, ssc.sc.clean(updateFunc), partitioner, rememberPartitioner, None)

updateStateByKey與mapwithstate怎么實(shí)現(xiàn)

StateDStream 繼承自Dstream。

stateDStream自會(huì)持久化到內(nèi)存中

updateStateByKey與mapwithstate怎么實(shí)現(xiàn)

里面有一個(gè)很總要的方法:如果存在parent RDD 就將執(zhí)行computeUsingPreviousRDD方法

updateStateByKey與mapwithstate怎么實(shí)現(xiàn)

在該方法中,有一處性能瓶頸的代碼

updateStateByKey與mapwithstate怎么實(shí)現(xiàn)

每次進(jìn)行更新的時(shí)候都會(huì)將原有的parentRDD進(jìn)行cogroup,這樣程序不斷的運(yùn)行這樣會(huì)導(dǎo)致越來越慢!盡量少用改方法!

updateStateByKey與mapwithstate怎么實(shí)現(xiàn)

Mapwithstate

mapWithState方法的返回值是MapWithStateDStream,我們來看看它的實(shí)現(xiàn)類

MapWithStateDStreamImpl

updateStateByKey與mapwithstate怎么實(shí)現(xiàn)

最終返回InternalMapWithStateDStream

updateStateByKey與mapwithstate怎么實(shí)現(xiàn)

跟updateStateByKey一樣是持久化在了內(nèi)存中

persist(StorageLevel.MEMORY_ONLY)

接下來看看每個(gè)繼承自Dstream的最重要的方法 compute:

updateStateByKey與mapwithstate怎么實(shí)現(xiàn)

最終操作的是RDD:MapWithStateRDD

RDD中的partition被MapWithStateRDDRecord代表

updateStateByKey與mapwithstate怎么實(shí)現(xiàn)

MapWithStateRDDRecord有伴生對(duì)象:中的方法,該方法是對(duì)state進(jìn)行更新操作,不像 updateStateByKey每次都會(huì)進(jìn)cogroup的操作,而是在原有的基礎(chǔ)上進(jìn)行更新,效率得到了提高!

defupdateRecordWithData[K: ClassTag, V: ClassTag, S: ClassTag, E: ClassTag](
    prevRecord: Option[MapWithStateRDDRecord[K, S, E]],
    dataIterator: Iterator[(K, V)],
    mappingFunction: (Time, K, Option[V], State[S]) => Option[E],
    batchTime: Time,
    timeoutThresholdTime: Option[Long],
    removeTimedoutData: Boolean
  ): MapWithStateRDDRecord[K, S, E] = {
    // Create a new state map by cloning the previous one (if it exists) or by creating an empty one
    valnewStateMap = prevRecord.map { _.stateMap.copy() }. getOrElse { newEmptyStateMap[K, S]() }

    valmappedData = newArrayBuffer[E]
    valwrappedState = newStateImpl[S]()

    // Call the mapping function on each record in the data iterator, and accordingly
    // update the states touched, and collect the data returned by the mapping function
    dataIterator.foreach { case(key, value) =>
      wrappedState.wrap(newStateMap.get(key))
      valreturned = mappingFunction(batchTime, key, Some(value), wrappedState)
      if(wrappedState.isRemoved) {
        newStateMap.remove(key)
      } else if(wrappedState.isUpdated
          || (wrappedState.exists && timeoutThresholdTime.isDefined)) {
        newStateMap.put(key, wrappedState.get(), batchTime.milliseconds)
      }
      mappedData ++= returned
    }

    // Get the timed out state records, call the mapping function on each and collect the
    // data returned
    if(removeTimedoutData && timeoutThresholdTime.isDefined) {
      newStateMap.getByTime(timeoutThresholdTime.get).foreach { case(key, state, _) =>
        wrappedState.wrapTimingOutState(state)
        valreturned = mappingFunction(batchTime, key, None, wrappedState)
        mappedData ++= returned
        newStateMap.remove(key)
      }
    }

    MapWithStateRDDRecord(newStateMap, mappedData)
  }
}

感謝各位的閱讀,以上就是“updateStateByKey與mapwithstate怎么實(shí)現(xiàn)”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)updateStateByKey與mapwithstate怎么實(shí)現(xiàn)這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

新聞標(biāo)題:updateStateByKey與mapwithstate怎么實(shí)現(xiàn)
當(dāng)前URL:http://aaarwkj.com/article24/ggheje.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、ChatGPT用戶體驗(yàn)、網(wǎng)站導(dǎo)航、標(biāo)簽優(yōu)化、面包屑導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)
久久久久久狠狠亚洲综合| 亚洲少妇熟女一区二区三区| 亚洲一区二区三区久久伊人| 欧美日韩视频在线第一页| 色综合婷婷九月中文字幕| 午夜剧场福利在线观看| 最新91精品国产自产在线| 日日激情综合久久一区| 欧美日韩国产在线91| 日韩美女av在线播放| 日本视频免费一区二区| 中文字幕精品一区二区三区在线| 日韩区一区二在线视频| 偷拍福利视频一区二区三区| 91桃色网站在线免费观看| 久久国产麻豆精品电影| 国产精品一区二区国产激情久久| 国产午夜福利诱惑在线观看| 日本岛国免费一区二区| 久久精品国产av极品| 国产成人福利视频在线观看| 青青青久热国产精品视频| 亚洲青青草原一区二区| 蜜桃午夜精品一区二区三区| 蜜臀综合亚洲国产精品| 国产深夜福利在线观看| 国产av不卡精品影片| 日本一二三四卡久久精品| 久久精品亚洲国产成人av| 色综合一区二区日本韩国亚洲 | 成人短篇在线视频夫妻刺激自拍| 成人性生交免大片免费| 亚洲国产av永久精品成人| 欧美日韩亚洲一区二区搜索| 色国产精品一区在线观看| 亚洲精品一区二区日本| 欧美乱与老熟妇视频观看| 国产美女冒白浆视频免费| 国产成人精品久久一区二区三区| 日本人妻成人免费大片| 水蜜桃成人在线视频免费观看|