mirror of
https://github.com/wassname/ray.git
synced 2026-07-10 12:58:04 +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
@@ -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 */
|
||||
Reference in New Issue
Block a user