これは私のpython-sparkコードの一部です。 特にコードのこの部分は、速度を向上させたいと思っていますが、方法はわかりません。現在、6,000万のデータ行で約1分かかっており、10秒未満に改善したいと考えています。私のスパークアプリのspark appのスピードを改善する
sqlContext.read.format("org.apache.spark.sql.cassandra").options(table="axes", keyspace=source).load()
もっとコンテキスト:
article_ids = sqlContext.read.format("org.apache.spark.sql.cassandra").options(table="article_by_created_at", keyspace=source).load().where(range_expr).select('article','created_at').repartition(64*2)
axes = sqlContext.read.format("org.apache.spark.sql.cassandra").options(table="axes", keyspace=source).load()
speed_df = article_ids.join(axes,article_ids.article==axes.article).select(axes.article,axes.at,axes.comments,axes.likes,axes.reads,axes.shares) \
.map(lambda x:(x.article,[x])).reduceByKey(lambda x,y:x+y) \
.map(lambda x:(x[0],sorted(x[1],key=lambda y:y.at,reverse = False))) \
.filter(lambda x:len(x[1])>=2) \
.map(lambda x:x[1][-1]) \
.map(lambda x:(x.article,(x,(x.comments if x.comments else 0)+(x.likes if x.likes else 0)+(x.reads if x.reads else 0)+(x.shares if x.shares else 0))))
おかげで、あなたの提案をたくさん。
EDIT:
Countが(50代)の時間の大半を占める
に参加していない、私はまたして増加の並列処理を試してみましたが、それは明らかな効果がありませんでした:
sqlContext.read.format("org.apache.spark.sql.cassandra").options(table="axes", keyspace=source).load().repartition(number)
をし、
sqlContext.read.format("org.apache.spark.sql.cassandra").options(table="axes", keyspace=source,numPartitions=number).load()
あなたは負荷ですか、それとも参加してもよろしいですか?ジョインは高価です... –
カウントは、ほとんどの時間がかかる、上記の私の更新を参照してください。ありがとう – peter
この質問は[this](http://stackoverflow.com/a/37507116/1560062)とどう違うのですか? – eliasah