This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 284
Add run_benchmark to environments #4372
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 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
Empty file.
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM golemfactory/base:1.5 | ||
|
||
MAINTAINER Golem Tech <[email protected]> | ||
|
||
COPY minilight /golem/minilight | ||
COPY entrypoint.py /golem/ | ||
|
||
ENTRYPOINT ["python3", "/golem/entrypoint.py"] |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from minilight import make_perf_test | ||
|
||
|
||
if __name__ == '__main__': | ||
score = make_perf_test() | ||
print(score) |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from pathlib import Path | ||
|
||
from .src.minilight import make_perf_test as make_perf_test_impl | ||
|
||
TESTFILE = Path(__file__).parent / 'cornellbox.ml.txt' | ||
|
||
|
||
def make_perf_test() -> float: | ||
return make_perf_test_impl(str(TESTFILE)) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import logging | ||
import os | ||
from pathlib import Path | ||
from socket import socket, SocketIO, SHUT_WR | ||
from threading import Thread, Lock | ||
|
@@ -7,7 +8,7 @@ | |
NamedTuple, Tuple, Iterator, Union, Iterable | ||
|
||
from docker.errors import APIError | ||
from twisted.internet.defer import Deferred | ||
from twisted.internet.defer import Deferred, inlineCallbacks | ||
from twisted.internet.threads import deferToThread | ||
from urllib3.contrib.pyopenssl import WrappedSocket | ||
|
||
|
@@ -285,6 +286,12 @@ def _spawn_status_update_thread(_): | |
f"Starting container '{self._container_id}' failed.")) | ||
return deferred_start | ||
|
||
def wait_until_stopped(self) -> Deferred: | ||
def _wait_until_stopped(): | ||
while self.status() == RuntimeStatus.RUNNING: | ||
sleep(1) | ||
return deferToThread(_wait_until_stopped) | ||
|
||
def stop(self) -> Deferred: | ||
with self._status_lock: | ||
self._assert_status(self._status, RuntimeStatus.RUNNING) | ||
|
@@ -404,7 +411,7 @@ class DockerCPUEnvironment(Environment): | |
MIN_MEMORY_MB: ClassVar[int] = 1024 | ||
MIN_CPU_COUNT: ClassVar[int] = 1 | ||
|
||
SHARED_DIR_PATH: ClassVar[str] = '/golem' | ||
SHARED_DIR_PATH: ClassVar[str] = '/golem/work' | ||
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. Is this consistent with Task API? 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. While it's not documented atm, this is what Blender assumes, so I guess this should be added as part of the Task API. |
||
|
||
NETWORK_MODE: ClassVar[str] = 'none' | ||
DNS_SERVERS: ClassVar[List[str]] = [] | ||
|
@@ -431,6 +438,8 @@ class DockerCPUEnvironment(Environment): | |
'sys_tty_config' | ||
] | ||
|
||
BENCHMARK_IMAGE = 'igorgolem/cpu_benchmark:1.0' | ||
|
||
@classmethod | ||
def supported(cls) -> EnvSupportStatus: | ||
logger.info('Checking environment support status...') | ||
|
@@ -505,6 +514,28 @@ def _clean_up(): | |
|
||
return deferToThread(_clean_up) | ||
|
||
@inlineCallbacks | ||
def run_benchmark(self) -> Deferred: | ||
image, tag = self.BENCHMARK_IMAGE.split(':') | ||
yield self.install_prerequisites(DockerPrerequisites( | ||
image=image, | ||
tag=tag, | ||
)) | ||
payload = DockerPayload( | ||
image=image, | ||
tag=tag, | ||
user=None if is_windows() else str(os.getuid()), | ||
env={}, | ||
) | ||
runtime = self.runtime(payload) | ||
yield runtime.prepare() | ||
yield runtime.start() | ||
yield runtime.wait_until_stopped() | ||
# Benchmark is supposed to output a single line containing a float value | ||
score = float(list(runtime.stdout('utf-8'))[0]) | ||
Krigpl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
yield runtime.clean_up() | ||
return score | ||
Krigpl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@classmethod | ||
def metadata(cls) -> EnvMetadata: | ||
return EnvMetadata( | ||
|
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
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
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.
Maybe move this up in class hierarchy and make a part of
Runtime
interface?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.
Maybe the implementation could be moved as well? It's not Docker-specific after all.
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.
I dunno, I'm still considering using
docker.wait()
method since I'm not happy with this kind of active waiting and wouldn't want it to become the default implementation for all envs. Not insisting tho.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.
OK, we don't have any other envs for now. We can reconsider this once we have some more.