-
Notifications
You must be signed in to change notification settings - Fork 116
feat(binary): лимит памяти для ДвоичныеДанные из конфигурации (#1667) #1670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
johnnyshut
wants to merge
2
commits into
EvilBeaver:develop
Choose a base branch
from
johnnyshut:fix/1667
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+172
−15
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /*---------------------------------------------------------- | ||
| This Source Code Form is subject to the terms of the | ||
| Mozilla Public License, v.2.0. If a copy of the MPL | ||
| was not distributed with this file, You can obtain one | ||
| at http://mozilla.org/MPL/2.0/. | ||
| ----------------------------------------------------------*/ | ||
|
|
||
| namespace ScriptEngine | ||
| { | ||
| /// <summary> | ||
| /// Значения по умолчанию для буферизации двоичных данных в памяти до перехода на временный файл. | ||
| /// </summary> | ||
| public static class BinaryDataConfigurationDefaults | ||
| { | ||
| /// <summary> | ||
| /// Лимит по умолчанию (50 МБ), если в конфигурации не задан ключ binaryData.inMemoryMaxBytes. | ||
| /// </summary> | ||
| public const int InMemoryMaxBytes = 1024 * 1024 * 50; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /*---------------------------------------------------------- | ||
| This Source Code Form is subject to the terms of the | ||
| Mozilla Public License, v.2.0. If a copy of the MPL | ||
| was not distributed with this file, You can obtain one | ||
| at http://mozilla.org/MPL/2.0/. | ||
| ----------------------------------------------------------*/ | ||
|
|
||
| namespace ScriptEngine | ||
| { | ||
| /// <summary> | ||
| /// Лимит объёма данных в памяти для объектов «ДвоичныеДанные» и смежных потоков | ||
| /// до выгрузки во временный файл (байты). | ||
| /// </summary> | ||
| public interface IBinaryDataMemoryLimit | ||
| { | ||
| int MaxBytesInMemory { get; } | ||
| } | ||
|
|
||
| internal sealed class BinaryDataMemoryLimitFromOptions : IBinaryDataMemoryLimit | ||
| { | ||
| public BinaryDataMemoryLimitFromOptions(OneScriptCoreOptions options) | ||
| { | ||
| MaxBytesInMemory = options.BinaryDataInMemoryMaxBytes; | ||
| } | ||
|
|
||
| public int MaxBytesInMemory { get; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /*---------------------------------------------------------- | ||
| This Source Code Form is subject to the terms of the | ||
| Mozilla Public License, v.2.0. If a copy of the MPL | ||
| was not distributed with this file, You can obtain one | ||
| at http://mozilla.org/MPL/2.0/. | ||
| ----------------------------------------------------------*/ | ||
|
|
||
| using System.Threading; | ||
| using OneScript.DependencyInjection; | ||
|
|
||
| namespace ScriptEngine.Machine | ||
| { | ||
| /// <summary> | ||
| /// Лимит памяти для двоичных данных на время выполнения процесса BSL (AsyncLocal). | ||
| /// </summary> | ||
| public static class BinaryDataRuntimeSettings | ||
| { | ||
| private static readonly AsyncLocal<int?> InMemoryMaxBytes = new AsyncLocal<int?>(); | ||
|
|
||
| internal static void PushFromServices(IServiceContainer services) | ||
| { | ||
| var opts = services.TryResolve<IBinaryDataMemoryLimit>(); | ||
| var maxBytes = opts?.MaxBytesInMemory ?? BinaryDataConfigurationDefaults.InMemoryMaxBytes; | ||
| if (maxBytes <= 0) | ||
| maxBytes = BinaryDataConfigurationDefaults.InMemoryMaxBytes; | ||
| InMemoryMaxBytes.Value = maxBytes; | ||
| } | ||
|
|
||
| internal static void Pop() | ||
| { | ||
| InMemoryMaxBytes.Value = null; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Текущий лимит «в памяти до временного файла» для двоичных данных (байты). | ||
| /// Вне процесса BSL возвращает значение по умолчанию из <see cref="BinaryDataConfigurationDefaults.InMemoryMaxBytes"/>. | ||
| /// </summary> | ||
| public static int GetEffectiveInMemoryMaxBytes() | ||
| { | ||
| return InMemoryMaxBytes.Value ?? BinaryDataConfigurationDefaults.InMemoryMaxBytes; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.