From 75c421520e4c9d080a8e9d695612b0853bab332b Mon Sep 17 00:00:00 2001 From: Jesse Ikawa Date: Sun, 14 Feb 2021 12:49:57 -0800 Subject: [PATCH 1/9] Fix HTTP for kernel < 4.16 Signed-off-by: Jesse Ikawa --- tools/rosgraph/src/rosgraph/xmlrpc.py | 30 ++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/rosgraph/src/rosgraph/xmlrpc.py b/tools/rosgraph/src/rosgraph/xmlrpc.py index db8c2d4410..6a8b4772ed 100644 --- a/tools/rosgraph/src/rosgraph/xmlrpc.py +++ b/tools/rosgraph/src/rosgraph/xmlrpc.py @@ -76,9 +76,32 @@ def isstring(s): except NameError: return isinstance(s, str) -class SilenceableXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): - protocol_version = 'HTTP/1.1' +def check_kernel(major, minor): + """Small helper version to check that the current platform kernel is a + newer or the same as the input + """ + release = platform.release().split('.') + + platform_major = int(release[0]) + platform_minor = int(release[1]) + + if platform_major > major: + return True + elif platform_major < major: + return False + + if platform_minor > minor: + return True + elif platform_minor < minor: + return False + + return True + + +class SilenceableXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): + if check_kernel(4,16): + protocol_version = 'HTTP/1.1' def log_message(self, format, *args): if 0: @@ -90,7 +113,8 @@ class ThreadingXMLRPCServer(socketserver.ThreadingMixIn, SimpleXMLRPCServer): requests via threading. Also makes logging toggleable. """ - daemon_threads = True + if check_kernel(4,16): + daemon_threads = True def __init__(self, addr, log_requests=1): """ From ec987afaa619f8f71dadd9e91705ace9f70a4450 Mon Sep 17 00:00:00 2001 From: Jesse Ikawa Date: Sun, 14 Feb 2021 17:00:40 -0800 Subject: [PATCH 2/9] Check Linux, add comment Signed-off-by: Jesse Ikawa --- tools/rosgraph/src/rosgraph/xmlrpc.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/rosgraph/src/rosgraph/xmlrpc.py b/tools/rosgraph/src/rosgraph/xmlrpc.py index 6a8b4772ed..54c7662e8c 100644 --- a/tools/rosgraph/src/rosgraph/xmlrpc.py +++ b/tools/rosgraph/src/rosgraph/xmlrpc.py @@ -77,10 +77,13 @@ def isstring(s): return isinstance(s, str) -def check_kernel(major, minor): +def check_linux_kernel(major, minor): """Small helper version to check that the current platform kernel is a newer or the same as the input """ + if platform.system()!='Linux': + return True + release = platform.release().split('.') platform_major = int(release[0]) @@ -100,7 +103,8 @@ def check_kernel(major, minor): class SilenceableXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): - if check_kernel(4,16): + # Linux kernels 4.15 and older encounter performance issues with HTTP/1.1 + if check_linux_kernel(4,16): protocol_version = 'HTTP/1.1' def log_message(self, format, *args): @@ -113,7 +117,7 @@ class ThreadingXMLRPCServer(socketserver.ThreadingMixIn, SimpleXMLRPCServer): requests via threading. Also makes logging toggleable. """ - if check_kernel(4,16): + if check_linux_kernel(4,16): daemon_threads = True def __init__(self, addr, log_requests=1): From a95cfa2e84db90d4ce7395bf0ec883f21d72ffc0 Mon Sep 17 00:00:00 2001 From: Jesse Ikawa Date: Sun, 14 Feb 2021 17:33:22 -0800 Subject: [PATCH 3/9] update logic, add platform Signed-off-by: Jesse Ikawa --- tools/rosgraph/src/rosgraph/xmlrpc.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tools/rosgraph/src/rosgraph/xmlrpc.py b/tools/rosgraph/src/rosgraph/xmlrpc.py index 54c7662e8c..54e795d007 100644 --- a/tools/rosgraph/src/rosgraph/xmlrpc.py +++ b/tools/rosgraph/src/rosgraph/xmlrpc.py @@ -44,6 +44,7 @@ import errno import logging +import platform import select import socket @@ -78,12 +79,9 @@ def isstring(s): def check_linux_kernel(major, minor): - """Small helper version to check that the current platform kernel is a - newer or the same as the input + """Small helper version to check that the current Linux kernel is a + newer or the same as the input. """ - if platform.system()!='Linux': - return True - release = platform.release().split('.') platform_major = int(release[0]) @@ -104,7 +102,7 @@ def check_linux_kernel(major, minor): class SilenceableXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): # Linux kernels 4.15 and older encounter performance issues with HTTP/1.1 - if check_linux_kernel(4,16): + if platform.system() == 'Linux' and check_linux_kernel(4,16): protocol_version = 'HTTP/1.1' def log_message(self, format, *args): @@ -117,7 +115,7 @@ class ThreadingXMLRPCServer(socketserver.ThreadingMixIn, SimpleXMLRPCServer): requests via threading. Also makes logging toggleable. """ - if check_linux_kernel(4,16): + if platform.system() == 'Linux' and check_linux_kernel(4,16): daemon_threads = True def __init__(self, addr, log_requests=1): From 96b1c3c39d7574f6eec999f50cb400fe6f54d635 Mon Sep 17 00:00:00 2001 From: Jesse Ikawa Date: Mon, 15 Feb 2021 14:25:08 -0800 Subject: [PATCH 4/9] internal function name, invert logic Signed-off-by: Jesse Ikawa --- tools/rosgraph/src/rosgraph/xmlrpc.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tools/rosgraph/src/rosgraph/xmlrpc.py b/tools/rosgraph/src/rosgraph/xmlrpc.py index 54e795d007..c612809c1f 100644 --- a/tools/rosgraph/src/rosgraph/xmlrpc.py +++ b/tools/rosgraph/src/rosgraph/xmlrpc.py @@ -78,31 +78,34 @@ def isstring(s): return isinstance(s, str) -def check_linux_kernel(major, minor): - """Small helper version to check that the current Linux kernel is a - newer or the same as the input. +def _check_linux_kernel(major, minor): + """Small helper version to check if the current Linux kernel is older than + the input version and return true. If not Linux return false. """ + if platform.system() != 'Linux': + return False + release = platform.release().split('.') platform_major = int(release[0]) platform_minor = int(release[1]) - if platform_major > major: + if platform_major < major: return True - elif platform_major < major: + elif platform_major > major: return False - if platform_minor > minor: + if platform_minor < minor: return True - elif platform_minor < minor: + elif platform_minor > minor: return False - return True + return False class SilenceableXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): # Linux kernels 4.15 and older encounter performance issues with HTTP/1.1 - if platform.system() == 'Linux' and check_linux_kernel(4,16): + if not _check_linux_kernel(4,15): protocol_version = 'HTTP/1.1' def log_message(self, format, *args): @@ -115,7 +118,7 @@ class ThreadingXMLRPCServer(socketserver.ThreadingMixIn, SimpleXMLRPCServer): requests via threading. Also makes logging toggleable. """ - if platform.system() == 'Linux' and check_linux_kernel(4,16): + if not _check_linux_kernel(4,15): daemon_threads = True def __init__(self, addr, log_requests=1): From 10937afe1ef4e611dc7fbce4f88bf94aa3c13c55 Mon Sep 17 00:00:00 2001 From: Jesse Ikawa Date: Mon, 15 Feb 2021 14:52:15 -0800 Subject: [PATCH 5/9] Target function specifically to HTTP1.1 error Signed-off-by: Jesse Ikawa --- tools/rosgraph/src/rosgraph/xmlrpc.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tools/rosgraph/src/rosgraph/xmlrpc.py b/tools/rosgraph/src/rosgraph/xmlrpc.py index c612809c1f..d57e4bc7a7 100644 --- a/tools/rosgraph/src/rosgraph/xmlrpc.py +++ b/tools/rosgraph/src/rosgraph/xmlrpc.py @@ -78,34 +78,35 @@ def isstring(s): return isinstance(s, str) -def _check_linux_kernel(major, minor): - """Small helper version to check if the current Linux kernel is older than - the input version and return true. If not Linux return false. +def _support_http_1_1(major, minor): + """Linux kernels 4.15 and older encounter performance issues with HTTP/1.1 + This function returns true if the Linux kernel version is greater than the + input or if the platform is not Linux. """ + # HTTP/1.1 performance issue only detected on Linux if platform.system() != 'Linux': - return False + return True release = platform.release().split('.') platform_major = int(release[0]) platform_minor = int(release[1]) - if platform_major < major: + if platform_major > major: return True - elif platform_major > major: + elif platform_major < major: return False - if platform_minor < minor: + if platform_minor > minor: return True - elif platform_minor > minor: + elif platform_minor < minor: return False return False class SilenceableXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): - # Linux kernels 4.15 and older encounter performance issues with HTTP/1.1 - if not _check_linux_kernel(4,15): + if _support_http_1_1(4,15): protocol_version = 'HTTP/1.1' def log_message(self, format, *args): @@ -118,7 +119,7 @@ class ThreadingXMLRPCServer(socketserver.ThreadingMixIn, SimpleXMLRPCServer): requests via threading. Also makes logging toggleable. """ - if not _check_linux_kernel(4,15): + if _support_http_1_1(4,15): daemon_threads = True def __init__(self, addr, log_requests=1): From 108cc8c1c18c05a283ea90264d924026b3a3abb6 Mon Sep 17 00:00:00 2001 From: Jesse Ikawa Date: Mon, 15 Feb 2021 16:22:45 -0800 Subject: [PATCH 6/9] Remove function parameters Signed-off-by: Jesse Ikawa --- tools/rosgraph/src/rosgraph/xmlrpc.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/rosgraph/src/rosgraph/xmlrpc.py b/tools/rosgraph/src/rosgraph/xmlrpc.py index d57e4bc7a7..54e9b5f7e8 100644 --- a/tools/rosgraph/src/rosgraph/xmlrpc.py +++ b/tools/rosgraph/src/rosgraph/xmlrpc.py @@ -78,7 +78,7 @@ def isstring(s): return isinstance(s, str) -def _support_http_1_1(major, minor): +def _support_http_1_1(): """Linux kernels 4.15 and older encounter performance issues with HTTP/1.1 This function returns true if the Linux kernel version is greater than the input or if the platform is not Linux. @@ -89,6 +89,9 @@ def _support_http_1_1(major, minor): release = platform.release().split('.') + major = 4 + minor = 15 + platform_major = int(release[0]) platform_minor = int(release[1]) @@ -106,7 +109,7 @@ def _support_http_1_1(major, minor): class SilenceableXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): - if _support_http_1_1(4,15): + if _support_http_1_1: protocol_version = 'HTTP/1.1' def log_message(self, format, *args): @@ -119,7 +122,7 @@ class ThreadingXMLRPCServer(socketserver.ThreadingMixIn, SimpleXMLRPCServer): requests via threading. Also makes logging toggleable. """ - if _support_http_1_1(4,15): + if _support_http_1_1: daemon_threads = True def __init__(self, addr, log_requests=1): From 510de0034511b44af660e110d17d7ec922c2b088 Mon Sep 17 00:00:00 2001 From: Jesse Ikawa Date: Mon, 15 Feb 2021 16:47:32 -0800 Subject: [PATCH 7/9] update logic, fix function call Signed-off-by: Jesse Ikawa --- tools/rosgraph/src/rosgraph/xmlrpc.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/tools/rosgraph/src/rosgraph/xmlrpc.py b/tools/rosgraph/src/rosgraph/xmlrpc.py index 54e9b5f7e8..fe20b65cc7 100644 --- a/tools/rosgraph/src/rosgraph/xmlrpc.py +++ b/tools/rosgraph/src/rosgraph/xmlrpc.py @@ -95,21 +95,15 @@ def _support_http_1_1(): platform_major = int(release[0]) platform_minor = int(release[1]) - if platform_major > major: - return True - elif platform_major < major: + if platform_major < major: return False - - if platform_minor > minor: - return True - elif platform_minor < minor: + if platform_major == major and platform_minor <= minor: return False - - return False + return True class SilenceableXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): - if _support_http_1_1: + if _support_http_1_1(): protocol_version = 'HTTP/1.1' def log_message(self, format, *args): @@ -122,7 +116,7 @@ class ThreadingXMLRPCServer(socketserver.ThreadingMixIn, SimpleXMLRPCServer): requests via threading. Also makes logging toggleable. """ - if _support_http_1_1: + if _support_http_1_1(): daemon_threads = True def __init__(self, addr, log_requests=1): From 6ca0bc075f1d385c9e7c92d7ba5034faf1bb5bae Mon Sep 17 00:00:00 2001 From: Jesse Ikawa Date: Tue, 16 Feb 2021 10:27:00 -0800 Subject: [PATCH 8/9] Update comment, names Signed-off-by: Jesse Ikawa --- tools/rosgraph/src/rosgraph/xmlrpc.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tools/rosgraph/src/rosgraph/xmlrpc.py b/tools/rosgraph/src/rosgraph/xmlrpc.py index fe20b65cc7..2ec87c7cbf 100644 --- a/tools/rosgraph/src/rosgraph/xmlrpc.py +++ b/tools/rosgraph/src/rosgraph/xmlrpc.py @@ -79,25 +79,23 @@ def isstring(s): def _support_http_1_1(): - """Linux kernels 4.15 and older encounter performance issues with HTTP/1.1 - This function returns true if the Linux kernel version is greater than the - input or if the platform is not Linux. """ - # HTTP/1.1 performance issue only detected on Linux + Determine whether HTTP 1.1 should be enabled for XMLRPC communications. + + This will be true on non-Linux systems, and on Linux kernels at least as + new as 4.16. Linux kernels 4.15 and older cause significance performance + degradation in the roscore when using HTTP 1.1 + """ if platform.system() != 'Linux': return True - + minimum_supported_major, minimum_supported_minor = (4, 16) release = platform.release().split('.') - - major = 4 - minor = 15 - platform_major = int(release[0]) platform_minor = int(release[1]) - - if platform_major < major: + if platform_major < minimum_supported_major: return False - if platform_major == major and platform_minor <= minor: + if (platform_major == minimum_supported_major and + platform_minor < minimum_supported_minor): return False return True From 80247735d6344fb8a3c4476efe198d272ede56dc Mon Sep 17 00:00:00 2001 From: Jesse Ikawa <64169356+jikawa-az@users.noreply.github.com> Date: Tue, 16 Feb 2021 15:54:59 -0800 Subject: [PATCH 9/9] fix typo Co-authored-by: Emerson Knapp <537409+emersonknapp@users.noreply.github.com> --- tools/rosgraph/src/rosgraph/xmlrpc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/rosgraph/src/rosgraph/xmlrpc.py b/tools/rosgraph/src/rosgraph/xmlrpc.py index 2ec87c7cbf..7b87520c0e 100644 --- a/tools/rosgraph/src/rosgraph/xmlrpc.py +++ b/tools/rosgraph/src/rosgraph/xmlrpc.py @@ -83,7 +83,7 @@ def _support_http_1_1(): Determine whether HTTP 1.1 should be enabled for XMLRPC communications. This will be true on non-Linux systems, and on Linux kernels at least as - new as 4.16. Linux kernels 4.15 and older cause significance performance + new as 4.16. Linux kernels 4.15 and older cause significant performance degradation in the roscore when using HTTP 1.1 """ if platform.system() != 'Linux':