This repository has been archived by the owner on Jun 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
jstorm 获取系统(linux)获取可用内存应该使用/proc/meminfo中的MemAvailable #427
Open
superwood
wants to merge
3
commits into
alibaba:master
Choose a base branch
from
superwood:GetMemAvailable
base: master
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.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 |
---|---|---|
|
@@ -185,7 +185,19 @@ public static Long getFreePhysicalMem() { | |
} | ||
return 0L; | ||
} | ||
|
||
public static Long getAvailablePhysicalMem() { | ||
if (!OSInfo.isLinux()) { | ||
return 0L; | ||
} | ||
try { | ||
List<String> lines = IOUtils.readLines(new FileInputStream(PROCFS_MEMINFO)); | ||
String free = lines.get(2).split("\\s+")[1]; | ||
return Long.valueOf(free); | ||
} catch (Exception ignored) { | ||
LOG.warn("failed to get total free memory."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @superwood , 切换到available memory 没有什么问题, 但这里有个兼容性的问题, 如果os 不带“MemAvailable”时,需要额外增加一个逻辑,回退到getFreeMemory There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @longdafeng 没问题,可以在代码里面做一个兼容。 稍后重新提交下。 |
||
} | ||
return 0L; | ||
} | ||
/** | ||
* calcute the disk usage at current filesystem | ||
* @return | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的逻辑,我觉得应该反过来,默认使用mem free,当存在MemAvailable的时候才用这个。
另外,默认的情况下,需要考虑mem free + cache