-
Notifications
You must be signed in to change notification settings - Fork 120
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
CODENVY-408: Add System RAM check #501
Conversation
} | ||
|
||
private long getBytesAmountFromString(String string) { | ||
if (string.contains("KiB")) { |
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.
Can you give an example of the output?
It seems that you can reuse: this class for parsing
1c9d7a0
to
20d7ef2
Compare
3ec7961
to
a1ccf0c
Compare
startSemaphore.acquire(); | ||
return checkRamAndPropagateStart(config, envName, namespace, workspaceId, callback); | ||
} catch (InterruptedException e) { | ||
throw new ServerException("Starting workspace was interrupted", e); |
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.
it shouldn't happen normally, can you please just rethrow InterruptedException
as ServerException
with the same message like throw new ServerException(e.getMessage(), e)
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.
done
-1 for now. |
980c95e
to
143c082
Compare
@evoevodin fixed all notes, please take a look |
config.getDefaultEnv(), | ||
namespace, | ||
() -> super.startWorkspace(config, namespace, isTemporary, accountId)); | ||
return checkRamAndPropagateLimitedStart(config, |
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.
Why this method is renamed, new name doesn't add anything meaningful
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.
It is a new method that wraps checkRamAndPropagateStart
method
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.
But here limited is not to obvious. Maybe change to limited throughput ?
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.
renamed
591b57f
to
edefd63
Compare
} | ||
|
||
@Test | ||
public void shouldSetSemaphoreToNullIfThroughputPropertyIsLessThenZero() throws Exception { |
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.
Tests that check throughput limitation are also needed
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.
added test:
Lines 567 to 621 in 2abe1b7
@Test(timeOut = 3000) | |
public void shouldPermitToCheckRamOnlyForFiveThreadsAtTheSameTime() throws Exception { | |
when(systemRamInfoProvider.getSystemRamInfo()).thenReturn(new SystemRamInfo(0, parseSize("3 GiB"))); | |
final LimitsCheckingWorkspaceManager manager = spy(new LimitsCheckingWorkspaceManager(2, | |
"3gb", // <- workspaces ram limit | |
"1gb", | |
5, | |
systemRamInfoProvider, | |
null, | |
null, | |
null, | |
null, | |
null, | |
environmentParser, | |
false, | |
false, | |
2000)); | |
doReturn(singletonList(createRuntime("1gb", "1gb"))).when(manager).getByNamespace(anyString()); // <- currently running 2gb | |
/* | |
The count-down latch is needed to reach the throughput limit by acquiring RAM check permits. | |
The lath is configured to 6 invocations: 5 (number of allowed same time requests) + 1 for main thread | |
to be able to release the throughput limit. | |
*/ | |
final CountDownLatch invokeProcessLatch = new CountDownLatch(6); | |
//Pause 5 threads after they will acquire all permits to check RAM. | |
doAnswer(invocationOnMock -> { | |
invokeProcessLatch.countDown(); | |
invokeProcessLatch.await(); | |
return null; | |
}).when(manager).checkRamAndPropagateStart(anyObject(), anyString(), anyString(), anyObject()); | |
Runnable runnable = () -> { | |
try { | |
final WorkspaceCallback callback = mock(WorkspaceCallback.class); | |
manager.checkRamAndPropagateLimitedThroughputStart(createConfig("1gb"), null, "user123", callback); | |
} catch (Exception e) { | |
} | |
}; | |
//Run 7 threads (more than number of allowed same time requests) that want to request RAM check at the same time. | |
ExecutorService executor = Executors.newFixedThreadPool(7); | |
executor.submit(runnable); | |
executor.submit(runnable); | |
executor.submit(runnable); | |
executor.submit(runnable); | |
executor.submit(runnable); | |
executor.submit(runnable); | |
executor.submit(runnable); | |
//Wait for throughput limit will be reached and check that RAM check was performed only in allowed number of threads. | |
verify(manager, timeout(300).times(5)).checkRamAndPropagateStart(anyObject(), anyString(), anyString(), anyObject()); | |
//Execute paused threads to release the throughput limit for other threads. | |
invokeProcessLatch.countDown(); | |
//Wait for throughput limit will be released and check that RAM check was performed in other threads. | |
verify(manager, timeout(300).times(7)).checkRamAndPropagateStart(anyObject(), anyString(), anyString(), anyObject()); | |
} |
99080ac
to
9f8cb9e
Compare
LGTM |
ok for me. Final decision up to @evoevodin and @garagatyi |
@evoevodin wdyt? |
The general approach is okay for me. |
5171982
to
2bc0dd9
Compare
34e3e96
to
835e452
Compare
CODENVY-408: Add System RAM check
What does this PR do?
Checks whole system ram before starting workspace and if it is more than 90% of used ram workspace will not be started. When it will be less then 90% of used ram, a message will be sent by websocket.
What issues does this PR fix or reference?
#408
Tests written?
Yes
@garagatyi @evoevodin please review