Performance 使用Pyspark脚本的stanfordcorenlp用例在本地节点上运行良好,但在纱线集群模式下运行非常慢

Performance 使用Pyspark脚本的stanfordcorenlp用例在本地节点上运行良好,但在纱线集群模式下运行非常慢,performance,apache-spark,pyspark,stanford-nlp,Performance,Apache Spark,Pyspark,Stanford Nlp,我尝试调试所有可能的解决方案,但无法在集群上运行此脚本和扩展此脚本,因为我需要处理1亿条记录,此脚本在本地节点上运行良好,但在Cloudera Amazon集群上无法运行。下面是在本地节点上工作的示例数据。据我所知,问题是我在udf中使用的2个文件没有分布在执行器/容器或节点上,作业只是一直在运行,处理速度非常慢。我无法修复此代码以在集群上执行此操作 ##Link to the 2 files which i use in the script### ##https://nlp.

我尝试调试所有可能的解决方案,但无法在集群上运行此脚本和扩展此脚本,因为我需要处理1亿条记录,此脚本在本地节点上运行良好,但在Cloudera Amazon集群上无法运行。下面是在本地节点上工作的示例数据。据我所知,问题是我在udf中使用的2个文件没有分布在执行器/容器或节点上,作业只是一直在运行,处理速度非常慢。我无法修复此代码以在集群上执行此操作

    ##Link to the 2 files which i use in the script###
    ##https://nlp.stanford.edu/software/stanford-ner-2015-12-09.zip
    ####Link to the data set########
    ##https://docs.google.com/spreadsheets/d/17b9NUonmFjp_W0dOe7nzuHr7yMM0ITTDPCBmZ6xM0iQ/edit?usp=drivesdk&lipi=urn%3Ali%3Apage%3Ad_flagship3_messaging%3BQHHZFKYfTPyRb%2FmUg6ahsQ%3D%3D

    #spark-submit --packages com.databricks:spark-csv_2.10:1.5.0 --master yarn-cluster --files /home/ec2-user/StanfordParser/stanford-ner-2016-10-31/stanford-ner.jar,/home/ec2-user/StanfordParser/stanford-ner-2016-10-31/classifiers/english.all.3class.distsim.crf.ser.gz stanford_ner.py


    from pyspark.sql.types import StringType
    from pyspark.sql.functions import udf
    import os
    from pyspark import SparkFiles
    from pyspark import SparkContext, SparkConf
    from pyspark.sql import Row
    from pyspark.context import SparkContext
    from pyspark.sql import HiveContext
    from pyspark.sql.functions import udf
    from pyspark.sql import SQLContext

    def stanford(str):
        os.environ['JAVA_HOME']='/usr/java/jdk1.8.0_131/'
        stanford_classifier = SparkFiles.get("english.all.3class.distsim.crf.ser.gz")
        stanford_ner_path = SparkFiles.get("stanford-ner.jar")
        st = StanfordNERTagger(stanford_classifier, stanford_ner_path, encoding='utf-8')
        output = st.tag(str.split())
        organizations = []
        organization = ""
        for t in output:
            #The word
            word = t[0]
            #What is the current tag
            tag = t[1]
            #print(word, tag)
            #If the current tag is the same as the previous tag Append the current word to the previous word
            if (tag == "ORGANIZATION"):
                organization += " " + word
            organizations.append(organization)
            final = "-".join(organizations)
            return final


    stanford_lassification = udf(stanford, StringType())

    ###################Pyspark Section###############
    #Set context
    sc = SparkContext.getOrCreate()
    sc.setLogLevel("DEBUG")
    sqlContext = SQLContext(sc)

    #Get data
    df = sqlContext.read.format('com.databricks.spark.csv').options(header='true', inferschema='true').load(r"/Downloads/authors_data.csv")

    #Create new dataframe with new column organization
    df = df.withColumn("organizations", stanford_lassification(df['affiliation_string']))

    #Save result
    df.select('pmid','affiliation_string','organizations').write.format('com.databricks.spark.csv').save(r"/Downloads/organizations.csv")

嗨,Sunil,你有没有找到解决办法来解释为什么CoreNLP作为UDF在集群上执行时速度非常慢?是的,我用pig和流式python重新编写了整个程序,无法用spark找到解决方案,但是的,原因似乎是因为我为每个字符串或句子调用了缓慢且多个JVM,我遇到了同样的问题(速度慢,同时有多个JVM)在使用pig和streaming python时,我阅读了整个大文件,以便JVM加载一次,stanford ner标记文件中的所有单词,然后我相应地解析标记的单词。在apace spark而不是pig和streaming pythonMany上执行此任务将非常棒。感谢Sunil的回复。你有任何基准测试吗?我有StanfordNLP简单API(仅句子拆分器和词性标记)500万份科学摘要需要2个多小时。我想知道你在修改代码时是否有一些基准测试?再次感谢。是的,在我们改变了整个方法并在普通6节点集群上使用pig和流式python重新编写了此练习后,我们在不到10分钟的时间内解析了700万份科学摘要。非常感谢Sunil!你的回答对我找到在Spark上工作的方法非常有帮助。我能比较的最后一个问题是,当你尝试Spark/UDF时,这700万篇摘要花了多长时间?不到10分钟,这非常令人印象深刻,但我只是想知道它在Spark上工作了多长时间。再次感谢Sunil,我真的很感激谢谢你的帮助。