Repository: ray-project/ray

Issue:
Using gflags or similar for argument parsing
Did a quick search through the issues list and didn't see anything related. Since the raylet code is fast-moving, it may be helpful to rely on an argument parsing library for ```raylet``` and ```raylet_monitor``` rather than magic numbers for argument positions.

Should be a small change, but raising as an issue rather than PR first because there may be some reason that the team doesn't want to do this.


Discussion:
You're completely right.

We do it *slightly* better in legacy Ray 

https://github.com/ray-project/ray/blob/6bf48f47bcf91610db42b350e8149c85e01afb0d/src/local_scheduler/local_scheduler.cc#L1522-L1557

but if there's a more canonical C++ way of parsing arguments, that would be preferable.
Yeah, getopt is the POSIX way. There are innumerable c++ libraries doing this now, but [gflags](https://gflags.github.io/gflags/) seems to be reasonably popular. Some people don’t like the dependence on macros, though.

Boost also has a library and we already have that dependency. 
+1 to gflags.

On Thu, Jun 21, 2018 at 3:54 AM Daniel Suo <notifications@github.com> wrote:

> Yeah, getopt is the POSIX way. There are innumerable c++ libraries doing
> this now, but gflags <https://gflags.github.io/gflags/> seems to be
> reasonably popular. Some people don’t like the dependence on macros, though.
>
> Boost also has a library and we already have that dependency.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/ray-project/ray/issues/2280#issuecomment-399060723>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAkLHrUaGghVSSDrn5RRgAs_H0CaBijOks5t-3tpgaJpZM4Uvp_m>
> .
>

We are trying to minimize the boost dependency (just asio in the Ray codebase). gflags might be a good option.

Resolving patch:
diff --git a/python/ray/services.py b/python/ray/services.py
--- a/python/ray/services.py
+++ b/python/ray/services.py
@@ -1177,21 +1177,21 @@ def start_raylet(redis_address,
 
     command = [
         RAYLET_EXECUTABLE,
-        raylet_name,
-        plasma_store_name,
-        str(object_manager_port),
-        str(node_manager_port),
-        node_ip_address,
-        gcs_ip_address,
-        gcs_port,
-        str(num_initial_workers),
-        str(maximum_startup_concurrency),
-        resource_argument,
-        config_str,
-        start_worker_command,
-        java_worker_command,
-        redis_password or "",
-        temp_dir,
+        "--raylet_socket_name={}".format(raylet_name),
+        "--store_socket_name={}".format(plasma_store_name),
+        "--object_manager_port={}".format(object_manager_port),
+        "--node_manager_port={}".format(node_manager_port),
+        "--node_ip_address={}".format(node_ip_address),
+        "--redis_address={}".format(gcs_ip_address),
+        "--redis_port={}".format(gcs_port),
+        "--num_initial_workers={}".format(num_initial_workers),
+        "--maximum_startup_concurrency={}".format(maximum_startup_concurrency),
+        "--static_resource_list={}".format(resource_argument),
+        "--config_list={}".format(config_str),
+        "--python_worker_command={}".format(start_worker_command),
+        "--java_worker_command={}".format(java_worker_command),
+        "--redis_password={}".format(redis_password or ""),
+        "--temp_dir={}".format(temp_dir),
     ]
     process_info = start_ray_process(
         command,
@@ -1555,7 +1555,12 @@ def start_raylet_monitor(redis_address,
     redis_password = redis_password or ""
     config = config or {}
     config_str = ",".join(["{},{}".format(*kv) for kv in config.items()])
-    command = [RAYLET_MONITOR_EXECUTABLE, gcs_ip_address, gcs_port, config_str]
+    command = [
+        RAYLET_MONITOR_EXECUTABLE,
+        "--redis_address={}".format(gcs_ip_address),
+        "--redis_port={}".format(gcs_port),
+        "--config_list={}".format(config_str),
+    ]
     if redis_password:
         command += [redis_password]
     process_info = start_ray_process(


Test patch: