0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
A platform for community discussion. Free, open, simple. https://www.discourse.org
  • Ruby 58.5%
  • JavaScript 35.5%
  • HTML 3.1%
  • SCSS 2.8%
Find a file
Gerhard Schlager 7e30fa8196 MT: Replace the static thread factor with an adaptive worker gate
This is the last of the upload-tooling PRs, and it deletes the one setting
I could never pick a good default for: thread_count_factor.

The benchmarks (mt/upload-bench-harness) made the problem obvious. For the
exact same code, the best worker count runs from about 8 (local store,
CPU-bound image cooking) up to about 24 (an 8-core box pushing to S3, where
every worker just parks on PUT latency). No single factor is right in both
places, so instead of guessing I let the pipeline find the level while it
runs and adjust as it goes.

Throughput is the primary signal, not CPU. On the local-store image path the
box tops out at only 27-47% CPU while throughput has already flatlined, because
the real ceiling is the single writer thread plus the GVL-serialized Ruby per
upload, not the cores. So "CPU still has headroom" does not mean more workers
will help. The controller watches items/s and, when two increases in a row each
buy less than ~5%, it reverts the last step and holds for a while before probing
again. That plateau guard is what actually catches the ceiling, whatever the
cause (writer thread, GVL, subprocess saturation, S3 bandwidth). CPU stays as a
guard rail: over ~95% it backs off, then waits a couple of ticks because the
in-flight convert subprocesses lag the signal.

Memory comes first, ahead of everything, because an OOM kills the run and a bit
of oscillation does not. When available memory drops near empty the controller
halves the target (allowed below the normal floor) and freezes increases for a
few ticks; when it is merely low it just blocks increases for that tick. It
reads both /proc/meminfo and the cgroup v2 limit and takes the tighter of the
two, so a container capped well under the host RAM is respected. As a second
layer, since one pathological convert can balloon within a single 2s tick, each
task also sets MAGICK_MEMORY_LIMIT/MAGICK_MAP_LIMIT to a sane bound at startup
(unless the operator set one, and never above what policy.xml allows). The
existing max_image_megapixels caps the decode size on top of that.

Pieces:

- WorkerGate: an adjustable semaphore. The pipeline spawns ceiling-many worker
  threads once; a worker takes a permit around each item, so raising or lowering
  the target is just workers waking or parking at the next item boundary, no
  threads killed or respawned. The permit is taken outside with_connection, so a
  parked worker never pins an AR connection.
- ResourceSampler: CPU busy from /proc/stat (which sees the ImageMagick children
  and Postgres, not just our threads), with a Process.times fallback where procfs
  is missing; memory headroom from meminfo + cgroup v2. cgroup v1 is deliberately
  skipped (noted in the code) since the tooling only runs on v2 or bare metal.
- AdaptiveController: the ~2s control loop, with the seed and hard bounds in one
  place. Seed is today's heuristic (usable_cpus * 1.5 * store_factor) so it
  starts familiar; ceiling is min(ar_pool - 8, (external ? 16 : 4) * usable_cpus,
  fd_headroom), and it raises the NOFILE soft limit to the hard one at startup.

I moved WorkerBudget.usable_cpus to a shared Migrations::SystemInfo, since the
converter and the uploads pipeline now both need it.

Not built, on purpose: a PID controller (overkill for a signal this noisy),
loadavg (the 1-minute EMA is far too laggy for 2s ticks), and per-worker
blocked-state introspection.
2026-07-11 00:34:49 +02:00
.agents DEV: symlink to skills (#38573) 2026-03-18 09:41:56 +11:00
.claude DEV: symlink to skills (#38573) 2026-03-18 09:41:56 +11:00
.cursor/rules
.devcontainer Bump devcontainer image to 20260707-0040 (#41503) 2026-07-07 21:40:22 +10:00
.github DEV: Enable Playwright soft reset on CI for all system tests (#41573) 2026-07-09 10:02:42 +08:00
.skills DEV: Improve RSpec agent testing guidance (#41611) 2026-07-10 12:06:53 +08:00
.vscode DEV: Replace JS build system with Rolldown (#35963) 2026-05-29 11:11:55 +01:00
.zed
app UX: Tweaks to default theme screenshots (#41592) 2026-07-10 09:05:41 -04:00
bin DEV: add typescript support for core, themes and plugins (#41478) 2026-07-08 12:57:18 +01:00
config FEATURE: Support bulk user search in the admin users list (#41572) 2026-07-09 10:34:52 -03:00
db FEATURE: Add category scope for AI translations (#41585) 2026-07-10 09:39:20 +08:00
docs DEV: Fix headings for theme setting docs (#41574) 2026-07-09 11:41:54 +10:00
frontend FIX: Print site setting descriptions and setting enums correctly (#41617) 2026-07-10 21:44:47 +08:00
images
lib DEV: Fix stylesheet watcher file matching (#41593) 2026-07-09 16:30:28 -04:00
log
migrations MT: Replace the static thread factor with an adaptive worker gate 2026-07-11 00:34:49 +02:00
patches DEV: Replace JS build system with Rolldown (#35963) 2026-05-29 11:11:55 +01:00
plugins FEATURE: Add AI agent suspend/silence tools with inline approval review (#41497) 2026-07-10 10:59:51 -03:00
public UX: add Klipy branding to gifs picker (#41501) 2026-07-07 10:31:30 +04:00
script FEATURE: Support AI agent workflow uploads and runner (#41042) 2026-06-19 18:06:17 +02:00
spec SECURITY: Private UserField value disclosure via directory_items order sort side-channel (#41598) 2026-07-09 21:52:51 -05:00
stylelint-rules DEV: Exploring a token system (#38700) 2026-04-23 13:47:45 -05:00
test DEV: Clean up smoke-test (#40066) 2026-05-15 12:28:41 +02:00
themes UX: Tweaks to default theme screenshots (#41592) 2026-07-10 09:05:41 -04:00
vendor DEV: move discourse gifs to core (#40162) 2026-06-10 11:35:44 +04:00
.annotaterb.yml
.editorconfig
.git-blame-ignore-revs DEV: Add nested module style commit to .git-blame-ignore-revs 2026-03-20 10:08:56 +01:00
.gitattributes
.gitignore DEV: Replace JS build system with Rolldown (#35963) 2026-05-29 11:11:55 +01:00
.ignore
.jsdoc
.licensed.yml DEPS: Bump oauth from 1.1.3 to 1.1.5 (#40263) 2026-06-04 01:06:17 +02:00
.licensee.json DEV: Bump vitest and vite (#40450) 2026-06-08 10:29:44 +01:00
.npmrc
.pnpmfile.cjs
.prettierignore DEV: add typescript support for core, themes and plugins (#41478) 2026-07-08 12:57:18 +01:00
.prettierrc.cjs
.rspec
.rspec_parallel
.rubocop.yml DEV: Enable Style/RedundantSelf rubocop rule (#40098) 2026-05-19 19:27:45 +02:00
.ruby-gemset.sample
.streerc
AGENTS.md
AI-AGENTS.md DEV: Optimise number of lint calls in AI-AGENTS.md (#40594) 2026-06-05 11:48:49 +08:00
Brewfile
CLAUDE.md
CODEOWNERS
config.ru
CONTRIBUTING.md
COPYRIGHT.md
d
discourse.sublime-project
eslint.config.mjs DEV: add typescript support for core, themes and plugins (#41478) 2026-07-08 12:57:18 +01:00
Gemfile FEATURE: Route all GitHub API requests through one rate-limited client (#40637) 2026-06-15 10:59:10 +02:00
Gemfile.lock MT: Run conversion steps concurrently and split the heavy ones across cores 2026-07-03 11:48:25 +02:00
GEMINI.md
lefthook.yml DEV: add typescript support for core, themes and plugins (#41478) 2026-07-08 12:57:18 +01:00
LICENSE.txt
package.json DEV: add typescript support for core, themes and plugins (#41478) 2026-07-08 12:57:18 +01:00
pnpm-lock.yaml DEV: add typescript support for core, themes and plugins (#41478) 2026-07-08 12:57:18 +01:00
pnpm-workspace.yaml DEV: Configure pnpm builtDependencies (#41332) 2026-07-01 15:26:00 +01:00
Rakefile
README.md DEV: Link to Docker CLI documentation (#40375) 2026-05-28 22:10:18 +02:00
stylelint.config.mjs DEV: Exploring a token system (#38700) 2026-04-23 13:47:45 -05:00
translator.yml
tsconfig-base.json
tsconfig.json
versions.json DEV: Begin development of v2026.7.0-latest 2026-06-30 16:19:27 +02:00

The online home for your community.

github-readme

You can self-host Discourse on your own infrastructure. But if you'd rather skip the setup, maintenance, and server management, we offer official Discourse hosting.

👉 Learn more about Discourse hosting

Discourse is a 100% open-source community platform for those who want complete control over how and where their site is run.

Our platform has been battle-tested for over a decade and continues to evolve to meet users needs for a powerful community platform.

With Discourse, you can:

  • 💬 Create discussion topics to foster meaningful conversations.

  • Connect in real-time with built-in chat.

  • 🎨 Customize your experience with an ever-growing selection of official and community themes.

  • 🤖 Enhance your community with plugins, from chatbots powered by Discourse AI to advanced tools like SQL analysis with the Data Explorer plugin.

To learn more, visit discourse.org and join our support community at meta.discourse.org.

Here are just a few of the incredible communities using Discourse:

discourse-communities

👉 Discover more communities using Discourse

Development

To get your environment set up, follow one of the setup guides:

Before you get started, ensure you have the following minimum versions: Ruby 3.4+, PostgreSQL 15, Redis 7.

For more information, check out the Developer Documentation.

Setting up Discourse

If you want to set up a Discourse forum for production use, see our Discourse Install Guide.

If you're looking for official hosting, see discourse.org/pricing.

Requirements

Discourse supports the latest, stable releases of all major browsers and platforms:

Browsers Tablets Phones
Apple Safari iPadOS iOS
Google Chrome Android Android
Microsoft Edge
Mozilla Firefox

Additionally, we aim to support Safari on iOS 16.4+.

Built With

  • Ruby on Rails — Our back end API is a Rails app. It responds to requests RESTfully in JSON.
  • Ember.js — Our front end is an Ember.js app that communicates with the Rails API.
  • PostgreSQL — Our main data store is in Postgres.
  • Redis — We use Redis as a cache and for transient data.
  • BrowserStack — We use BrowserStack to test on real devices and browsers.

Plus lots of Ruby Gems, a complete list of which is at /main/Gemfile.

Contributing

Build Status

Discourse is 100% free and open source. We encourage and support an active, healthy community that accepts contributions from the public including you!

Before contributing to Discourse:

  1. Please read the complete mission statements on discourse.org. Yes we actually believe this stuff; you should too.
  2. Read and sign the Electronic Discourse Forums Contribution License Agreement.
  3. Dig into CONTRIBUTING.MD, which covers submitting bugs, requesting new features, preparing your code for a pull request, etc.
  4. Always strive to collaborate with mutual respect.
  5. Not sure what to work on? We've got some ideas.

We look forward to seeing your pull requests!

Security

We take security very seriously at Discourse; all our code is 100% open source and peer reviewed. Please read our security guide for an overview of security measures in Discourse, or if you wish to report a security issue.

Security fixes are listed in the release notes for each version.

The Discourse Team

The original Discourse code contributors can be found in AUTHORS.MD. For a complete list of the many individuals that contributed to the design and implementation of Discourse, please refer to the official Discourse blog and GitHub's list of contributors.

Copyright 2014 - 2025 Civilized Discourse Construction Kit, Inc.

Licensed under the GNU General Public License Version 2.0 (or later); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Discourse logo and “Discourse Forum” ®, Civilized Discourse Construction Kit, Inc.

Accessibility

To guide our ongoing effort to build accessible software we follow the W3Cs Web Content Accessibility Guidelines (WCAG). If you'd like to report an accessibility issue that makes it difficult for you to use Discourse, email accessibility@discourse.org. For more information visit discourse.org/accessibility.

Dedication

Discourse is built with love, Internet style.

For over a decade, our amazing community has helped shape Discourse into what it is today. Your support, feedback, and contributions have been invaluable in making Discourse a powerful and versatile platform.

Were deeply grateful for every feature request, bug report, and discussion that has driven Discourse forward. Thank you for being a part of this journey—we couldnt have done it without you!