python - 高效地并行运行 Pyspark 函数
问题描述
我有一个具有 3 个功能的 pyspark 代码。第一个函数是加载一些数据并为其他两个函数做准备。其他两个函数获取此输出并执行一些任务并生成相应的输出。
所以代码看起来像这样,
def first_function():
# load data
# pre-process
# return pre-processed data
def second_function(output_of_first_function):
# tasks for second function
# return output
def third_function(output_of_first_function):
# tasks for third function
# return output
这些函数是从这样的主函数调用的,
def main():
output_from_first_function = first_function()
output_from_second_function = second_function(output_from_first_function)
output_from_third_function = third_function(output_from_first_function)
second_function 和 third_function 之间没有相互依赖关系。我正在寻找一种同时并行运行这两个功能的方法。这些函数内部发生了一些转换。因此,并行帮助这些功能可能会有所帮助。
如何并行运行 second_function 和 third_function?这些函数中的每一个应该创建自己的火花上下文还是可以共享火花上下文?
解决方案
From your problem, it doesn't seems like you really need pyspark. I think you should consider using Python Threads library. As described in this post: How to run independent transformations in parallel using PySpark?
推荐阅读
- jfrog - 我可以删除默认的 Maven 存储库吗?
- javascript - chartj 模板不接受新数据集
- azure - 可疑的 powershell 脚本 Microsoft Defender for Cloud
- javascript - 如何将数组从 .js 文件导入 HTML 文件?
- mysql - 使用 SQL 合并两个表
- python - 无法在python中添加列表中的最后一个元素
- c# - 从 Windows.forms 打开时如何关闭用户控件 wpf
- reactjs - 如何将提交的 react 应用代码部署到 Github Pages
- reactjs - 我如何改变tinymce的方向性
- r - ggplot2 Barplot 上缺少一列