> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# max_threads_* 세션 설정

> max_threads_* 자동 생성 그룹에 속한 ClickHouse 세션 설정입니다.

export const SettingsInfoBlock = ({type, default_value, changeable_without_restart}) => {
  return <div className="not-prose" style={{
    display: "flex",
    flexWrap: "wrap",
    alignItems: "baseline",
    columnGap: "0.5rem",
    rowGap: "0.125rem",
    margin: "0.375rem 0",
    fontSize: "0.8125rem",
    lineHeight: "1.125rem"
  }}>
      <div style={{
    fontWeight: 600,
    opacity: 0.72
  }}>유형</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{type}</div>
      <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>기본값</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{default_value}</div>
      {changeable_without_restart && <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>
          재시작 없이 변경 가능
        </div>}
      {changeable_without_restart && <div style={{
    overflowWrap: "anywhere"
  }}>
          {changeable_without_restart}
        </div>}
    </div>;
};

이 설정은 [system.settings](/docs/ko/reference/system-tables/settings)에서 확인할 수 있으며, [source](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp)에서 자동 생성됩니다.

<div id="max_threads">
  ## max\_threads
</div>

<SettingsInfoBlock type="MaxThreads" default_value="auto(N)" />

원격 서버에서 데이터를 가져오는 스레드(['max\_distributed\_connections'](/docs/ko/reference/settings/session-settings/max-distributed#max_distributed_connections) 매개변수 참고)를 제외한 쿼리 처리 스레드의 최대 개수입니다.

이 매개변수는 쿼리 처리 파이프라인의 동일한 단계를 병렬로 수행하는 스레드에 적용됩니다.
예를 들어 테이블에서 데이터를 읽을 때 함수가 포함된 표현식을 계산하고, `WHERE`로 필터링하고, `GROUP BY`를 위한 사전 집계를 최소 'max\_threads'개의 스레드로 병렬 수행할 수 있다면 'max\_threads'가 사용됩니다.

LIMIT 때문에 빠르게 완료되는 쿼리에는 더 작은 'max\_threads' 값을 설정할 수 있습니다.
예를 들어 필요한 항목 수가 모든 block에 들어 있고 max\_threads = 8이면, 실제로는 하나만 읽어도 충분하더라도 8개의 block을 가져오게 됩니다.
`max_threads` 값이 작을수록 메모리 사용량이 줄어듭니다.

기본적으로 `max_threads` 설정은 ClickHouse에서 사용할 수 있는 하드웨어 스레드 수(CPU 코어 수)에 맞춰집니다.
예외적으로, CPU 코어가 32개 미만이고 SMT(예: Intel HyperThreading)를 사용하는 x86 프로세서에서는 기본값으로 논리 코어 수(= 물리 코어 수 x 2)를 사용합니다.

SMT(예: Intel HyperThreading)가 없으면 이는 CPU 코어 수와 같습니다.

ClickHouse Cloud 사용자의 경우 기본값은 `auto(N)`으로 표시되며, 여기서 N은 서비스의 vCPU 크기(예: 2vCPU/8GiB, 4vCPU/16GiB 등)와 일치합니다.
모든 서비스 크기 목록은 Cloud Console의 설정 탭에서 확인할 수 있습니다.

<div id="max_threads_for_indexes">
  ## max\_threads\_for\_indexes
</div>

<SettingsInfoBlock type="UInt64" default_value="0" />

인덱스를 처리하는 데 사용되는 최대 스레드 수입니다.

<div id="max_threads_min_free_memory_per_thread">
  ## max\_threads\_min\_free\_memory\_per\_thread
</div>

<SettingsInfoBlock type="UInt64" default_value="1073741824" />

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.5"},{"label": "1073741824"},{"label": "사용 가능한 메모리를 기준으로 스레드 수를 제한하는 새로운 설정"}]}]} />

서버가 메모리 부족 상태일 때 `max_threads`를 낮춰, 메모리 한도에 도달할 가능성이 높은 고병렬 쿼리가 시작되지 않도록 합니다.

사용 가능한 메모리는 서버의 `max_server_memory_usage`에서 전역 memory tracker가 현재 추적 중인 메모리를 뺀 값으로 계산됩니다. 이 사용 가능한 메모리가 `max_threads`에 이 값을 곱한 값보다 작으면, `N * value <= free_memory`를 만족하는 가장 큰 N이 되도록 `max_threads`를 줄이며, 최솟값은 `1`입니다.

이 제한을 비활성화하려면 `0`으로 설정합니다.

예를 들어 기본값이 1 GiB이고 사용 가능한 메모리가 32 GiB이면 `max_threads`의 상한은 32가 되며, 사용 가능한 메모리가 1 GiB이면 1로 낮아집니다.

이 설정은 읽기 측 병렬성(`SELECT`, `UNION`, `INTERSECT`/`EXCEPT`, 그리고 `INSERT ... SELECT`의 `SELECT` 측)에 적용됩니다. 쓰기 측은 `max_insert_threads_min_free_memory_per_thread`를 참조하십시오.
