python multiprocessing hangs at map on one cluster but works fine on another
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 06:40 AM - edited 06-10-2024 06:42 AM
I have a simple python script which have been running fine on my cluster but recently the same script gets stuck at map. So I tried creating a new cluster with less resources and tried to run the same script over that and it ran just fine.
Here are the specifications of my cluster:
My old cluster:
9.1-LTS ML (includes Apache Spark 3.1.2, Scala 2.12)
Worker type: Standard_D16s_v3 (min "1", max "8" )
Driver type: Standard_D64s_v3
Spot instances = True
My new cluster:
9.1-LTS ML (includes Apache Spark 3.1.2, Scala 2.12)
Worker type: Standard_DS3_v2 (min "1", max "8" )
Driver type: Standard_DS3_v2
Spot instances = True
import multiprocessing
from functools import partial
# Define the function to process each row
def process_row(row, func):
index, data = row
if data['some_new_column'] == '':
data['some_new_column'] = func(data['text'])
return index, data
# Define the function for parallel processing
def parallel_process(data, func, num_processes):
pool = multiprocessing.Pool(processes=num_processes)
func_partial = partial(process_row, func=func)
print('Stating mapping. . . ')
processed_data = pool.map(func_partial, data)
pool.close()
pool.join()
return processed_data
num_processes = multiprocessing.cpu_count()
# Apply parallel processing to speed up the operation
processed_data = parallel_process(models_df.iterrows(), my_custom_func, num_processes)