• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    해결됨

안녕하세요. worker 관련 질문입니다.

20.03.02 20:45 작성 조회수 254

0

worker를 최소 10에서 work_list 개수로 구하셨는데

cpu와 worker 관련 개수 구하는 혹은 판단 할수 있는 기준이 무엇인지 알수 있을까요?

답변 1

답변을 작성해보세요.

0

네 안녕하세요. jin님

상당히 좋은 질문을 해주셨습니다.

공식 레퍼런스를 보면 파이썬 버전마다 동작 방식이 모두 다른것을 확인하실 수 있어요.

최근 CPU들이 기본 코어개수가 늘어나고 가격도 저렴해진 관계로 3.8부터는 디폴트로 아래 내용을 보시면

최소 5개부터 할당되는 것을 확인하실 수 있습니다. 물론 운영체제의 현재 동작 환경에 따라서 달라지겠지요.

해당 내용은 아래 레퍼런스에서 WORKER 등으로 검색하셔서 한글로 보시면 자세하게 확인 가능합니다.

https://docs.python.org/3/library/concurrent.futures.html

class concurrent.futures.ThreadPoolExecutor(max_workers=Nonethread_name_prefix=''initializer=Noneinitargs=())

An Executor subclass that uses a pool of at most max_workers threads to execute calls asynchronously.

initializer is an optional callable that is called at the start of each worker thread; initargs is a tuple of arguments passed to the initializer. Should initializer raise an exception, all currently pending jobs will raise a BrokenThreadPool, as well as any attempt to submit more jobs to the pool.

Changed in version 3.5: If max_workers is None or not given, it will default to the number of processors on the machine, multiplied by 5, assuming that ThreadPoolExecutor is often used to overlap I/O instead of CPU work and the number of workers should be higher than the number of workers for ProcessPoolExecutor.

New in version 3.6: The thread_name_prefix argument was added to allow users to control the threading.Thread names for worker threads created by the pool for easier debugging.

Changed in version 3.7: Added the initializer and initargs arguments.

Changed in version 3.8: Default value of max_workers is changed to min(32, os.cpu_count() + 4). This default value preserves at least 5 workers for I/O bound tasks. It utilizes at most 32 CPU cores for CPU bound tasks which release the GIL. And it avoids using very large resources implicitly on many-core machines.