# 스탠얼론 디스커스 속도 향상을 위한 최적 구성

**URL:** https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456
**Category:** Self-hosting
**Tags:** server-resources
**Created:** [8월 30, 2020, 7:39오전 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456 "2020-08-30T07:39:37Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![nildarar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nildarar/32/331927_2.png) [@nildarar](https://meta.discourse.org/u/nildarar)
#### Post date: [8월 30, 2020, 7:39오전 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/1 "2020-08-30T07:39:37Z")

</div>

저희 Discourse 사이트에는 1만 명 이상의 사용자와 약 700명의 일일 활성 사용자가 있습니다. 사용자들은 하루 평균 1만 건의 게시물을 올리고 있습니다. 크롤러와 익명 사용자를 포함하여 하루 페이지뷰는 16만 회를 넘습니다. 거의 모든 사용자가 모바일 기기를 통해 저희 사이트에 접속합니다.

저희는 16개 CPU 코어와 24GB RAM을 갖춘 단일 VPS에서 독립 실행형(standalone) 설치 모드로 커뮤니티를 운영했으며, app.yml 설정 파일에는 다음과 같은 값들이 지정되어 있었습니다:

```
params:
  db_shared_buffers: "6GB"
  db_work_mem: "50MB"
env:
  UNICORN_WORKERS: 16

```

다음 플러그인들을 사용 중입니다:

```
docker_manager
discourse-solved
discourse-adplugin
discourse-voting
discourse-push-notifications
discourse-whos-online
discourse-akismet
discourse-data-explorer
discourse-sitemap
discourse-telegram-notifications

```

위 설정을 사용했을 때, 일부 사용자는 사이트 로딩이 느리다고 보고했으며, 게시물을 제출하는 과정에서 화면이 하얗게 변하는 현상(헤더는 여전히 표시됨)이 발생하기도 했습니다. 또한 피크 시간대에는 사이트 성능이 저하되는 경우가 있습니다.

설정 오류가 있는지, 아니면 더 많은 리소스가 필요한지 설명해 주실 수 있을까요?  
많은 도움 부탁드립니다 🙏

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [8월 30, 2020, 8:33오전 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/2 "2020-08-30T08:33:23Z")

</div>

하루 1만 건의 게시물은 페이지뷰 수량에 비해 상당히 높은 수치입니다. 현재 설정을 고려할 때 리소스 한계에 부딪히지 않을까 예상되며, 그 원인은 데이터베이스일 가능성이 높습니다. 멀티 컨테이너 구성으로 전환하여 메인 서버에서 유니콘(unicorn) 워커의 부하를 덜어내는 방법을 시도해 볼 수 있습니다.

---

<div class="post-metadata">

### Author: ![nildarar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nildarar/32/331927_2.png) [@nildarar](https://meta.discourse.org/u/nildarar)
#### Post date: [8월 30, 2020, 8:42오전 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/3 "2020-08-30T08:42:55Z")

</div>

귀하의 답변에 따르면, 이 구성에서 리소스를 늘리는 것이 우리의 문제를 해결하는 데 도움이 되지 않는다는 말씀인가요? 예를 들어 24개의 CPU 코어와 32GB의 RAM 같은 경우요.

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [8월 30, 2020, 8:55오전 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/4 "2020-08-30T08:55:57Z")

</div>

가능성은 충분히 있지만, 저는 먼저 수평 확장 가능한 모든 것을 수평적으로 확장해 보겠습니다. 그러면 병목 현상이 어디에 있는지도 훨씬 더 명확해질 것입니다.

대부분의 성능 문제는 단순히 더 많은 리소스를 투입하는 것으로 해결할 수 있습니다. 어려운 부분은 비용을 절감(혹은 큰돈을 절약)할 수 있도록 이를 지능적으로 실행하는 것입니다.

---

<div class="post-metadata">

### Author: ![nildarar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nildarar/32/331927_2.png) [@nildarar](https://meta.discourse.org/u/nildarar)
#### Post date: [8월 30, 2020, 5:48오후 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/5 "2020-08-30T17:48:37Z")

</div>

전문 지식과 친절한 조언에 감사드립니다. 반드시 이 내용을 구현하는 방법에 대해 읽어보겠습니다. 한 가지 더 궁금한 점이 있는데, 위에서 언급한 사양(24개 CPU 코어, 32GB RAM)에 맞춰 앱에서 어떤 설정을 적용해야 하는지 궁금합니다.

현재 설정이 적절한가요, 아니면 값을 높이는 것이 더 나은가요?

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [8월 30, 2020, 7:40오후 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/6 "2020-08-30T19:40:57Z")

</div>

시스템을 검사해서 어떤 일이 일어나고 있는지 확인해 봐야 알 수 있습니다.

게시물을 제출할 때 문제가 가장 많이 발생한다고 하셨으니, 문제는 아마 데이터베이스 쓰기 과정에 있을 가능성이 높고, `shared buffers`를 더 늘리는 것이 큰 도움이 될 것 같지 않습니다. 그래도 시도해 볼 수는 있습니다. 모든 조언에 반하여 메모리의 50% 이상까지 올린 경우도 본 적이 있으니, 점진적으로 최대 12GB까지 올려볼 수 있습니다.  
502 에러가 발생하지 않는다면 `UNICORN_WORKERS`를 늘리는 것도 의미가 없습니다.

---

<div class="post-metadata">

### Author: ![marianord](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marianord/32/90502_2.png) [@marianord](https://meta.discourse.org/u/marianord)
#### Post date: [8월 31, 2020, 3:41오후 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/7 "2020-08-31T15:41:35Z")

</div>

사용법에 대해 언급하지 않으셨기 때문에, 제가 처음에 할 일은 CDN을 추가하는 것입니다. 이렇게 하면 더 큰 요청이 서버에 도달하지 않으므로 VPS의 부하를 크게 줄일 수 있습니다.

CDN 외에도 S3와 유사한 스토리지를 사용하는 것을 권장합니다. 이렇게 하면 스토리지와 VPS 리소스를 독립적으로 확장할 수 있습니다(커뮤니티가 업로드 중심이라면 더욱 유용합니다).

이러한 권장 사항들은 **크게** 부하를 줄이는 데 도움이 되며, 더 큰 VPS로 업그레이드하는 것보다 비용 증가 폭이 훨씬 적습니다.

---

<div class="post-metadata">

### Author: ![nildarar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nildarar/32/331927_2.png) [@nildarar](https://meta.discourse.org/u/nildarar)
#### Post date: [8월 31, 2020, 3:55오후 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/8 "2020-08-31T15:55:58Z")

</div>

@marianord 감사합니다. 불행히도 저희는 CDN을 사용하지 않습니다. 포럼의 업로드 속도는 그리 높지 않습니다. 대부분의 시간 동안 사용자들은 다양한 주제에 대해 이야기합니다. 예를 들어, 지난 1년 동안 약 280만 개의 게시글과 270만 개의 좋아요가 있었지만, 업로드된 파일은 단 25GB에 불과했습니다.

제가 작성한 정보를 바탕으로, S3와 같은 CDN을 사용하면 서버 부하가 줄어드는 것일까요?

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [8월 31, 2020, 3:58오후 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/9 "2020-08-31T15:58:09Z")

</div>

@marianord님과 의견이 다릅니다. CDN이 서버 부하에 눈에 띄는 차이를 만들 거라고 생각하지 않습니다.  
이것들은 단순히 정적 파일일 뿐이며, 서빙하는 데 전혀 무리가 없으니까요.

---

<div class="post-metadata">

### Author: ![marianord](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marianord/32/90502_2.png) [@marianord](https://meta.discourse.org/u/marianord)
#### Post date: [8월 31, 2020, 4:09오후 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/10 "2020-08-31T16:09:43Z")

</div>

CDN과 S3는 두 가지가 서로 다른 것입니다.

- S3는 파일과 백업을 클라우드 제공업체가 관리하는 다른 서버로 오프로딩합니다 (매우 고수준의 요약)
- CDN은 서버의 정적 파일(이미지, JS, CSS)을 전 세계 여러 서버(PoP)에 캐시하여 이러한 자산의 로딩 속도를 높입니다.

> [@RGJ](#):
>
> CDN이 서버 부하 측면에서 눈에 띄는 차이를 만들지 않을 것 같습니다.

적어도 제 경험상으로는, 서버에 도달하는 요청의 양을 줄여줌으로써 부하를 감소시킵니다. 사용자당 100개의 요청을 처리하는 것보다 10개의 JSON 요청만 처리하는 것이 훨씬 쉽습니다.

아마도 이 방법은 @nildarar 님이 겪고 있는 모든 문제를 해결하지는 못하겠지만, 정적 요청(캐시된 요청)을 Discourse 서버에서 제거함으로써 서버의 무거운 부하를 줄이는 데 도움이 될 것입니다.

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [8월 31, 2020, 4:24오후 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/11 "2020-08-31T16:24:07Z")

</div>

> [@marianord](#):
>
> 서버에 도달하는 요청의 양을 줄이므로 부하를 줄이는 것입니다.

정적 파일에 대한 요청은 전체 서버 부하에 큰 영향을 미치지 않습니다. 동적 콘텐츠에 대한 요청이 훨씬 무거운 작업입니다.

> [@marianord](#):
>
> 사용자당 100개의 요청을 처리하는 것보다 사용자당 10개의 JSON 요청만 제공하는 것이 훨씬 쉽습니다.

일반적으로 `json` 요청은 CDN에 의해 캐시되는 정적 자산이 아닙니다. 이는 실시간으로 생성되는 동적 콘텐츠입니다. 왜 CDN 맥락에서 json 파일에 대해 이야기하고 있습니까?

> [@marianord](#):
>
> Discourse 서버에서 모든 정적 요청(캐시된 요청)을 제거하여 서버의 무거운 부하를 줄입니다.

정적 요청 != 무거운 부하.

죄송하지만 이것은 정말로 잘못된 조언입니다.

다음은 CDN이나 S3 없이 Discourse를 실행 중인 6-CPU 머신(즉, CPU 합계가 600%까지 올라감)의 예시입니다.

 ![image](https://global.discourse-cdn.com/meta/original/3X/5/5/55bdc96002d27f13caf5ec0704ab25b968ec15ca.png)

nginx가 전체 용량의 6.7%만 차지하고 있음을 볼 수 있습니다(즉, **용량의 1/100** ). 그 중 일부만이 정적 자산에 사용됩니다.

정적 자산을 S3와/또는 CDN으로 오프로드하면 전체 서버 부하가 1% 미만만 감소할 것입니다.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [8월 31, 2020, 4:38오후 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/12 "2020-08-31T16:38:31Z")

</div>

맞습니다. 다만 Discourse에는 몇 가지 예외가 있습니다. Ruby를 통해 서빙되는 스타일시트가 그 예인데, 캐싱 CDN을 사용하면 해당 요청이 unicorn 프로세스를 차지하지 않게 됩니다.

OP의 문제에 대해서는, 먼저 전문가가 피크 시간대에 성능 분석을 수행하여 현재 병목 현상이 무엇인지 파악하는 것이 필요합니다.

---

<div class="post-metadata">

### Author: ![marianord](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marianord/32/90502_2.png) [@marianord](https://meta.discourse.org/u/marianord)
#### Post date: [8월 31, 2020, 4:45오후 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/13 "2020-08-31T16:45:49Z")

</div>

> [@RGJ](#):
>
> CDN 컨텍스트에서 왜 json 파일에 대해 이야기하는 건가요?

JSON 요청은 서버에 도달하지만, 정적 요청은 그렇지 않다는 뜻입니다.

---

<div class="post-metadata">

### Author: ![nildarar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nildarar/32/331927_2.png) [@nildarar](https://meta.discourse.org/u/nildarar)
#### Post date: [9월 1, 2020, 3:12오전 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/14 "2020-09-01T03:12:24Z")

</div>

가이드에 감사드립니다. 몇 개월 전까지는 Cloudflare CDN 서비스를 사용했으며, 페이지 규칙을 통해 정적 콘텐츠에 좋은 변경 사항을 적용했습니다. 그러다 어딘가에서 Cloudflare 같은 프록시를 사용하면 Discourse의 성능이 크게 저하된다는 내용을 읽게 되어, 해당 서비스를 비활성화했습니다.

어제는 CPU 코어를 16개에서 24개로 늘리고, app.yml 파일에 다음과 같은 변경 사항을 적용했습니다.

```
params:
  # db_shared_buffers: "6GB"
  db_shared_buffers: "7GB"
env:
  # UNICORN_WORKERS: 16
  UNICORN_WORKERS: 24

```

이러한 변경 사항으로 인해 우리의 문제는 일시적으로 해결되었지만, 향후 몇 개월간 근본적인 변경이 필요하다고 생각합니다.

따라서 선생님의 추천에 따르면, 정적 콘텐츠 서빙을 위해 CDN을 사용하고 Discourse를 두 개의 별도 컨테이너로 분리하는 것이 성능 개선 측면에서 더 우선순위가 높습니다.

---

<div class="post-metadata">

### Author: ![SouperC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/souperc/32/62875_2.png) [@SouperC](https://meta.discourse.org/u/SouperC)
#### Post date: [9월 1, 2020, 4:01오전 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/15 "2020-09-01T04:01:03Z")

</div>

이 정보는 오래되었을 수 있지만, discourse가 성능이 낮은 CPU 여러 개보다는 성능이 높은 CPU 소수를 선호한다는 내용을 읽은 기억이 있습니다… unicorn 워커 수를 업데이트하더라도 마찬가지입니다.

@codinghorror, 이 정보가 여전히 정확한지 확인해 주실 수 있을까요?

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [9월 1, 2020, 8:08오전 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/16 "2020-09-01T08:08:02Z")

</div>

네, 맞습니다. 코어 CPU 성능은 중요하지만, 이는 _전체_ 속도를 향상시킵니다.

@nildarar은 성능 병목 현상을 겪고 있으며, 이는 다른 접근 방식이 필요합니다.

---

<div class="post-metadata">

### Author: ![nildarar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nildarar/32/331927_2.png) [@nildarar](https://meta.discourse.org/u/nildarar)
#### Post date: [9월 1, 2020, 8:37오전 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/17 "2020-09-01T08:37:45Z")

</div>

담화 성능 병목을 식별하는 데 사용할 수 있는 특별한 도구가 있나요?

 ![image](https://global.discourse-cdn.com/meta/original/3X/9/5/951779a1889455054404532932db0f509756c95a.png)  
_CPU 사용량 순으로 정렬된 htop 화면_

내년에는 사용자 수가 3배로 증가할 것으로 예측되므로, 오늘부터 이 규모에 필요한 자원을 확보해야 합니다.

---

<div class="post-metadata">

### Author: ![marianord](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marianord/32/90502_2.png) [@marianord](https://meta.discourse.org/u/marianord)
#### Post date: [9월 1, 2020, 12:34오후 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/18 "2020-09-01T12:34:15Z")

</div>

> [@nildarar](#):
>
> 디스커스 성능 병목을 식별하는 데 사용할 수 있는 특별한 도구가 있나요?

Prometheus + Grafana와 같은 도구를 사용하면 데이터를 실시간으로 보는 대신 과거 데이터를 수집하여 어떤 일이 일어나고 있는지 더 깊이 있는 분석을 수행할 수 있습니다.

> [@Discourse Prometheus](https://meta.discourse.org/t/prometheus-exporter-plugin-for-discourse/72666):
>
> discourse2Summary Discourse Prometheus is the official [Prometheus](https://prometheus.io/) exporter for Discoursehammer_and_wrenchRepository Link [https://github.com/discourse/discourse-prometheus](https://github.com/discourse/discourse-prometheus)open_bookInstall Guide [How to install plugins in Discourse](https://meta.discourse.org/t/install-plugins-in-discourse/19157) The Discourse Prometheus plugin collects key metrics from Discourse and exposes them in the /metrics path so prometheus can consume them. These metrics can be used to Graph all sorts of data like: Median and 99th percentile time…

---

<div class="post-metadata">

### Author: ![nildarar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nildarar/32/331927_2.png) [@nildarar](https://meta.discourse.org/u/nildarar)
#### Post date: [10월 13, 2020, 6:24오전 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/19 "2020-10-13T06:24:46Z")

</div>

다시 인사드립니다 👋

귀하의 조언에 따라 Prometheus를 설치하고 커뮤니티 성능을 일정 기간 동안 모니터링했습니다. 아래 보고서를 확인하시고, 다른 설치 환경에서 확인한 값들과 비교해 보시기 바랍니다.

 ![image](https://global.discourse-cdn.com/meta/original/3X/8/c/8c47883bc3dd45fde1f29f3f47ee19b95196fb03.png)

 ![image](https://global.discourse-cdn.com/meta/original/3X/6/b/6b09eb4f8743d70e2c22793494337805439bda73.png)

 ![image](https://global.discourse-cdn.com/meta/original/3X/d/8/d892daa807b526003a11135f14ea11ea0ba1a0a9.png)

 ![image](https://global.discourse-cdn.com/meta/original/3X/9/2/925df80f550b25c8fa2dd72af2d8cce4a673a484.png)

 ![image](https://global.discourse-cdn.com/meta/original/3X/4/f/4fa4f6d236e93f02d21b1fe6c3fe748e427ab17a.png)

 ![image](https://global.discourse-cdn.com/meta/original/3X/e/8/e8164e9e9b5b6155a5d136a6c53dbaec87d5cbed.png)

 ![image](https://global.discourse-cdn.com/meta/original/3X/3/5/3590c55589e3820ae902f2de355c93a5e7bebeaf.png)

 ![image](https://global.discourse-cdn.com/meta/original/3X/1/8/1833f5c2fe140d01ebe75d658a0c15125ad6fe38.png)

 ![image](https://global.discourse-cdn.com/meta/original/3X/6/d/6de649723e3e82879458808ebca87459374941fa.png)

 ![image](https://global.discourse-cdn.com/meta/original/3X/8/d/8d6ee65b9b829655e06c4cc5341923f2c23ec558.png)

---

<div class="post-metadata">

### Author: ![Jonathan5](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jonathan5/32/197134_2.png) [@Jonathan5](https://meta.discourse.org/u/Jonathan5)
#### Post date: [10월 13, 2020, 7:42오전 UTC](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456/20 "2020-10-13T07:42:21Z")

</div>

최근 다른 게시글에서 한 사이트가 느려지는 원인이 되었다며 Who’s Online 플러그인을 제거했다는 내용을 읽었습니다.

관련 링크: [Benefits of the who's online plugin? - #6 by neounix](https://meta.discourse.org/t/benefits-of-the-whos-online-plugin/165583/6)

[다음 페이지](https://meta.discourse.org/t/best-configurations-for-speeding-up-standalone-discourse/162456.md?page=2)
