-
Notifications
You must be signed in to change notification settings - Fork 566
[INLONG-8251][Agent] Add global memory limit for file collect #8253
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
88278fd
[INLONG-8244][Agent]thread leaks after job finished
justinwwhuang 02fd747
[INLONG-8244][Agent]thread leaks after job finished
justinwwhuang 797e83d
[INLONG-8244][Agent]thread leaks after job finished
justinwwhuang 189ba4a
[INLONG-8251][agent] add global memory limit for file collect
justinwwhuang 377f5f2
Merge branch 'apache:master' into develop
justinwwhuang a5770ec
[INLONG-8251][agent] add global memory limit for file collect
justinwwhuang 3802fa2
[INLONG-8251][agent] add global memory limit for file collect
justinwwhuang b06b17b
[INLONG-8251][agent] add global memory limit for file collect
justinwwhuang 17ae91f
[INLONG-8251][agent] add global memory limit for file collect
justinwwhuang 119a28f
[INLONG-8251][agent] add global memory limit for file collect
justinwwhuang be14d80
[INLONG-8251][agent] add global memory limit for file collect
justinwwhuang 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
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
115 changes: 115 additions & 0 deletions
115
inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/task/MemoryManager.java
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,115 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.inlong.agent.core.task; | ||
|
|
||
| import org.apache.inlong.agent.conf.AgentConfiguration; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.Semaphore; | ||
|
|
||
| import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_GLOBAL_CHANNEL_PERMIT; | ||
| import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_GLOBAL_READER_QUEUE_PERMIT; | ||
| import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_GLOBAL_READER_SOURCE_PERMIT; | ||
| import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_GLOBAL_WRITER_PERMIT; | ||
| import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_GLOBAL_CHANNEL_PERMIT; | ||
| import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_GLOBAL_READER_QUEUE_PERMIT; | ||
| import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_GLOBAL_READER_SOURCE_PERMIT; | ||
| import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_GLOBAL_WRITER_PERMIT; | ||
|
|
||
| /** | ||
| * used to limit global memory to avoid oom | ||
| */ | ||
| public class MemoryManager { | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(MemoryManager.class); | ||
| private static volatile MemoryManager memoryManager = null; | ||
| private final AgentConfiguration conf; | ||
| private ConcurrentHashMap<String, Semaphore> semaphoreMap = new ConcurrentHashMap<>(); | ||
|
|
||
| private MemoryManager() { | ||
| this.conf = AgentConfiguration.getAgentConf(); | ||
| Semaphore semaphore = null; | ||
| semaphore = new Semaphore( | ||
| conf.getInt(AGENT_GLOBAL_READER_SOURCE_PERMIT, DEFAULT_AGENT_GLOBAL_READER_SOURCE_PERMIT)); | ||
| semaphoreMap.put(AGENT_GLOBAL_READER_SOURCE_PERMIT, semaphore); | ||
justinwwhuang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| semaphore = new Semaphore( | ||
| conf.getInt(AGENT_GLOBAL_READER_QUEUE_PERMIT, DEFAULT_AGENT_GLOBAL_READER_QUEUE_PERMIT)); | ||
| semaphoreMap.put(AGENT_GLOBAL_READER_QUEUE_PERMIT, semaphore); | ||
|
|
||
| semaphore = new Semaphore( | ||
| conf.getInt(AGENT_GLOBAL_CHANNEL_PERMIT, DEFAULT_AGENT_GLOBAL_CHANNEL_PERMIT)); | ||
| semaphoreMap.put(AGENT_GLOBAL_CHANNEL_PERMIT, semaphore); | ||
|
|
||
| semaphore = new Semaphore( | ||
| conf.getInt(AGENT_GLOBAL_WRITER_PERMIT, DEFAULT_AGENT_GLOBAL_WRITER_PERMIT)); | ||
| semaphoreMap.put(AGENT_GLOBAL_WRITER_PERMIT, semaphore); | ||
| } | ||
|
|
||
| /** | ||
| * manager singleton | ||
| */ | ||
| public static MemoryManager getInstance() { | ||
| if (memoryManager == null) { | ||
| synchronized (MemoryManager.class) { | ||
| if (memoryManager == null) { | ||
| memoryManager = new MemoryManager(); | ||
| } | ||
| } | ||
| } | ||
| return memoryManager; | ||
| } | ||
|
|
||
| public boolean tryAcquire(String semaphoreName, int permit) { | ||
| Semaphore semaphore = semaphoreMap.get(semaphoreName); | ||
| if (semaphore == null) { | ||
| LOGGER.error("tryAcquire {} not exist"); | ||
| return false; | ||
| } | ||
| return semaphore.tryAcquire(permit); | ||
| } | ||
|
|
||
| public void release(String semaphoreName, int permit) { | ||
| Semaphore semaphore = semaphoreMap.get(semaphoreName); | ||
| if (semaphore == null) { | ||
| LOGGER.error("release {} not exist"); | ||
| return; | ||
| } | ||
| semaphore.release(permit); | ||
| } | ||
|
|
||
| public void printDetail(String semaphoreName) { | ||
| Semaphore semaphore = semaphoreMap.get(semaphoreName); | ||
| if (semaphore == null) { | ||
| LOGGER.error("printDetail {} not exist"); | ||
| return; | ||
| } | ||
| LOGGER.info("permit left {} wait {} {}", semaphore.availablePermits(), semaphore.getQueueLength(), | ||
| semaphoreName); | ||
| } | ||
|
|
||
| public void printAll() { | ||
| printDetail(AGENT_GLOBAL_READER_SOURCE_PERMIT); | ||
| printDetail(AGENT_GLOBAL_READER_QUEUE_PERMIT); | ||
| printDetail(AGENT_GLOBAL_CHANNEL_PERMIT); | ||
| printDetail(AGENT_GLOBAL_WRITER_PERMIT); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.