アセットの事前コンパイルによる過剰なメモリ消費

@david さん、こんにちは。

アセットのビルドタスクが完了すると、メモリ使用量はすぐに減少しますか?

いいえ。さらに詳しく調査したところ、何か奇妙なことが起きているようです。

precompiling:build 実行前のプラグインリストは以下の通りです。

/var/www/discourse$ ls plugins/
automation           discourse-akismet           discourse-data-explorer  discourse-hcaptcha           discourse-microsoft-auth  discourse-post-voting  discourse-saved-searches       discourse-user-notes           styleguide
chat                 discourse-apple-auth        discourse-details        discourse-lazy-videos        discourse-narrative-bot   discourse-presence     discourse-solved               discourse-zendesk-plugin
checklist            discourse-assign            discourse-docs           discourse-local-dates        discourse-oauth2-basic    discourse-prometheus   discourse-subscriptions        footnote
discourse-adplugin   discourse-cakeday           discourse-gamification   discourse-login-with-amazon  discourse-openid-connect  discourse-reactions    discourse-templates            msgraph-poll-discourse-plugin
discourse-affiliate  discourse-calendar          discourse-github         discourse-lti                discourse-patreon         discourse-rewind       discourse-topic-trade-buttons  poll
discourse-ai         discourse-chat-integration  discourse-graphviz       discourse-math               discourse-policy          discourse-rss-polling  discourse-topic-voting         spoiler-alert

コードのデバッグ中に、以下の動作に気づきました。

/var/www/discourse$ script/rails runner "AssetProcessor.ember_version"
プラグイン名は 'msgraph-polling' ですが、プラグインディレクトリ名は 'msgraph-poll-discourse-plugin' です

# ここから永遠にフリーズ

AssetProcessor.ember_version は、discourse/lib/plugin/js_manager.rb at latest · discourse/discourse · GitHub の行に対応しています。

そこで、このファイルにいくつかの変更を加えました(添付参照)。具体的には、処理中にどこで停止するかを出力し、discourse/lib/plugin/js_manager.rb at latest · discourse/discourse · GitHubAssetProcessor.ember_version を削除して、16 進数生成を継続するために 5 を直接設定しました。

その後、discourse/lib/plugin/js_manager.rb at latest · discourse/discourse · GitHub で並列度を 1 に減らして処理を容易にしました(parallel_count = [Etc.nprocessors, 1].min)。

この後、bundle exec rake assets:precompile:build を実行した結果は以下の通りです。

/var/www/discourse$ bundle exec rake assets:precompile:build
プラグイン名は 'msgraph-polling' ですが、プラグインディレクトリ名は 'msgraph-poll-discourse-plugin' です
[assemble_ember_build] 既存の Core Ember ビルドを再利用しています。完了しました。
プラグイン名は 'msgraph-polling' ですが、プラグインディレクトリ名は 'msgraph-poll-discourse-plugin' です
[Plugin::JsManager] 49 個のプラグインをコンパイル中...
automation をコンパイル中...
ファイルのソート終了
ファイルのソート終了
        hex_digest 103dc9ebebb80a7065cb8dd41fb3356b30f151f7
########### 再帰処理

# ここから永遠にフリーズし、メモリを全容量消費

これは ulimit の値(現在は unlimited に設定されており、ulimit -n 1048576; のような値ではなく)に関連している可能性が高いと考えています。再帰呼び出しを通じて非常に多くのファイルを開き、その内容をメモリに格納しているためです。

この状況が何か思い当たる節がありますか?あるいは、問題の原因について他のヒントがあれば教えてください。

よろしくお願いいたします。

Ismael

js_manager.rb.txt|添付ファイル (7.7 KB)