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

Move all config constants into single file. #1192

Merged
merged 18 commits into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Expose config through Python.
  • Loading branch information
robertnishihara committed Nov 8, 2017
commit 9945785a7c8014c50549d6aee120bb7f56323508
1 change: 1 addition & 0 deletions python/ray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
e.args += (helpful_message,)
raise

from ray.local_scheduler import config
from ray.worker import (error_info, init, connect, disconnect,
get, put, wait, remote, log_event, log_span,
flush_log, get_gpu_ids, get_webui_url,
Expand Down
2 changes: 1 addition & 1 deletion python/ray/local_scheduler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ray.core.src.local_scheduler.liblocal_scheduler_library import (
Task, LocalSchedulerClient, ObjectID, check_simple_value, task_from_string,
task_to_string)
task_to_string, config)
from .local_scheduler_services import start_local_scheduler

__all__ = ["Task", "LocalSchedulerClient", "ObjectID", "check_simple_value",
Expand Down
6 changes: 2 additions & 4 deletions python/ray/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

# These variables must be kept in sync with the C codebase.
# common/common.h
HEARTBEAT_TIMEOUT_MILLISECONDS = 100
NUM_HEARTBEATS_TIMEOUT = 100
DB_CLIENT_ID_SIZE = 20
NIL_ID = b"\xff" * DB_CLIENT_ID_SIZE

Expand Down Expand Up @@ -580,7 +578,7 @@ def run(self):
plasma_manager_ids = list(self.live_plasma_managers.keys())
for plasma_manager_id in plasma_manager_ids:
if ((self.live_plasma_managers[plasma_manager_id]) >=
NUM_HEARTBEATS_TIMEOUT):
ray.config.NUM_HEARTBEATS_TIMEOUT()):
log.warn("Timed out {}".format(PLASMA_MANAGER_CLIENT_TYPE))
# Remove the plasma manager from the managers whose
# heartbeats we're tracking.
Expand All @@ -599,7 +597,7 @@ def run(self):

# Wait for a heartbeat interval before processing the next round of
# messages.
time.sleep(HEARTBEAT_TIMEOUT_MILLISECONDS * 1e-3)
time.sleep(ray.config.HEARTBEAT_TIMEOUT_MILLISECONDS() * 1e-3)


if __name__ == "__main__":
Expand Down
6 changes: 1 addition & 5 deletions python/ray/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@
NIL_FUNCTION_ID = NIL_ID
NIL_ACTOR_ID = NIL_ID

# When performing ray.get, wait 1 second before attemping to reconstruct and
# fetch the object again.
GET_TIMEOUT_MILLISECONDS = 1000

# This must be kept in sync with the `error_types` array in
# common/state/error_table.h.
OBJECT_HASH_MISMATCH_ERROR_TYPE = b"object_hash_mismatch"
Expand Down Expand Up @@ -452,7 +448,7 @@ def get_object(self, object_ids):
object_ids_to_fetch[i:(i + fetch_request_size)])
results = self.retrieve_and_deserialize(
object_ids_to_fetch,
max([GET_TIMEOUT_MILLISECONDS, int(0.01 * len(unready_ids))]))
max([ray.config.GET_TIMEOUT_MILLISECONDS(), int(0.01 * len(unready_ids))]))
# Remove any entries for objects we received during this iteration
# so we don't retrieve the same object twice.
for i, val in enumerate(results):
Expand Down
8 changes: 0 additions & 8 deletions src/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ extern "C" {

#include "state/config.h"

// /** The duration between heartbeats. These are sent by the plasma manager and
// * local scheduler. */
// #define HEARTBEAT_TIMEOUT_MILLISECONDS 100
// /** If a component has not sent a heartbeat in the last NUM_HEARTBEATS_TIMEOUT
// * heartbeat intervals, the global scheduler or monitor process will report it
// * as dead to the db_client table. */
// #define NUM_HEARTBEATS_TIMEOUT 100

/** Definitions for Ray logging levels. */
#define RAY_COMMON_DEBUG 0
#define RAY_COMMON_INFO 1
Expand Down
10 changes: 0 additions & 10 deletions src/common/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@

#include <vector>

// #define RAY_PROTOCOL_VERSION 0x0000000000000000

// /* Number of times we try binding to a socket. */
// #define NUM_BIND_ATTEMPTS 5
// #define BIND_TIMEOUT_MS 100
//
// /* Number of times we try connecting to a socket. */
// #define NUM_CONNECT_ATTEMPTS 50
// #define CONNECT_TIMEOUT_MS 100

struct aeEventLoop;
typedef aeEventLoop event_loop;

Expand Down
3 changes: 0 additions & 3 deletions src/common/lib/python/common_extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,6 @@ PyObject *PyTask_make(TaskSpec *task_spec, int64_t task_size) {

/* Define the methods for the module. */

// #define SIZE_LIMIT 100
// #define NUM_ELEMENTS_LIMIT 1000

#if PY_MAJOR_VERSION >= 3
#define PyInt_Check PyLong_Check
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/common/lib/python/common_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ PyObject *check_simple_value(PyObject *self, PyObject *args);
PyObject *PyTask_to_string(PyObject *, PyObject *args);
PyObject *PyTask_from_string(PyObject *, PyObject *args);

PyObject *compute_put_id(PyObject *self, PyObject *args);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed because this was unused.

PyObject *PyTask_make(TaskSpec *task_spec, int64_t task_size);

#endif /* COMMON_EXTENSION_H */
100 changes: 100 additions & 0 deletions src/common/lib/python/config_extension.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#include <Python.h>
#include "bytesobject.h"

#include "common.h"

PyObject *PyRayConfig_RAY_PROTOCOL_VERSION(PyObject *self) {
return PyLong_FromLongLong(RAY_PROTOCOL_VERSION);
}

PyObject *PyRayConfig_HEARTBEAT_TIMEOUT_MILLISECONDS(PyObject *self) {
return PyLong_FromLongLong(HEARTBEAT_TIMEOUT_MILLISECONDS);
}

PyObject *PyRayConfig_NUM_HEARTBEATS_TIMEOUT(PyObject *self) {
return PyLong_FromLongLong(NUM_HEARTBEATS_TIMEOUT);
}

PyObject *PyRayConfig_GET_TIMEOUT_MILLISECONDS(PyObject *self) {
return PyLong_FromLongLong(GET_TIMEOUT_MILLISECONDS);
}

PyObject *PyRayConfig_NUM_BIND_ATTEMPTS(PyObject *self) {
return PyLong_FromLongLong(NUM_BIND_ATTEMPTS);
}

PyObject *PyRayConfig_BIND_TIMEOUT_MS(PyObject *self) {
return PyLong_FromLongLong(BIND_TIMEOUT_MS);
}

PyObject *PyRayConfig_NUM_CONNECT_ATTEMPTS(PyObject *self) {
return PyLong_FromLongLong(NUM_CONNECT_ATTEMPTS);
}

PyObject *PyRayConfig_CONNECT_TIMEOUT_MS(PyObject *self) {
return PyLong_FromLongLong(CONNECT_TIMEOUT_MS);
}

PyObject *PyRayConfig_kLocalSchedulerFetchTimeoutMilliseconds(PyObject *self) {
return PyLong_FromLongLong(kLocalSchedulerFetchTimeoutMilliseconds);
}

PyObject *PyRayConfig_kLocalSchedulerReconstructionTimeoutMilliseconds(PyObject *self) {
return PyLong_FromLongLong(kLocalSchedulerReconstructionTimeoutMilliseconds);
}

PyObject *PyRayConfig_KILL_WORKER_TIMEOUT_MILLISECONDS(PyObject *self) {
return PyLong_FromLongLong(KILL_WORKER_TIMEOUT_MILLISECONDS);
}

PyObject *PyRayConfig_kDefaultNumCPUs(PyObject *self) {
return PyFloat_FromDouble(kDefaultNumCPUs);
}

PyObject *PyRayConfig_kDefaultNumGPUs(PyObject *self) {
return PyFloat_FromDouble(kDefaultNumGPUs);
}

PyObject *PyRayConfig_kDefaultNumCustomResource(PyObject *self) {
return PyFloat_FromDouble(kDefaultNumCustomResource);
}

PyObject *PyRayConfig_MANAGER_TIMEOUT(PyObject *self) {
return PyLong_FromLongLong(MANAGER_TIMEOUT);
}

PyObject *PyRayConfig_BUFSIZE(PyObject *self) {
return PyLong_FromLongLong(BUFSIZE);
}

PyObject *PyRayConfig_max_time_for_handler(PyObject *self) {
return PyLong_FromLongLong(max_time_for_handler);
}

PyObject *PyRayConfig_SIZE_LIMIT(PyObject *self) {
return PyLong_FromLongLong(SIZE_LIMIT);
}

PyObject *PyRayConfig_NUM_ELEMENTS_LIMIT(PyObject *self) {
return PyLong_FromLongLong(NUM_ELEMENTS_LIMIT);
}

PyObject *PyRayConfig_max_time_for_loop(PyObject *self) {
return PyLong_FromLongLong(max_time_for_loop);
}

PyObject *PyRayConfig_REDIS_DB_CONNECT_RETRIES(PyObject *self) {
return PyLong_FromLongLong(REDIS_DB_CONNECT_RETRIES);
}

PyObject *PyRayConfig_REDIS_DB_CONNECT_WAIT_MS(PyObject *self) {
return PyLong_FromLongLong(REDIS_DB_CONNECT_WAIT_MS);
}

PyObject *PyRayConfig_PLASMA_DEFAULT_RELEASE_DELAY(PyObject *self) {
return PyLong_FromLongLong(PLASMA_DEFAULT_RELEASE_DELAY);
}

PyObject *PyRayConfig_kL3CacheSizeBytes(PyObject *self) {
return PyLong_FromLongLong(kL3CacheSizeBytes);
}
89 changes: 89 additions & 0 deletions src/common/lib/python/config_extension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#ifndef CONFIG_EXTENSION_H
#define CONFIG_EXTENSION_H

#include <Python.h>

#include "common.h"

// clang-format off
typedef struct {
PyObject_HEAD
} PyRayConfig;
// clang-format on

PyObject *PyRayConfig_HEARTBEAT_TIMEOUT_MILLISECONDS(PyObject *self);

static PyMethodDef PyRayConfig_methods[] = {
{"RAY_PROTOCOL_VERSION", (PyCFunction) PyRayConfig_RAY_PROTOCOL_VERSION, METH_NOARGS, "Return RAY_PROTOCOL_VERSION"},
{PyRayConfig_HEARTBEAT_TIMEOUT_MILLISECONDS"", (PyCFunction) PyRayConfig_HEARTBEAT_TIMEOUT_MILLISECONDS, METH_NOARGS, "Return HEARTBEAT_TIMEOUT_MILLISECONDS"},
{"NUM_HEARTBEATS_TIMEOUT", (PyCFunction) PyRayConfig_NUM_HEARTBEATS_TIMEOUT, METH_NOARGS, "Return NUM_HEARTBEATS_TIMEOUT"},
{"GET_TIMEOUT_MILLISECONDS", (PyCFunction) PyRayConfig_GET_TIMEOUT_MILLISECONDS, METH_NOARGS, "Return GET_TIMEOUT_MILLISECONDS"},
{"NUM_BIND_ATTEMPTS", (PyCFunction) PyRayConfig_NUM_BIND_ATTEMPTS, METH_NOARGS, "Return NUM_BIND_ATTEMPTS"},
{"BIND_TIMEOUT_MS", (PyCFunction) PyRayConfig_BIND_TIMEOUT_MS, METH_NOARGS, "Return BIND_TIMEOUT_MS"},
{"NUM_CONNECT_ATTEMPTS", (PyCFunction) PyRayConfig_NUM_CONNECT_ATTEMPTS, METH_NOARGS, "Return NUM_CONNECT_ATTEMPTS"},
{"CONNECT_TIMEOUT_MS", (PyCFunction) PyRayConfig_CONNECT_TIMEOUT_MS, METH_NOARGS, "Return CONNECT_TIMEOUT_MS"},
{"kLocalSchedulerFetchTimeoutMilliseconds", (PyCFunction) PyRayConfig_kLocalSchedulerFetchTimeoutMilliseconds, METH_NOARGS, "Return kLocalSchedulerFetchTimeoutMilliseconds"},
{"kLocalSchedulerReconstructionTimeoutMilliseconds", (PyCFunction) PyRayConfig_kLocalSchedulerReconstructionTimeoutMilliseconds, METH_NOARGS, "Return kLocalSchedulerReconstructionTimeoutMilliseconds"},
{"KILL_WORKER_TIMEOUT_MILLISECONDS", (PyCFunction) PyRayConfig_KILL_WORKER_TIMEOUT_MILLISECONDS, METH_NOARGS, "Return KILL_WORKER_TIMEOUT_MILLISECONDS"},
{"kDefaultNumCPUs", (PyCFunction) PyRayConfig_kDefaultNumCPUs, METH_NOARGS, "Return kDefaultNumCPUs"},
{"kDefaultNumGPUs", (PyCFunction) PyRayConfig_kDefaultNumGPUs, METH_NOARGS, "Return kDefaultNumGPUs"},
{"kDefaultNumCustomResource", (PyCFunction) PyRayConfig_kDefaultNumCustomResource, METH_NOARGS, "Return kDefaultNumCustomResource"},
{"MANAGER_TIMEOUT", (PyCFunction) PyRayConfig_MANAGER_TIMEOUT, METH_NOARGS, "Return MANAGER_TIMEOUT"},
{"BUFSIZE", (PyCFunction) PyRayConfig_BUFSIZE, METH_NOARGS, "Return BUFSIZE"},
{"max_time_for_handler", (PyCFunction) PyRayConfig_max_time_for_handler, METH_NOARGS, "Return max_time_for_handler"},
{"SIZE_LIMIT", (PyCFunction) PyRayConfig_SIZE_LIMIT, METH_NOARGS, "Return SIZE_LIMIT"},
{"NUM_ELEMENTS_LIMIT", (PyCFunction) PyRayConfig_NUM_ELEMENTS_LIMIT, METH_NOARGS, "Return NUM_ELEMENTS_LIMIT"},
{"max_time_for_loop", (PyCFunction) PyRayConfig_max_time_for_loop, METH_NOARGS, "Return max_time_for_loop"},
{"REDIS_DB_CONNECT_RETRIES", (PyCFunction) PyRayConfig_REDIS_DB_CONNECT_RETRIES, METH_NOARGS, "Return REDIS_DB_CONNECT_RETRIES"},
{"REDIS_DB_CONNECT_WAIT_MS", (PyCFunction) PyRayConfig_REDIS_DB_CONNECT_WAIT_MS, METH_NOARGS, "Return REDIS_DB_CONNECT_WAIT_MS"},
{"PLASMA_DEFAULT_RELEASE_DELAY", (PyCFunction) PyRayConfig_PLASMA_DEFAULT_RELEASE_DELAY, METH_NOARGS, "Return PLASMA_DEFAULT_RELEASE_DELAY"},
{"kL3CacheSizeBytes", (PyCFunction) PyRayConfig_kL3CacheSizeBytes, METH_NOARGS, "Return kL3CacheSizeBytes"},
{NULL} /* Sentinel */
};

static PyMemberDef PyRayConfig_members[] = {
{NULL} /* Sentinel */
};

PyTypeObject PyRayConfigType = {
PyVarObject_HEAD_INIT(NULL, 0) /* ob_size */
"common.RayConfig", /* tp_name */
sizeof(PyRayConfig), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"RayConfig object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
PyRayConfig_methods, /* tp_methods */
PyRayConfig_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
};

#endif /* CONFIG_EXTENSION_H */
64 changes: 64 additions & 0 deletions src/common/state/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef CONFIG_H
#define CONFIG_H

#include <math.h>
#include <stdint.h>

constexpr int64_t RAY_PROTOCOL_VERSION = 0x0000000000000000;

/** The duration between heartbeats. These are sent by the plasma manager and
* local scheduler. */
constexpr int64_t HEARTBEAT_TIMEOUT_MILLISECONDS = 100;
/** If a component has not sent a heartbeat in the last NUM_HEARTBEATS_TIMEOUT
* heartbeat intervals, the global scheduler or monitor process will report it
* as dead to the db_client table. */
constexpr int64_t NUM_HEARTBEATS_TIMEOUT = 100;

/** When performing ray.get, wait 1 second before attemping to reconstruct and
* fetch the object again. */
constexpr int64_t GET_TIMEOUT_MILLISECONDS = 1000;

/* Number of times we try binding to a socket. */
constexpr int64_t NUM_BIND_ATTEMPTS = 5;
constexpr int64_t BIND_TIMEOUT_MS = 100;

/* Number of times we try connecting to a socket. */
constexpr int64_t NUM_CONNECT_ATTEMPTS = 50;
constexpr int64_t CONNECT_TIMEOUT_MS = 100;

/* The duration that the local scheduler will wait before reinitiating a fetch
* request for a missing task dependency. This time may adapt based on the
* number of missing task dependencies. */
constexpr int64_t kLocalSchedulerFetchTimeoutMilliseconds = 1000;
/* The duration that the local scheduler will wait between initiating
* reconstruction calls for missing task dependencies. If there are many missing
* task dependencies, we will only iniate reconstruction calls for some of them
* each time. */
constexpr int64_t kLocalSchedulerReconstructionTimeoutMilliseconds = 1000;

/* The duration that we wait after sending a worker SIGTERM before sending the
* worker SIGKILL. */
constexpr int64_t KILL_WORKER_TIMEOUT_MILLISECONDS = 100;

constexpr double kDefaultNumCPUs = INT16_MAX;
constexpr double kDefaultNumGPUs = 0;
constexpr double kDefaultNumCustomResource = INFINITY;

constexpr int64_t MANAGER_TIMEOUT = 1000;
constexpr int64_t BUFSIZE = 4096;

constexpr int64_t max_time_for_handler = 1000;

constexpr int64_t SIZE_LIMIT = 100;
constexpr int64_t NUM_ELEMENTS_LIMIT = 1000;

constexpr int64_t max_time_for_loop = 1000;

/* Allow up to 5 seconds for connecting to Redis. */
constexpr int64_t REDIS_DB_CONNECT_RETRIES = 50;
constexpr int64_t REDIS_DB_CONNECT_WAIT_MS = 100;

constexpr int64_t PLASMA_DEFAULT_RELEASE_DELAY = 64;
constexpr int64_t kL3CacheSizeBytes = 100000000;

#endif /* CONFIG_H */
1 change: 0 additions & 1 deletion src/common/state/redis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ const std::vector<std::string> redis_get_cached_db_clients(
}

int64_t end_time = current_time_ms();
//int64_t max_time_for_loop = 1000;
if (end_time - start_time > max_time_for_loop) {
LOG_WARN(
"calling redis_get_cached_db_client in a loop in with %zu manager IDs "
Expand Down
4 changes: 0 additions & 4 deletions src/common/state/redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
#include "hiredis/hiredis.h"
#include "hiredis/async.h"

// /* Allow up to 5 seconds for connecting to Redis. */
// #define REDIS_DB_CONNECT_RETRIES 50
// #define REDIS_DB_CONNECT_WAIT_MS 100

#define LOG_REDIS_ERROR(context, M, ...) \
LOG_ERROR("Redis error %d %s; %s", context->err, context->errstr, M)

Expand Down
Loading