Skip to content
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

Merged
merged 5 commits into from
Sep 27, 2016
Merged

CODENVY-408: Add System RAM check #501

merged 5 commits into from
Sep 27, 2016

Conversation

vinokurig
Copy link
Contributor

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

}

private long getBytesAmountFromString(String string) {
if (string.contains("KiB")) {
Copy link
Contributor

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

@vinokurig vinokurig force-pushed the CODENVY-408 branch 2 times, most recently from 1c9d7a0 to 20d7ef2 Compare August 3, 2016 11:08
@vinokurig vinokurig force-pushed the CODENVY-408 branch 6 times, most recently from 3ec7961 to a1ccf0c Compare August 17, 2016 13:03
startSemaphore.acquire();
return checkRamAndPropagateStart(config, envName, namespace, workspaceId, callback);
} catch (InterruptedException e) {
throw new ServerException("Starting workspace was interrupted", e);
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@voievodin
Copy link
Contributor

voievodin commented Aug 17, 2016

-1 for now.
The design and implementation of the component for ram checking must be reworked.
I didn't check all the code, but i think that i left more than enough comments for now, please check&answer where necessary.

@vinokurig vinokurig force-pushed the CODENVY-408 branch 4 times, most recently from 980c95e to 143c082 Compare August 26, 2016 06:23
@vinokurig
Copy link
Contributor Author

@evoevodin fixed all notes, please take a look

config.getDefaultEnv(),
namespace,
() -> super.startWorkspace(config, namespace, isTemporary, accountId));
return checkRamAndPropagateLimitedStart(config,
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

@vinokurig vinokurig force-pushed the CODENVY-408 branch 2 times, most recently from 591b57f to edefd63 Compare September 7, 2016 13:07
}

@Test
public void shouldSetSemaphoreToNullIfThroughputPropertyIsLessThenZero() throws Exception {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added test:

@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());
}

@vinokurig vinokurig force-pushed the CODENVY-408 branch 7 times, most recently from 99080ac to 9f8cb9e Compare September 9, 2016 09:11
@garagatyi
Copy link
Contributor

LGTM

@skabashnyuk
Copy link
Contributor

ok for me. Final decision up to @evoevodin and @garagatyi

@skabashnyuk
Copy link
Contributor

@evoevodin wdyt?

@voievodin
Copy link
Contributor

The general approach is okay for me.
@vinokurig it was a long discussion, go ahead and finally merge it

@vinokurig vinokurig merged commit 1c8d378 into master Sep 27, 2016
@vinokurig vinokurig deleted the CODENVY-408 branch September 27, 2016 17:35
mshaposhnik pushed a commit that referenced this pull request Sep 28, 2016
CODENVY-408: Add System RAM check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants