Python에서 Dask로 병렬 프로그래밍
James Fulton
Climate Informatics Researcher
dask.delayed()로 만든 지연 파이프라인# 기본 사용 result = x.compute()result = dask.compute(x)# 스레드 사용 result = x.compute(scheduler='threads')result = dask.compute(x, scheduler='threads')# 프로세스 사용 result = x.compute(scheduler='processes')result = dask.compute(x, scheduler='processes')
from dask.distributed import LocalCluster
cluster = LocalCluster(
processes=True,
n_workers=2,
threads_per_worker=2
)
print(cluster)
LocalCluster(..., workers=2, threads=4, memory=31.38 GiB)
from dask.distributed import LocalCluster
cluster = LocalCluster(
processes=False,
n_workers=2,
threads_per_worker=2
)
print(cluster)
LocalCluster(..., workers=2, threads=4, memory=31.38 GiB)
cluster = LocalCluster(processes=True)
print(cluster)
LocalCluster(..., workers=4 threads=8, memory=31.38 GiB)
cluster = LocalCluster(processes=False)
print(cluster)
LocalCluster(..., workers=1 threads=8, memory=31.38 GiB)
from dask.distributed import Client, LocalCluster
cluster = LocalCluster(
processes=True,
n_workers=4,
threads_per_worker=2
)
client = Client(cluster)
print(client)
<Client: 'tcp://127.0.0.1:61391' processes=4 threads=8, memory=31.38 GiB>
클러스터를 만든 뒤 클라이언트에 전달
cluster = LocalCluster(
processes=True,
n_workers=4,
threads_per_worker=2
)
client = Client(cluster)
print(client)
<Client: ... processes=4 threads=8, ...>
클라이언트를 생성하여 자체 클러스터 만들기
client = Client(
processes=True,
n_workers=4,
threads_per_worker=2
)
print(client)
<Client: ... processes=4 threads=8, ...>
client = Client(processes=True) # 기본은 클라이언트를 사용 result = x.compute()# 다른 스케줄러로 변경 가능 result = x.compute(scheduler='threads')# 클라이언트를 명시적으로 사용 result = client.compute(x)
LocalCluster() - 내 컴퓨터에서 실행되는 클러스터Python에서 Dask로 병렬 프로그래밍