mirror of
https://github.com/wassname/ray.git
synced 2026-09-11 12:43:20 +08:00
Move all config constants into single file. (#1192)
* Initial pass at factoring out C++ configuration into a single file. * Expose config through Python. * Forward declarations. * Fixes with Python extensions * Remove old code. * Consistent naming for constants. * Fixes * Fix linting. * More linting. * Whitespace * rename config -> _config. * Move config inside a class. * update naming convention * Fix linting. * More linting * More linting. * Add in some more constants. * Fix linting
This commit is contained in:
committed by
Philipp Moritz
parent
a8032b9ca1
commit
1c6b30b5e2
+1
-7
@@ -25,13 +25,7 @@ extern "C" {
|
||||
#include "plasma/common.h"
|
||||
#include "arrow/util/macros.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
|
||||
#include "state/ray_config.h"
|
||||
|
||||
/** Definitions for Ray logging levels. */
|
||||
#define RAY_COMMON_DEBUG 0
|
||||
|
||||
+7
-7
@@ -102,10 +102,10 @@ int connect_ipc_sock_retry(const char *socket_pathname,
|
||||
int64_t timeout) {
|
||||
/* Pick the default values if the user did not specify. */
|
||||
if (num_retries < 0) {
|
||||
num_retries = NUM_CONNECT_ATTEMPTS;
|
||||
num_retries = RayConfig::instance().num_connect_attempts();
|
||||
}
|
||||
if (timeout < 0) {
|
||||
timeout = CONNECT_TIMEOUT_MS;
|
||||
timeout = RayConfig::instance().connect_timeout_milliseconds();
|
||||
}
|
||||
|
||||
CHECK(socket_pathname);
|
||||
@@ -163,10 +163,10 @@ int connect_inet_sock_retry(const char *ip_addr,
|
||||
int64_t timeout) {
|
||||
/* Pick the default values if the user did not specify. */
|
||||
if (num_retries < 0) {
|
||||
num_retries = NUM_CONNECT_ATTEMPTS;
|
||||
num_retries = RayConfig::instance().num_connect_attempts();
|
||||
}
|
||||
if (timeout < 0) {
|
||||
timeout = CONNECT_TIMEOUT_MS;
|
||||
timeout = RayConfig::instance().connect_timeout_milliseconds();
|
||||
}
|
||||
|
||||
CHECK(ip_addr);
|
||||
@@ -251,7 +251,7 @@ int write_bytes(int fd, uint8_t *cursor, size_t length) {
|
||||
}
|
||||
|
||||
int write_message(int fd, int64_t type, int64_t length, uint8_t *bytes) {
|
||||
int64_t version = RAY_PROTOCOL_VERSION;
|
||||
int64_t version = RayConfig::instance().ray_protocol_version();
|
||||
int closed;
|
||||
closed = write_bytes(fd, (uint8_t *) &version, sizeof(version));
|
||||
if (closed) {
|
||||
@@ -302,7 +302,7 @@ void read_message(int fd, int64_t *type, int64_t *length, uint8_t **bytes) {
|
||||
if (closed) {
|
||||
goto disconnected;
|
||||
}
|
||||
CHECK(version == RAY_PROTOCOL_VERSION);
|
||||
CHECK(version == RayConfig::instance().ray_protocol_version());
|
||||
closed = read_bytes(fd, (uint8_t *) type, sizeof(*type));
|
||||
if (closed) {
|
||||
goto disconnected;
|
||||
@@ -359,7 +359,7 @@ int64_t read_vector(int fd, int64_t *type, std::vector<uint8_t> &buffer) {
|
||||
if (closed) {
|
||||
goto disconnected;
|
||||
}
|
||||
CHECK(version == RAY_PROTOCOL_VERSION);
|
||||
CHECK(version == RayConfig::instance().ray_protocol_version());
|
||||
int64_t length;
|
||||
closed = read_bytes(fd, (uint8_t *) type, sizeof(*type));
|
||||
if (closed) {
|
||||
|
||||
+6
-14
@@ -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;
|
||||
|
||||
@@ -74,9 +64,10 @@ int connect_ipc_sock(const char *socket_pathname);
|
||||
* @param socket_pathname The pathname for the socket.
|
||||
* @param num_retries The number of times to retry the connection
|
||||
* before exiting. If -1 is provided, then this defaults to
|
||||
* NUM_CONNECT_ATTEMPTS.
|
||||
* num_connect_attempts.
|
||||
* @param timeout The number of milliseconds to wait in between
|
||||
* retries. If -1 is provided, then this defaults to CONNECT_TIMEOUT_MS.
|
||||
* retries. If -1 is provided, then this defaults to
|
||||
* connect_timeout_milliseconds.
|
||||
* @return A file descriptor for the socket, or -1 if an error occurred.
|
||||
*/
|
||||
int connect_ipc_sock_retry(const char *socket_pathname,
|
||||
@@ -102,9 +93,10 @@ int connect_inet_sock(const char *ip_addr, int port);
|
||||
* @param port The port number to connect to.
|
||||
* @param num_retries The number of times to retry the connection
|
||||
* before exiting. If -1 is provided, then this defaults to
|
||||
* NUM_CONNECT_ATTEMPTS.
|
||||
* num_connect_attempts.
|
||||
* @param timeout The number of milliseconds to wait in between
|
||||
* retries. If -1 is provided, then this defaults to CONNECT_TIMEOUT_MS.
|
||||
* retries. If -1 is provided, then this defaults to
|
||||
* connect_timeout_milliseconds.
|
||||
* @return A file descriptor for the socket, or -1 if an error occurred.
|
||||
*/
|
||||
int connect_inet_sock_retry(const char *ip_addr,
|
||||
|
||||
@@ -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
|
||||
@@ -531,7 +528,7 @@ PyObject *PyTask_make(TaskSpec *task_spec, int64_t task_size) {
|
||||
*/
|
||||
int is_simple_value(PyObject *value, int *num_elements_contained) {
|
||||
*num_elements_contained += 1;
|
||||
if (*num_elements_contained >= NUM_ELEMENTS_LIMIT) {
|
||||
if (*num_elements_contained >= RayConfig::instance().num_elements_limit()) {
|
||||
return 0;
|
||||
}
|
||||
if (PyInt_Check(value) || PyLong_Check(value) || value == Py_False ||
|
||||
@@ -540,21 +537,26 @@ int is_simple_value(PyObject *value, int *num_elements_contained) {
|
||||
}
|
||||
if (PyBytes_CheckExact(value)) {
|
||||
*num_elements_contained += PyBytes_Size(value);
|
||||
return (*num_elements_contained < NUM_ELEMENTS_LIMIT);
|
||||
return (*num_elements_contained <
|
||||
RayConfig::instance().num_elements_limit());
|
||||
}
|
||||
if (PyUnicode_CheckExact(value)) {
|
||||
*num_elements_contained += PyUnicode_GET_SIZE(value);
|
||||
return (*num_elements_contained < NUM_ELEMENTS_LIMIT);
|
||||
return (*num_elements_contained <
|
||||
RayConfig::instance().num_elements_limit());
|
||||
}
|
||||
if (PyList_CheckExact(value) && PyList_Size(value) < SIZE_LIMIT) {
|
||||
if (PyList_CheckExact(value) &&
|
||||
PyList_Size(value) < RayConfig::instance().size_limit()) {
|
||||
for (Py_ssize_t i = 0; i < PyList_Size(value); ++i) {
|
||||
if (!is_simple_value(PyList_GetItem(value, i), num_elements_contained)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return (*num_elements_contained < NUM_ELEMENTS_LIMIT);
|
||||
return (*num_elements_contained <
|
||||
RayConfig::instance().num_elements_limit());
|
||||
}
|
||||
if (PyDict_CheckExact(value) && PyDict_Size(value) < SIZE_LIMIT) {
|
||||
if (PyDict_CheckExact(value) &&
|
||||
PyDict_Size(value) < RayConfig::instance().size_limit()) {
|
||||
PyObject *key, *val;
|
||||
Py_ssize_t pos = 0;
|
||||
while (PyDict_Next(value, &pos, &key, &val)) {
|
||||
@@ -563,15 +565,18 @@ int is_simple_value(PyObject *value, int *num_elements_contained) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return (*num_elements_contained < NUM_ELEMENTS_LIMIT);
|
||||
return (*num_elements_contained <
|
||||
RayConfig::instance().num_elements_limit());
|
||||
}
|
||||
if (PyTuple_CheckExact(value) && PyTuple_Size(value) < SIZE_LIMIT) {
|
||||
if (PyTuple_CheckExact(value) &&
|
||||
PyTuple_Size(value) < RayConfig::instance().size_limit()) {
|
||||
for (Py_ssize_t i = 0; i < PyTuple_Size(value); ++i) {
|
||||
if (!is_simple_value(PyTuple_GetItem(value, i), num_elements_contained)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return (*num_elements_contained < NUM_ELEMENTS_LIMIT);
|
||||
return (*num_elements_contained <
|
||||
RayConfig::instance().num_elements_limit());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
PyObject *PyTask_make(TaskSpec *task_spec, int64_t task_size);
|
||||
|
||||
#endif /* COMMON_EXTENSION_H */
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
#include <Python.h>
|
||||
#include "bytesobject.h"
|
||||
|
||||
#include "state/ray_config.h"
|
||||
#include "config_extension.h"
|
||||
|
||||
PyObject *PyRayConfig_make() {
|
||||
PyRayConfig *result = PyObject_New(PyRayConfig, &PyRayConfigType);
|
||||
result = (PyRayConfig *) PyObject_Init((PyObject *) result, &PyRayConfigType);
|
||||
return (PyObject *) result;
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_ray_protocol_version(PyObject *self) {
|
||||
return PyLong_FromLongLong(RayConfig::instance().ray_protocol_version());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_heartbeat_timeout_milliseconds(PyObject *self) {
|
||||
return PyLong_FromLongLong(
|
||||
RayConfig::instance().heartbeat_timeout_milliseconds());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_num_heartbeats_timeout(PyObject *self) {
|
||||
return PyLong_FromLongLong(RayConfig::instance().num_heartbeats_timeout());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_get_timeout_milliseconds(PyObject *self) {
|
||||
return PyLong_FromLongLong(RayConfig::instance().get_timeout_milliseconds());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_worker_get_request_size(PyObject *self) {
|
||||
return PyLong_FromLongLong(RayConfig::instance().worker_get_request_size());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_worker_fetch_request_size(PyObject *self) {
|
||||
return PyLong_FromLongLong(RayConfig::instance().worker_fetch_request_size());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_num_connect_attempts(PyObject *self) {
|
||||
return PyLong_FromLongLong(RayConfig::instance().num_connect_attempts());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_connect_timeout_milliseconds(PyObject *self) {
|
||||
return PyLong_FromLongLong(
|
||||
RayConfig::instance().connect_timeout_milliseconds());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_local_scheduler_fetch_timeout_milliseconds(
|
||||
PyObject *self) {
|
||||
return PyLong_FromLongLong(
|
||||
RayConfig::instance().local_scheduler_fetch_timeout_milliseconds());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_local_scheduler_reconstruction_timeout_milliseconds(
|
||||
PyObject *self) {
|
||||
return PyLong_FromLongLong(
|
||||
RayConfig::instance()
|
||||
.local_scheduler_reconstruction_timeout_milliseconds());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_max_num_to_reconstruct(PyObject *self) {
|
||||
return PyLong_FromLongLong(RayConfig::instance().max_num_to_reconstruct());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_local_scheduler_fetch_request_size(PyObject *self) {
|
||||
return PyLong_FromLongLong(
|
||||
RayConfig::instance().local_scheduler_fetch_request_size());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_kill_worker_timeout_milliseconds(PyObject *self) {
|
||||
return PyLong_FromLongLong(
|
||||
RayConfig::instance().kill_worker_timeout_milliseconds());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_default_num_CPUs(PyObject *self) {
|
||||
return PyFloat_FromDouble(RayConfig::instance().default_num_CPUs());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_default_num_GPUs(PyObject *self) {
|
||||
return PyFloat_FromDouble(RayConfig::instance().default_num_GPUs());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_default_num_custom_resource(PyObject *self) {
|
||||
return PyFloat_FromDouble(
|
||||
RayConfig::instance().default_num_custom_resource());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_manager_timeout_milliseconds(PyObject *self) {
|
||||
return PyLong_FromLongLong(
|
||||
RayConfig::instance().manager_timeout_milliseconds());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_buf_size(PyObject *self) {
|
||||
return PyLong_FromLongLong(RayConfig::instance().buf_size());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_max_time_for_handler_milliseconds(PyObject *self) {
|
||||
return PyLong_FromLongLong(
|
||||
RayConfig::instance().max_time_for_handler_milliseconds());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_size_limit(PyObject *self) {
|
||||
return PyLong_FromLongLong(RayConfig::instance().size_limit());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_num_elements_limit(PyObject *self) {
|
||||
return PyLong_FromLongLong(RayConfig::instance().num_elements_limit());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_max_time_for_loop(PyObject *self) {
|
||||
return PyLong_FromLongLong(RayConfig::instance().max_time_for_loop());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_redis_db_connect_retries(PyObject *self) {
|
||||
return PyLong_FromLongLong(RayConfig::instance().redis_db_connect_retries());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_redis_db_connect_wait_milliseconds(PyObject *self) {
|
||||
return PyLong_FromLongLong(
|
||||
RayConfig::instance().redis_db_connect_wait_milliseconds());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_plasma_default_release_delay(PyObject *self) {
|
||||
return PyLong_FromLongLong(
|
||||
RayConfig::instance().plasma_default_release_delay());
|
||||
}
|
||||
|
||||
PyObject *PyRayConfig_L3_cache_size_bytes(PyObject *self) {
|
||||
return PyLong_FromLongLong(RayConfig::instance().L3_cache_size_bytes());
|
||||
}
|
||||
|
||||
static PyMethodDef PyRayConfig_methods[] = {
|
||||
{"ray_protocol_version", (PyCFunction) PyRayConfig_ray_protocol_version,
|
||||
METH_NOARGS, "Return ray_protocol_version"},
|
||||
{"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"},
|
||||
{"worker_get_request_size",
|
||||
(PyCFunction) PyRayConfig_worker_get_request_size, METH_NOARGS,
|
||||
"Return worker_get_request_size"},
|
||||
{"worker_fetch_request_size",
|
||||
(PyCFunction) PyRayConfig_worker_fetch_request_size, METH_NOARGS,
|
||||
"Return worker_fetch_request_size"},
|
||||
{"num_connect_attempts", (PyCFunction) PyRayConfig_num_connect_attempts,
|
||||
METH_NOARGS, "Return num_connect_attempts"},
|
||||
{"connect_timeout_milliseconds",
|
||||
(PyCFunction) PyRayConfig_connect_timeout_milliseconds, METH_NOARGS,
|
||||
"Return connect_timeout_milliseconds"},
|
||||
{"local_scheduler_fetch_timeout_milliseconds",
|
||||
(PyCFunction) PyRayConfig_local_scheduler_fetch_timeout_milliseconds,
|
||||
METH_NOARGS, "Return local_scheduler_fetch_timeout_milliseconds"},
|
||||
{"local_scheduler_reconstruction_timeout_milliseconds",
|
||||
(PyCFunction)
|
||||
PyRayConfig_local_scheduler_reconstruction_timeout_milliseconds,
|
||||
METH_NOARGS, "Return local_scheduler_reconstruction_timeout_milliseconds"},
|
||||
{"max_num_to_reconstruct", (PyCFunction) PyRayConfig_max_num_to_reconstruct,
|
||||
METH_NOARGS, "Return max_num_to_reconstruct"},
|
||||
{"local_scheduler_fetch_request_size",
|
||||
(PyCFunction) PyRayConfig_local_scheduler_fetch_request_size, METH_NOARGS,
|
||||
"Return local_scheduler_fetch_request_size"},
|
||||
{"kill_worker_timeout_milliseconds",
|
||||
(PyCFunction) PyRayConfig_kill_worker_timeout_milliseconds, METH_NOARGS,
|
||||
"Return kill_worker_timeout_milliseconds"},
|
||||
{"default_num_CPUs", (PyCFunction) PyRayConfig_default_num_CPUs,
|
||||
METH_NOARGS, "Return default_num_CPUs"},
|
||||
{"default_num_GPUs", (PyCFunction) PyRayConfig_default_num_GPUs,
|
||||
METH_NOARGS, "Return default_num_GPUs"},
|
||||
{"default_num_custom_resource",
|
||||
(PyCFunction) PyRayConfig_default_num_custom_resource, METH_NOARGS,
|
||||
"Return default_num_custom_resource"},
|
||||
{"manager_timeout_milliseconds",
|
||||
(PyCFunction) PyRayConfig_manager_timeout_milliseconds, METH_NOARGS,
|
||||
"Return manager_timeout_milliseconds"},
|
||||
{"buf_size", (PyCFunction) PyRayConfig_buf_size, METH_NOARGS,
|
||||
"Return buf_size"},
|
||||
{"max_time_for_handler_milliseconds",
|
||||
(PyCFunction) PyRayConfig_max_time_for_handler_milliseconds, METH_NOARGS,
|
||||
"Return max_time_for_handler_milliseconds"},
|
||||
{"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_milliseconds",
|
||||
(PyCFunction) PyRayConfig_redis_db_connect_wait_milliseconds, METH_NOARGS,
|
||||
"Return redis_db_connect_wait_milliseconds"},
|
||||
{"plasma_default_release_delay",
|
||||
(PyCFunction) PyRayConfig_plasma_default_release_delay, METH_NOARGS,
|
||||
"Return plasma_default_release_delay"},
|
||||
{"L3_cache_size_bytes", (PyCFunction) PyRayConfig_L3_cache_size_bytes,
|
||||
METH_NOARGS, "Return L3_cache_size_bytes"},
|
||||
{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 */
|
||||
0, /* 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 */
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
#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
|
||||
|
||||
extern PyTypeObject PyRayConfigType;
|
||||
|
||||
/* Create a PyRayConfig from C++. */
|
||||
PyObject *PyRayConfig_make();
|
||||
|
||||
PyObject *PyRayConfig_ray_protocol_version(PyObject *self);
|
||||
PyObject *PyRayConfig_heartbeat_timeout_milliseconds(PyObject *self);
|
||||
PyObject *PyRayConfig_num_heartbeats_timeout(PyObject *self);
|
||||
PyObject *PyRayConfig_get_timeout_milliseconds(PyObject *self);
|
||||
PyObject *PyRayConfig_worker_get_request_size(PyObject *self);
|
||||
PyObject *PyRayConfig_worker_fetch_request_size(PyObject *self);
|
||||
PyObject *PyRayConfig_num_connect_attempts(PyObject *self);
|
||||
PyObject *PyRayConfig_connect_timeout_milliseconds(PyObject *self);
|
||||
PyObject *PyRayConfig_local_scheduler_fetch_timeout_milliseconds(
|
||||
PyObject *self);
|
||||
PyObject *PyRayConfig_local_scheduler_reconstruction_timeout_milliseconds(
|
||||
PyObject *self);
|
||||
PyObject *PyRayConfig_max_num_to_reconstruct(PyObject *self);
|
||||
PyObject *PyRayConfig_local_scheduler_fetch_request_size(PyObject *self);
|
||||
PyObject *PyRayConfig_kill_worker_timeout_milliseconds(PyObject *self);
|
||||
PyObject *PyRayConfig_default_num_CPUs(PyObject *self);
|
||||
PyObject *PyRayConfig_default_num_GPUs(PyObject *self);
|
||||
PyObject *PyRayConfig_default_num_custom_resource(PyObject *self);
|
||||
PyObject *PyRayConfig_manager_timeout_milliseconds(PyObject *self);
|
||||
PyObject *PyRayConfig_buf_size(PyObject *self);
|
||||
PyObject *PyRayConfig_max_time_for_handler_milliseconds(PyObject *self);
|
||||
PyObject *PyRayConfig_size_limit(PyObject *self);
|
||||
PyObject *PyRayConfig_num_elements_limit(PyObject *self);
|
||||
PyObject *PyRayConfig_max_time_for_loop(PyObject *self);
|
||||
PyObject *PyRayConfig_redis_db_connect_retries(PyObject *self);
|
||||
PyObject *PyRayConfig_redis_db_connect_wait_milliseconds(PyObject *self);
|
||||
PyObject *PyRayConfig_plasma_default_release_delay(PyObject *self);
|
||||
PyObject *PyRayConfig_L3_cache_size_bytes(PyObject *self);
|
||||
|
||||
#endif /* CONFIG_EXTENSION_H */
|
||||
@@ -31,7 +31,8 @@ void db_client_table_subscribe(
|
||||
void plasma_manager_send_heartbeat(DBHandle *db_handle) {
|
||||
RetryInfo heartbeat_retry;
|
||||
heartbeat_retry.num_retries = 0;
|
||||
heartbeat_retry.timeout = HEARTBEAT_TIMEOUT_MILLISECONDS;
|
||||
heartbeat_retry.timeout =
|
||||
RayConfig::instance().heartbeat_timeout_milliseconds();
|
||||
heartbeat_retry.fail_callback = NULL;
|
||||
|
||||
init_table_callback(db_handle, NIL_ID, __func__, NULL,
|
||||
|
||||
@@ -84,7 +84,7 @@ typedef struct {
|
||||
* Start sending heartbeats to the plasma_managers channel. Each
|
||||
* heartbeat contains this database client's ID. Heartbeats can be subscribed
|
||||
* to through the plasma_managers channel. Once called, this "retries" the
|
||||
* heartbeat operation forever, every HEARTBEAT_TIMEOUT_MILLISECONDS
|
||||
* heartbeat operation forever, every heartbeat_timeout_milliseconds
|
||||
* milliseconds.
|
||||
*
|
||||
* @param db_handle Database handle.
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
#ifndef RAY_CONFIG_H
|
||||
#define RAY_CONFIG_H
|
||||
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
||||
class RayConfig {
|
||||
public:
|
||||
static RayConfig &instance() {
|
||||
static RayConfig config;
|
||||
return config;
|
||||
}
|
||||
|
||||
int64_t ray_protocol_version() const { return ray_protocol_version_; }
|
||||
|
||||
int64_t heartbeat_timeout_milliseconds() const {
|
||||
return heartbeat_timeout_milliseconds_;
|
||||
}
|
||||
|
||||
int64_t num_heartbeats_timeout() const { return num_heartbeats_timeout_; }
|
||||
|
||||
int64_t get_timeout_milliseconds() const { return get_timeout_milliseconds_; }
|
||||
|
||||
int64_t worker_get_request_size() const { return worker_get_request_size_; }
|
||||
|
||||
int64_t worker_fetch_request_size() const {
|
||||
return worker_fetch_request_size_;
|
||||
}
|
||||
|
||||
int64_t num_connect_attempts() const { return num_connect_attempts_; }
|
||||
|
||||
int64_t connect_timeout_milliseconds() const {
|
||||
return connect_timeout_milliseconds_;
|
||||
}
|
||||
|
||||
int64_t local_scheduler_fetch_timeout_milliseconds() const {
|
||||
return local_scheduler_fetch_timeout_milliseconds_;
|
||||
}
|
||||
|
||||
int64_t local_scheduler_reconstruction_timeout_milliseconds() const {
|
||||
return local_scheduler_reconstruction_timeout_milliseconds_;
|
||||
}
|
||||
|
||||
int64_t max_num_to_reconstruct() const { return max_num_to_reconstruct_; }
|
||||
|
||||
int64_t local_scheduler_fetch_request_size() const {
|
||||
return local_scheduler_fetch_request_size_;
|
||||
}
|
||||
|
||||
int64_t kill_worker_timeout_milliseconds() const {
|
||||
return kill_worker_timeout_milliseconds_;
|
||||
}
|
||||
|
||||
double default_num_CPUs() const { return default_num_CPUs_; }
|
||||
|
||||
double default_num_GPUs() const { return default_num_GPUs_; }
|
||||
|
||||
double default_num_custom_resource() const {
|
||||
return default_num_custom_resource_;
|
||||
}
|
||||
|
||||
int64_t manager_timeout_milliseconds() const {
|
||||
return manager_timeout_milliseconds_;
|
||||
}
|
||||
|
||||
int64_t buf_size() const { return buf_size_; }
|
||||
|
||||
int64_t max_time_for_handler_milliseconds() const {
|
||||
return max_time_for_handler_milliseconds_;
|
||||
}
|
||||
|
||||
int64_t size_limit() const { return size_limit_; }
|
||||
|
||||
int64_t num_elements_limit() const { return num_elements_limit_; }
|
||||
|
||||
int64_t max_time_for_loop() const { return max_time_for_loop_; }
|
||||
|
||||
int64_t redis_db_connect_retries() const { return redis_db_connect_retries_; }
|
||||
|
||||
int64_t redis_db_connect_wait_milliseconds() const {
|
||||
return redis_db_connect_wait_milliseconds_;
|
||||
};
|
||||
|
||||
int64_t plasma_default_release_delay() const {
|
||||
return plasma_default_release_delay_;
|
||||
}
|
||||
|
||||
int64_t L3_cache_size_bytes() const { return L3_cache_size_bytes_; }
|
||||
|
||||
private:
|
||||
RayConfig()
|
||||
: ray_protocol_version_(0x0000000000000000),
|
||||
heartbeat_timeout_milliseconds_(100),
|
||||
num_heartbeats_timeout_(100),
|
||||
get_timeout_milliseconds_(1000),
|
||||
worker_get_request_size_(10000),
|
||||
worker_fetch_request_size_(10000),
|
||||
num_connect_attempts_(50),
|
||||
connect_timeout_milliseconds_(100),
|
||||
local_scheduler_fetch_timeout_milliseconds_(1000),
|
||||
local_scheduler_reconstruction_timeout_milliseconds_(1000),
|
||||
max_num_to_reconstruct_(10000),
|
||||
local_scheduler_fetch_request_size_(10000),
|
||||
kill_worker_timeout_milliseconds_(100),
|
||||
default_num_CPUs_(INT16_MAX),
|
||||
default_num_GPUs_(0),
|
||||
default_num_custom_resource_(INFINITY),
|
||||
manager_timeout_milliseconds_(1000),
|
||||
buf_size_(4096),
|
||||
max_time_for_handler_milliseconds_(1000),
|
||||
size_limit_(100),
|
||||
num_elements_limit_(1000),
|
||||
max_time_for_loop_(1000),
|
||||
redis_db_connect_retries_(50),
|
||||
redis_db_connect_wait_milliseconds_(100),
|
||||
plasma_default_release_delay_(64),
|
||||
L3_cache_size_bytes_(100000000) {}
|
||||
|
||||
~RayConfig() {}
|
||||
|
||||
/// In theory, this is used to detect Ray version mismatches.
|
||||
int64_t ray_protocol_version_;
|
||||
|
||||
/// The duration between heartbeats. These are sent by the plasma manager and
|
||||
/// local scheduler.
|
||||
int64_t heartbeat_timeout_milliseconds_;
|
||||
/// 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.
|
||||
int64_t num_heartbeats_timeout_;
|
||||
|
||||
/// These are used by the worker to set timeouts and to batch requests when
|
||||
/// getting objects.
|
||||
int64_t get_timeout_milliseconds_;
|
||||
int64_t worker_get_request_size_;
|
||||
int64_t worker_fetch_request_size_;
|
||||
|
||||
/// Number of times we try connecting to a socket.
|
||||
int64_t num_connect_attempts_;
|
||||
int64_t connect_timeout_milliseconds_;
|
||||
|
||||
/// 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.
|
||||
int64_t local_scheduler_fetch_timeout_milliseconds_;
|
||||
/// 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.
|
||||
int64_t local_scheduler_reconstruction_timeout_milliseconds_;
|
||||
/// The maximum number of objects that the local scheduler will issue
|
||||
/// reconstruct calls for in a single pass through the reconstruct object
|
||||
/// timeout handler.
|
||||
int64_t max_num_to_reconstruct_;
|
||||
/// The maximum number of objects to include in a single fetch request in the
|
||||
/// regular local scheduler fetch timeout handler.
|
||||
int64_t local_scheduler_fetch_request_size_;
|
||||
|
||||
/// The duration that we wait after sending a worker SIGTERM before sending
|
||||
/// the worker SIGKILL.
|
||||
int64_t kill_worker_timeout_milliseconds_;
|
||||
|
||||
/// These are used to determine the local scheduler's behavior with respect to
|
||||
/// different types of resources.
|
||||
double default_num_CPUs_;
|
||||
double default_num_GPUs_;
|
||||
double default_num_custom_resource_;
|
||||
|
||||
/// These are used by the plasma manager.
|
||||
int64_t manager_timeout_milliseconds_;
|
||||
int64_t buf_size_;
|
||||
|
||||
/// This is a timeout used to cause failures in the plasma manager and local
|
||||
/// scheduler when certain event loop handlers take too long.
|
||||
int64_t max_time_for_handler_milliseconds_;
|
||||
|
||||
/// This is used by the Python extension when serializing objects as part of
|
||||
/// a task spec.
|
||||
int64_t size_limit_;
|
||||
int64_t num_elements_limit_;
|
||||
|
||||
/// This is used to cause failures when a certain loop in redis.cc which
|
||||
/// synchronously looks up object manager addresses in redis is slow.
|
||||
int64_t max_time_for_loop_;
|
||||
|
||||
/// Allow up to 5 seconds for connecting to Redis.
|
||||
int64_t redis_db_connect_retries_;
|
||||
int64_t redis_db_connect_wait_milliseconds_;
|
||||
|
||||
/// TODO(rkn): These constants are currently unused.
|
||||
int64_t plasma_default_release_delay_;
|
||||
int64_t L3_cache_size_bytes_;
|
||||
};
|
||||
|
||||
#endif // RAY_CONFIG_H
|
||||
+11
-11
@@ -98,7 +98,7 @@ void get_redis_shards(redisContext *context,
|
||||
/* Get the total number of Redis shards in the system. */
|
||||
int num_attempts = 0;
|
||||
redisReply *reply = NULL;
|
||||
while (num_attempts < REDIS_DB_CONNECT_RETRIES) {
|
||||
while (num_attempts < RayConfig::instance().redis_db_connect_retries()) {
|
||||
/* Try to read the number of Redis shards from the primary shard. If the
|
||||
* entry is present, exit. */
|
||||
reply = (redisReply *) redisCommand(context, "GET NumRedisShards");
|
||||
@@ -108,11 +108,11 @@ void get_redis_shards(redisContext *context,
|
||||
|
||||
/* Sleep for a little, and try again if the entry isn't there yet. */
|
||||
freeReplyObject(reply);
|
||||
usleep(REDIS_DB_CONNECT_WAIT_MS * 1000);
|
||||
usleep(RayConfig::instance().redis_db_connect_wait_milliseconds() * 1000);
|
||||
num_attempts++;
|
||||
continue;
|
||||
}
|
||||
CHECKM(num_attempts < REDIS_DB_CONNECT_RETRIES,
|
||||
CHECKM(num_attempts < RayConfig::instance().redis_db_connect_retries(),
|
||||
"No entry found for NumRedisShards");
|
||||
CHECKM(reply->type == REDIS_REPLY_STRING,
|
||||
"Expected string, found Redis type %d for NumRedisShards",
|
||||
@@ -124,7 +124,7 @@ void get_redis_shards(redisContext *context,
|
||||
|
||||
/* Get the addresses of all of the Redis shards. */
|
||||
num_attempts = 0;
|
||||
while (num_attempts < REDIS_DB_CONNECT_RETRIES) {
|
||||
while (num_attempts < RayConfig::instance().redis_db_connect_retries()) {
|
||||
/* Try to read the Redis shard locations from the primary shard. If we find
|
||||
* that all of them are present, exit. */
|
||||
reply = (redisReply *) redisCommand(context, "LRANGE RedisShards 0 -1");
|
||||
@@ -135,11 +135,11 @@ void get_redis_shards(redisContext *context,
|
||||
/* Sleep for a little, and try again if not all Redis shard addresses have
|
||||
* been added yet. */
|
||||
freeReplyObject(reply);
|
||||
usleep(REDIS_DB_CONNECT_WAIT_MS * 1000);
|
||||
usleep(RayConfig::instance().redis_db_connect_wait_milliseconds() * 1000);
|
||||
num_attempts++;
|
||||
continue;
|
||||
}
|
||||
CHECKM(num_attempts < REDIS_DB_CONNECT_RETRIES,
|
||||
CHECKM(num_attempts < RayConfig::instance().redis_db_connect_retries(),
|
||||
"Expected %d Redis shard addresses, found %d", num_redis_shards,
|
||||
(int) reply->elements);
|
||||
|
||||
@@ -173,12 +173,13 @@ void db_connect_shard(const std::string &db_address,
|
||||
int connection_attempts = 0;
|
||||
redisContext *sync_context = redisConnect(db_address.c_str(), db_port);
|
||||
while (sync_context == NULL || sync_context->err) {
|
||||
if (connection_attempts >= REDIS_DB_CONNECT_RETRIES) {
|
||||
if (connection_attempts >=
|
||||
RayConfig::instance().redis_db_connect_retries()) {
|
||||
break;
|
||||
}
|
||||
LOG_WARN("Failed to connect to Redis, retrying.");
|
||||
/* Sleep for a little. */
|
||||
usleep(REDIS_DB_CONNECT_WAIT_MS * 1000);
|
||||
usleep(RayConfig::instance().redis_db_connect_wait_milliseconds() * 1000);
|
||||
sync_context = redisConnect(db_address.c_str(), db_port);
|
||||
connection_attempts += 1;
|
||||
}
|
||||
@@ -643,8 +644,7 @@ 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) {
|
||||
if (end_time - start_time > RayConfig::instance().max_time_for_loop()) {
|
||||
LOG_WARN(
|
||||
"calling redis_get_cached_db_client in a loop in with %zu manager IDs "
|
||||
"took %" PRId64 " milliseconds.",
|
||||
@@ -1515,7 +1515,7 @@ void redis_plasma_manager_send_heartbeat(TableCallbackData *callback_data) {
|
||||
DBHandle *db = callback_data->db_handle;
|
||||
/* NOTE(swang): We purposefully do not provide a callback, leaving the table
|
||||
* operation and timer active. This allows us to send a new heartbeat every
|
||||
* HEARTBEAT_TIMEOUT_MILLISECONDS without having to allocate and deallocate
|
||||
* heartbeat_timeout_milliseconds without having to allocate and deallocate
|
||||
* memory for callback data each time. */
|
||||
int status = redisAsyncCommand(
|
||||
db->context, NULL, (void *) callback_data->timer_id,
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user