Skip to content

Commit 907b0c2

Browse files
Development/batch jsonrpc (#926)
* JsonRpcMuxer: initial version * JsonRpcMuxer: only allow one websocket connection * JsonRpcMuxer: adding a queue wait time timeout. * JsonRpcMuxer: update module name to Plugin_JsonRpcMuxer * JsonRpcMuxer: Use workerpool to invoke messages. * JsonRpcMuxer: enhance error handling for inbound WebSocket messages * JsonRpcMuxer: improve error handling and add batch size configuration * JsonRpcMuxer: add timeout handling for batch processing and enhance logging * JsonRpcMuxer: add max batch size and concurrent batch limit configuration * JsonRpcMuxer: add configuration options for batch processing parameters * JsonRpcMuxer: fix race condition * JsonRpcMuxer: move common validation logic to one method * JsonRpcMuxer: Adding python tests that I used * JsonRpcMuxer: Add batch cleanup + added tests for it. * JsonRpcMuxer: fast burst stress test. * JsonRpcMuxer: split HTTP/WS tests. * JsonRpcMuxer: make direct websocket to plugin optional * JsonRpcMuxer: move some websocket only code within the #ifdef * JsonRpcMuxer: refactor to support both parallel and sequential processing * JsonRpcMuxer: Refactor Batch/Job design * JsonRpcMuxer: Use a job only as a minion to to work * JsonRpcMuxer: Limit logging * JsonRpcMuxer: Add missing initialization * JsonRpcMuxer: fix string consistency * JsonRpcMuxer: Refactor Batch public interface * JsonRpcMuxer: Update tests * JsonRpcMuxer: Add readme * JsonRpcMuxer: Remove WebSocket connection support * JsonRpcMuxer: Update default max wait time for batch completion to Core::infinite * JsonRpcMuxer: Optimize batch processing by removing response lock and introducing finishing state * JsonRpcMuxer: Added explicit memory ordering to allow better CPU optimizations * JsonRpcMuxer: Replace std::map with std::unordered_map to improve performance * JsonRpcMuxer: Implement lock-free batch release * JsonRpcMuxer: Fixed race condition in batch slot claiming * Update Readme.md * JsonRpcMuxer: Add lost Lock * JsonRpcMuxer: Remove atomics, just use good ols fashion locks * JsonRpcMuxer: Update error codes for batch processing * JsonRpcMuxer: Enhance stress tests with timing metrics and error handling * JsonRpcMuxer: Refactor batch processing. * JsonRpcMuxer: Increase max batch size and concurrent batches in test configuration * JsonRpcMuxer: Fix Sequential batch handling * JsonRpcMuxer: Update README * JsonRpcMuxer: Fix typo in test method name and enhance error handling for invalid requests --------- Co-authored-by: Pierre Wielders <[email protected]>
1 parent 6b027f8 commit 907b0c2

File tree

12 files changed

+3213
-0
lines changed

12 files changed

+3213
-0
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ option(PLUGIN_DICTIONARY "Include Dictionary plugin" OFF)
3737
option(PLUGIN_DOGGO "Include watchdog plugin" OFF)
3838
option(PLUGIN_IOCONNECTOR "Include IOConnector plugin" OFF)
3939
option(PLUGIN_INPUTSWITCH "Include InputSwitch plugin" OFF)
40+
option(PLUGIN_JSONRPCMUXER "Include JsonRpcMuxer plugin capable to execute batched jsonRPC messages" OFF)
4041
option(PLUGIN_FIRMWARECONTROL "Include FirmwareControl Plugin" OFF)
4142
option(PLUGIN_PROCESSMONITOR "Include Process Monitor plugin" OFF)
4243
option(PLUGIN_LANGUAGEADMINISTRATOR "Include LanguageAdministrator plugin" OFF)
@@ -158,6 +159,10 @@ if(PLUGIN_INPUTSWITCH)
158159
add_subdirectory(InputSwitch)
159160
endif()
160161

162+
if(PLUGIN_JSONRPCMUXER)
163+
add_subdirectory(JsonRpcMuxer)
164+
endif()
165+
161166
if(PLUGIN_SICONTROL)
162167
add_subdirectory (SIControl)
163168
endif(PLUGIN_SICONTROL)

JsonRpcMuxer/CMakeLists.txt

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# If not stated otherwise in this file or this component's LICENSE file the
2+
# following copyright and licenses apply:
3+
#
4+
# Copyright 2020 Metrological
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
project(JsonRpcMuxer)
19+
20+
cmake_minimum_required(VERSION 3.15)
21+
22+
find_package(Thunder)
23+
24+
project_version(1.0.0)
25+
26+
set(MODULE_NAME ${NAMESPACE}${PROJECT_NAME})
27+
28+
message("Setup ${MODULE_NAME} v${PROJECT_VERSION}")
29+
30+
set(PLUGIN_JSONRPCMUXER_STARTMODE "Activated" CACHE STRING "Automatically start JsonRpcMuxer plugin")
31+
set(PLUGIN_JSONRPCMUXER_MAX_CONCURRENT_JOBS 0 CACHE STRING "Maximum number of concurrent WorkerPool jobs")
32+
set(PLUGIN_JSONRPCMUXER_MAX_BATCH_SIZE 0 CACHE STRING "Maximum requests per batch")
33+
34+
if(BUILD_REFERENCE)
35+
add_definitions(-DBUILD_REFERENCE=${BUILD_REFERENCE})
36+
endif()
37+
38+
find_package(${NAMESPACE}Plugins REQUIRED)
39+
find_package(CompileSettingsDebug CONFIG REQUIRED)
40+
41+
add_library(${MODULE_NAME} SHARED
42+
JsonRpcMuxer.cpp
43+
Module.cpp)
44+
45+
target_compile_definitions(${MODULE_NAME} PRIVATE
46+
PLUGIN_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
47+
PLUGIN_VERSION_MINOR=${PROJECT_VERSION_MINOR}
48+
PLUGIN_VERSION_PATCH=${PROJECT_VERSION_PATCH}
49+
)
50+
51+
set_target_properties(${MODULE_NAME} PROPERTIES
52+
CXX_STANDARD 11
53+
CXX_STANDARD_REQUIRED YES)
54+
55+
target_link_libraries(${MODULE_NAME}
56+
PRIVATE
57+
CompileSettingsDebug::CompileSettingsDebug
58+
${NAMESPACE}Plugins::${NAMESPACE}Plugins)
59+
60+
install(TARGETS ${MODULE_NAME}
61+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${STORAGE_DIRECTORY}/plugins COMPONENT ${NAMESPACE}_Runtime)
62+
63+
write_config()

JsonRpcMuxer/JsonRpcMuxer.conf.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
startmode = "@PLUGIN_JSONRPCMUXER_STARTMODE@"
2+
3+
configuration = JSON()
4+
5+
if @PLUGIN_JSONRPCMUXER_MAX_CONCURRENT_JOBS@:
6+
configuration.add("maxconcurrentjobs", "@PLUGIN_JSONRPCMUXER_MAX_CONCURRENT_JOBS@")
7+
8+
if @PLUGIN_JSONRPCMUXER_MAX_BATCH_SIZE@:
9+
configuration.add("maxbatchsize", "@PLUGIN_JSONRPCMUXER_MAX_BATCH_SIZE@")

0 commit comments

Comments
 (0)