├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── grpc ├── README.md ├── build.gradle └── src │ └── main │ ├── java │ └── io │ │ └── netifi │ │ └── thunderdome │ │ └── grpc │ │ └── nonblocking │ │ ├── rs │ │ ├── GrpcRequestReplyClient.java │ │ ├── GrpcServer.java │ │ └── MultithreadedGrpcRequestReplyClient.java │ │ └── stock │ │ ├── GrpcRequestReplyClient.java │ │ └── GrpcServer.java │ ├── proto │ └── io │ │ └── netifi │ │ └── thunderdome │ │ └── grpc │ │ └── nonblocking │ │ └── stock │ │ └── simpleservice.proto │ └── resources │ └── log4j2.xml ├── ratpack ├── README.md ├── build.gradle └── src │ └── main │ ├── java │ └── io │ │ └── netifi │ │ └── thunderdome │ │ └── ratpack │ │ ├── RatpackRequestReply.java │ │ ├── RatpackTestServer.java │ │ ├── SimpleRequest.java │ │ └── SimpleResponse.java │ └── resources │ └── log4j2.xml ├── rsocket-rpc ├── README.md ├── build.gradle └── src │ └── main │ ├── java │ └── io │ │ └── netifi │ │ └── thunderdome │ │ └── rsocketrpc │ │ ├── MultithreadedRSocketRpcRequestReplyClient.java │ │ ├── RSocketRpcRequestReplyClient.java │ │ └── RSocketRpcServer.java │ ├── proto │ └── io │ │ └── netifi │ │ └── thunderdome │ │ └── rsocketrpc │ │ └── simpleservice.proto │ └── resources │ └── log4j2.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/java,linux,macos,gradle,android,intellij,androidstudio 3 | 4 | ### Android ### 5 | # Built application files 6 | *.apk 7 | *.ap_ 8 | 9 | # Files for the ART/Dalvik VM 10 | *.dex 11 | 12 | # Java class files 13 | *.class 14 | 15 | # Generated files 16 | bin/ 17 | gen/ 18 | out/ 19 | 20 | # Gradle files 21 | .gradle/ 22 | build/ 23 | 24 | # Local configuration file (sdk path, etc) 25 | local.properties 26 | 27 | # Proguard folder generated by Eclipse 28 | proguard/ 29 | 30 | # Log Files 31 | *.log 32 | 33 | # Android Studio Navigation editor temp files 34 | .navigation/ 35 | 36 | # Android Studio captures folder 37 | captures/ 38 | 39 | # Intellij 40 | *.iml 41 | .idea/workspace.xml 42 | .idea/tasks.xml 43 | .idea/gradle.xml 44 | .idea/dictionaries 45 | .idea/libraries 46 | 47 | # External native build folder generated in Android Studio 2.2 and later 48 | .externalNativeBuild 49 | 50 | # Freeline 51 | freeline.py 52 | freeline/ 53 | freeline_project_description.json 54 | 55 | ### Android Patch ### 56 | gen-external-apklibs 57 | 58 | ### AndroidStudio ### 59 | # Covers files to be ignored for android development using Android Studio. 60 | 61 | # Built application files 62 | 63 | # Files for the ART/Dalvik VM 64 | 65 | # Java class files 66 | 67 | # Generated files 68 | 69 | # Gradle files 70 | .gradle 71 | 72 | # Signing files 73 | .signing/ 74 | 75 | # Local configuration file (sdk path, etc) 76 | 77 | # Proguard folder generated by Eclipse 78 | 79 | # Log Files 80 | 81 | # Android Studio 82 | /*/build/ 83 | /*/local.properties 84 | /*/out 85 | /*/*/build 86 | /*/*/production 87 | *.ipr 88 | *~ 89 | *.swp 90 | 91 | # Android Patch 92 | 93 | # External native build folder generated in Android Studio 2.2 and later 94 | 95 | # NDK 96 | obj/ 97 | 98 | # IntelliJ IDEA 99 | *.iws 100 | /out/ 101 | 102 | # User-specific configurations 103 | .idea/libraries/ 104 | .idea/.name 105 | .idea/compiler.xml 106 | .idea/copyright/profiles_settings.xml 107 | .idea/encodings.xml 108 | .idea/misc.xml 109 | .idea/modules.xml 110 | .idea/scopes/scope_settings.xml 111 | .idea/vcs.xml 112 | .idea/jsLibraryMappings.xml 113 | .idea/datasources.xml 114 | .idea/dataSources.ids 115 | .idea/sqlDataSources.xml 116 | .idea/dynamic.xml 117 | .idea/uiDesigner.xml 118 | 119 | # OS-specific files 120 | .DS_Store 121 | .DS_Store? 122 | ._* 123 | .Spotlight-V100 124 | .Trashes 125 | ehthumbs.db 126 | Thumbs.db 127 | 128 | # Legacy Eclipse project files 129 | .classpath 130 | .project 131 | 132 | # Mobile Tools for Java (J2ME) 133 | .mtj.tmp/ 134 | 135 | # Package Files # 136 | *.war 137 | *.ear 138 | 139 | # virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml) 140 | hs_err_pid* 141 | 142 | ## Plugin-specific files: 143 | 144 | # mpeltonen/sbt-idea plugin 145 | .idea_modules/ 146 | 147 | # JIRA plugin 148 | atlassian-ide-plugin.xml 149 | 150 | # Mongo Explorer plugin 151 | .idea/mongoSettings.xml 152 | 153 | # Crashlytics plugin (for Android Studio and IntelliJ) 154 | com_crashlytics_export_strings.xml 155 | crashlytics.properties 156 | crashlytics-build.properties 157 | fabric.properties 158 | 159 | ### AndroidStudio Patch ### 160 | 161 | !/gradle/wrapper/gradle-wrapper.jar 162 | 163 | ### Intellij ### 164 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 165 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 166 | 167 | # User-specific stuff: 168 | .idea/** 169 | 170 | # CMake 171 | cmake-build-debug/ 172 | 173 | ### Java ### 174 | # Compiled class file 175 | 176 | # Log file 177 | 178 | # BlueJ files 179 | *.ctxt 180 | 181 | # Mobile Tools for Java (J2ME) 182 | 183 | # Package Files # 184 | *.jar 185 | *.zip 186 | *.tar.gz 187 | *.rar 188 | 189 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 190 | 191 | ### Linux ### 192 | 193 | # temporary files which can be created if a process still has a handle open of a deleted file 194 | .fuse_hidden* 195 | 196 | # KDE directory preferences 197 | .directory 198 | 199 | # Linux trash folder which might appear on any partition or disk 200 | .Trash-* 201 | 202 | # .nfs files are created when an open file is removed but is still being accessed 203 | .nfs* 204 | 205 | ### macOS ### 206 | *.DS_Store 207 | .AppleDouble 208 | .LSOverride 209 | 210 | # Icon must end with two \r 211 | Icon 212 | 213 | # Thumbnails 214 | 215 | # Files that might appear in the root of a volume 216 | .DocumentRevisions-V100 217 | .fseventsd 218 | .TemporaryItems 219 | .VolumeIcon.icns 220 | .com.apple.timemachine.donotpresent 221 | 222 | # Directories potentially created on remote AFP share 223 | .AppleDB 224 | .AppleDesktop 225 | Network Trash Folder 226 | Temporary Items 227 | .apdisk 228 | 229 | ### Gradle ### 230 | /build/ 231 | 232 | # Ignore Gradle GUI config 233 | gradle-app.setting 234 | 235 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 236 | !gradle-wrapper.jar 237 | 238 | # Cache of project 239 | .gradletasknamecache 240 | 241 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 242 | # gradle/wrapper/gradle-wrapper.properties 243 | 244 | # End of https://www.gitignore.io/api/java,linux,macos,gradle,android,intellij,androidstudio 245 | 246 | generated/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rpc-thunderdome 2 | A comparison between [RSocket RPC](https://github.com/rsocket/rsocket-rpc-java) and other commonly used RPC frameworks. 3 | 4 | ## Prerequisites 5 | RPC Thunderdome requires the following: 6 | 7 | 1. Java Development Kit 8: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 8 | 9 | 2. Protocol Buffers Compiler - Requires Protobuf 3.5.1 10 | 11 | You can download the compiler from here: https://github.com/google/protobuf/releases 12 | 13 | OR 14 | 15 | If you are on a mac using homebrew you can install it with the following command: 16 | 17 | $ brew install protobuf 18 | 19 | ## Bugs and Feedback 20 | For bugs, questions and discussions please use the [Github Issues](https://github.com/netifi/rpc-thunderdome/issues). 21 | 22 | ## License 23 | Copyright 2017 Netifi Inc. 24 | 25 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 26 | 27 | http://www.apache.org/licenses/LICENSE-2.0 28 | 29 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 30 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | maven { 4 | url "https://plugins.gradle.org/m2/" 5 | } 6 | } 7 | dependencies { 8 | classpath "com.github.jengelman.gradle.plugins:shadow:4.0.3" 9 | } 10 | } 11 | 12 | plugins { 13 | id 'com.gradle.build-scan' version '2.1' 14 | } 15 | 16 | buildScan { 17 | termsOfServiceUrl = 'https://gradle.com/terms-of-service' 18 | termsOfServiceAgree = 'yes' 19 | publishAlways() 20 | } 21 | 22 | allprojects { 23 | repositories { 24 | jcenter() 25 | mavenCentral() 26 | } 27 | } 28 | 29 | subprojects { 30 | apply plugin: "com.github.johnrengelman.shadow" 31 | apply plugin: 'java' 32 | 33 | ext { 34 | protobufVersion = '3.6.1' 35 | rsocketRpcVersion = '0.2.13' 36 | rsocketVersion = '0.11.16' 37 | hdrHistogramVersion = '2.1.11' 38 | log4jVersion = '2.11.2' 39 | reactorNettyVersion ='0.8.5.RELEASE' 40 | grpcCommonsVersion='1.14.0' 41 | grpcVersion='1.18.0' 42 | nettyEpollVersion='4.1.33.Final' 43 | reactorCoreVersion='3.2.6.RELEASE' 44 | junitVersion = '4.12' 45 | mockitoVersion = '1.10.19' 46 | } 47 | 48 | sourceCompatibility = 1.8 49 | targetCompatibility = 1.8 50 | 51 | dependencies { 52 | compile "org.apache.logging.log4j:log4j-api:$log4jVersion" 53 | compile "org.apache.logging.log4j:log4j-core:$log4jVersion" 54 | compile "org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion" 55 | } 56 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | group=io.netifi 2 | version=1.0.0 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netifi/rpc-thunderdome/e79c6242400f5e9a73a6b56a346c813cf2b91e26/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /grpc/README.md: -------------------------------------------------------------------------------- 1 | # gRPC 2 | 3 | ### 128 megs 4 | `java -Xmx128m -Xms128m -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -Dhost=172.16.0.6 -Dcount=100000000 -Dconcurrency=256 -Dthreads=16 -DuseEpoll=true -cp ./grpc-1.0.0-all.jar io.netifi.thunderdome.grpc.nonblocking.rs.MultithreadedGrpcRequestReplyClient` 5 | 6 | `java -Xmx128m -Xms128m -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -Dhost=0.0.0.0 -DuseEpoll=true -cp ./grpc-1.0.0-all.jar io.netifi.thunderdome.grpc.nonblocking.rs.GrpcServer` 7 | 8 | ### 2 gigs 9 | `java -Xmx2g -Xms2g -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -Dhost=172.16.0.6 -Dcount=100000000 -Dconcurrency=256 -Dthreads=16 -DuseEpoll=true -cp ./grpc-1.0.0-all.jar io.netifi.thunderdome.grpc.nonblocking.rs.MultithreadedGrpcRequestReplyClient` 10 | 11 | `java -Xmx2g -Xms2g -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -Dhost=0.0.0.0 -DuseEpoll=true -cp ./grpc-1.0.0-all.jar io.netifi.thunderdome.grpc.nonblocking.rs.GrpcServer` 12 | -------------------------------------------------------------------------------- /grpc/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.google.protobuf' version '0.8.7' 3 | id 'idea' 4 | } 5 | 6 | dependencies { 7 | compile "org.hdrhistogram:HdrHistogram:$hdrHistogramVersion" 8 | compile "com.google.api.grpc:proto-google-common-protos:$grpcCommonsVersion" 9 | compile "io.grpc:grpc-netty:$grpcVersion" 10 | compile "io.netty:netty-transport-native-epoll:$nettyEpollVersion" 11 | compile "io.grpc:grpc-protobuf:$grpcVersion" 12 | compile "io.grpc:grpc-stub:$grpcVersion" 13 | compile "io.projectreactor:reactor-core:$reactorCoreVersion" 14 | 15 | testCompile "io.grpc:grpc-testing:$grpcVersion" 16 | testCompile "junit:junit:$junitVersion" 17 | testCompile "org.mockito:mockito-core:$mockitoVersion" 18 | } 19 | sourceSets { 20 | main { 21 | proto { srcDir 'src/main/proto' } 22 | } 23 | 24 | test { 25 | proto { srcDir 'src/test/proto' } 26 | } 27 | } 28 | 29 | protobuf { 30 | generatedFilesBaseDir = "${projectDir}/src/generated" 31 | 32 | protoc { 33 | artifact = "com.google.protobuf:protoc:$protobufVersion" 34 | } 35 | 36 | plugins { 37 | grpc { 38 | artifact = "io.grpc:protoc-gen-grpc-java:$grpcVersion" 39 | } 40 | generateProtoTasks { 41 | ofSourceSet('main')*.plugins { 42 | grpc {} 43 | } 44 | } 45 | } 46 | } 47 | 48 | idea { 49 | module { 50 | sourceDirs += file("src/main/proto") 51 | sourceDirs += file("src/generated/main/java") 52 | sourceDirs += file("src/generated/main/grpc") 53 | 54 | generatedSourceDirs += file('src/generated/main/java') 55 | generatedSourceDirs += file('src/generated/main/grpc') 56 | } 57 | } 58 | 59 | clean { 60 | delete 'src/generated' 61 | } -------------------------------------------------------------------------------- /grpc/src/main/java/io/netifi/thunderdome/grpc/nonblocking/rs/GrpcRequestReplyClient.java: -------------------------------------------------------------------------------- 1 | package io.netifi.thunderdome.grpc.nonblocking.rs; 2 | 3 | import io.grpc.ManagedChannel; 4 | import io.grpc.netty.NettyChannelBuilder; 5 | import io.grpc.stub.StreamObserver; 6 | import io.netifi.testing.protobuf.SimpleRequest; 7 | import io.netifi.testing.protobuf.SimpleResponse; 8 | import io.netifi.testing.protobuf.SimpleServiceGrpc; 9 | import io.netty.channel.nio.NioEventLoopGroup; 10 | import io.netty.channel.socket.nio.NioSocketChannel; 11 | import io.netty.util.concurrent.DefaultThreadFactory; 12 | import org.HdrHistogram.Histogram; 13 | import org.apache.logging.log4j.LogManager; 14 | import org.apache.logging.log4j.Logger; 15 | import reactor.core.publisher.Flux; 16 | import reactor.core.scheduler.Schedulers; 17 | 18 | import java.util.concurrent.ExecutorService; 19 | import java.util.concurrent.ThreadFactory; 20 | 21 | public class GrpcRequestReplyClient { 22 | private static final Logger logger = LogManager.getLogger(GrpcRequestReplyClient.class); 23 | 24 | public static void main(String... args) throws Exception { 25 | int warmup = 1_000_000; 26 | int count = 1_000_000; 27 | String host = System.getProperty("host", "127.0.0.1"); 28 | int port = Integer.getInteger("port", 8001); 29 | int concurrency = Integer.getInteger("concurrency", 128); 30 | 31 | ThreadFactory tf = new DefaultThreadFactory("client-elg-", true /*daemon */); 32 | NioEventLoopGroup worker = new NioEventLoopGroup(0, tf); 33 | ExecutorService executor = worker; 34 | 35 | ManagedChannel managedChannel = 36 | NettyChannelBuilder.forAddress(host, port) 37 | .eventLoopGroup(worker) 38 | .channelType(NioSocketChannel.class) 39 | .directExecutor() 40 | .flowControlWindow(NettyChannelBuilder.DEFAULT_FLOW_CONTROL_WINDOW) 41 | .usePlaintext() 42 | .build(); 43 | 44 | SimpleServiceGrpc.SimpleServiceStub simpleService = SimpleServiceGrpc.newStub(managedChannel); 45 | 46 | Histogram histogram = new Histogram(3600000000000L, 3); 47 | logger.info("starting warmup..."); 48 | execute(count, simpleService, histogram, concurrency, executor); 49 | logger.info("warmup complete"); 50 | 51 | logger.info("starting test - sending {}", count); 52 | histogram = new Histogram(3600000000000L, 3); 53 | long start = System.nanoTime(); 54 | execute(count, simpleService, histogram, concurrency, executor); 55 | 56 | histogram.outputPercentileDistribution(System.out, 1000.0d); 57 | double completedMillis = (System.nanoTime() - start) / 1_000_000d; 58 | double rps = count / ((System.nanoTime() - start) / 1_000_000_000d); 59 | logger.info("test complete in {} ms", completedMillis); 60 | logger.info("test rps {}", rps); 61 | System.exit(0); 62 | } 63 | 64 | private static void execute( 65 | int count, 66 | SimpleServiceGrpc.SimpleServiceStub simpleService, 67 | Histogram histogram, 68 | int concurrency, 69 | ExecutorService executor) { 70 | Flux.range(1, count) 71 | .publishOn(Schedulers.elastic()) 72 | .flatMap( 73 | integer -> { 74 | long s = System.nanoTime(); 75 | SimpleRequest request = SimpleRequest.newBuilder().setRequestMessage("hello").build(); 76 | return Flux.create( 77 | sink -> { 78 | simpleService.requestReply( 79 | request, 80 | new StreamObserver() { 81 | @Override 82 | public void onNext(SimpleResponse value) { 83 | sink.next(value); 84 | } 85 | 86 | @Override 87 | public void onError(Throwable t) { 88 | sink.error(t); 89 | } 90 | 91 | @Override 92 | public void onCompleted() { 93 | histogram.recordValue(System.nanoTime() - s); 94 | sink.complete(); 95 | } 96 | }); 97 | }); 98 | }, 99 | concurrency) 100 | .blockLast(); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /grpc/src/main/java/io/netifi/thunderdome/grpc/nonblocking/rs/GrpcServer.java: -------------------------------------------------------------------------------- 1 | package io.netifi.thunderdome.grpc.nonblocking.rs; 2 | 3 | import io.grpc.netty.NettyChannelBuilder; 4 | import io.grpc.netty.NettyServerBuilder; 5 | import io.grpc.stub.StreamObserver; 6 | import io.netifi.testing.protobuf.SimpleRequest; 7 | import io.netifi.testing.protobuf.SimpleResponse; 8 | import io.netifi.testing.protobuf.SimpleServiceGrpc; 9 | import io.netty.channel.epoll.EpollServerSocketChannel; 10 | import io.netty.channel.nio.NioEventLoopGroup; 11 | import io.netty.channel.socket.nio.NioServerSocketChannel; 12 | import io.netty.util.concurrent.DefaultThreadFactory; 13 | import org.apache.logging.log4j.LogManager; 14 | import org.apache.logging.log4j.Logger; 15 | 16 | import java.util.concurrent.ThreadFactory; 17 | 18 | public class GrpcServer { 19 | private static final Logger logger = LogManager.getLogger(GrpcServer.class); 20 | 21 | public static void main(String... args) throws Exception { 22 | logger.info("starting server"); 23 | 24 | String host = System.getProperty("host", "0.0.0.0"); 25 | int port = Integer.getInteger("port", 8001); 26 | boolean useEpoll = Boolean.getBoolean("usePoll"); 27 | 28 | Class channel; 29 | 30 | if (useEpoll) { 31 | channel = EpollServerSocketChannel.class; 32 | } else { 33 | channel = NioServerSocketChannel.class; 34 | } 35 | 36 | ThreadFactory tf = new DefaultThreadFactory("server-elg-", true /*daemon */); 37 | NioEventLoopGroup boss = new NioEventLoopGroup(1, tf); 38 | NioEventLoopGroup worker = new NioEventLoopGroup(0, tf); 39 | NettyServerBuilder builder = 40 | NettyServerBuilder.forPort(port) 41 | .bossEventLoopGroup(boss) 42 | .workerEventLoopGroup(worker) 43 | .channelType(channel) 44 | .addService(new DefaultService()) 45 | .directExecutor() 46 | .maxConcurrentCallsPerConnection(Runtime.getRuntime().availableProcessors() * 256) 47 | .flowControlWindow(NettyChannelBuilder.DEFAULT_FLOW_CONTROL_WINDOW * 10); 48 | 49 | io.grpc.Server start = builder.build(); 50 | start.start(); 51 | 52 | logger.info("server started"); 53 | start.awaitTermination(); 54 | } 55 | 56 | static class DefaultService extends SimpleServiceGrpc.SimpleServiceImplBase { 57 | @Override 58 | public void requestReply( 59 | SimpleRequest request, StreamObserver responseObserver) { 60 | SimpleResponse response = 61 | SimpleResponse.newBuilder().setResponseMessage(request.getRequestMessage()).build(); 62 | responseObserver.onNext(response); 63 | responseObserver.onCompleted(); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /grpc/src/main/java/io/netifi/thunderdome/grpc/nonblocking/rs/MultithreadedGrpcRequestReplyClient.java: -------------------------------------------------------------------------------- 1 | package io.netifi.thunderdome.grpc.nonblocking.rs; 2 | 3 | import io.grpc.ManagedChannel; 4 | import io.grpc.netty.NettyChannelBuilder; 5 | import io.grpc.stub.StreamObserver; 6 | import io.netifi.testing.protobuf.SimpleRequest; 7 | import io.netifi.testing.protobuf.SimpleResponse; 8 | import io.netifi.testing.protobuf.SimpleServiceGrpc; 9 | import io.netty.channel.epoll.EpollSocketChannel; 10 | import io.netty.channel.nio.NioEventLoopGroup; 11 | import io.netty.channel.socket.nio.NioSocketChannel; 12 | import io.netty.util.concurrent.DefaultThreadFactory; 13 | import org.HdrHistogram.Histogram; 14 | import org.apache.logging.log4j.LogManager; 15 | import org.apache.logging.log4j.Logger; 16 | import reactor.core.publisher.Flux; 17 | import reactor.core.publisher.Mono; 18 | import reactor.core.scheduler.Schedulers; 19 | 20 | import java.util.concurrent.CountDownLatch; 21 | import java.util.concurrent.ThreadFactory; 22 | 23 | public class MultithreadedGrpcRequestReplyClient { 24 | private static final Logger logger = LogManager.getLogger(MultithreadedGrpcRequestReplyClient.class); 25 | 26 | public static void main(String... args) throws Exception { 27 | String host = System.getProperty("host", "127.0.0.1"); 28 | int port = Integer.getInteger("port", 8001); 29 | int count = Integer.getInteger("count", 1_000_000); 30 | int concurrency = Integer.getInteger("concurrency", 64); 31 | int threads = Integer.getInteger("threads", 3); 32 | boolean useEpoll = Boolean.getBoolean("usePoll"); 33 | 34 | ThreadFactory tf = new DefaultThreadFactory("client-elg-", true /*daemon */); 35 | NioEventLoopGroup worker = new NioEventLoopGroup(0, tf); 36 | 37 | Class channel; 38 | 39 | if (useEpoll) { 40 | channel = EpollSocketChannel.class; 41 | } else { 42 | channel = NioSocketChannel.class; 43 | } 44 | 45 | Histogram histogram = new Histogram(3600000000000L, 3); 46 | logger.info("starting test - sending {}", count); 47 | CountDownLatch latch = new CountDownLatch(threads); 48 | long start = System.nanoTime(); 49 | Flux.range(1, threads) 50 | .flatMap( 51 | i -> { 52 | logger.info("start thread -> {}", i); 53 | ManagedChannel managedChannel = 54 | NettyChannelBuilder.forAddress(host, port) 55 | .eventLoopGroup(worker) 56 | .channelType(channel) 57 | .directExecutor() 58 | .flowControlWindow(NettyChannelBuilder.DEFAULT_FLOW_CONTROL_WINDOW) 59 | .usePlaintext() 60 | .build(); 61 | 62 | SimpleServiceGrpc.SimpleServiceStub simpleService = 63 | SimpleServiceGrpc.newStub(managedChannel); 64 | 65 | return Mono.fromRunnable( 66 | () -> { 67 | int i1 = count / threads; 68 | try { 69 | latch.countDown(); 70 | latch.await(); 71 | } catch (InterruptedException e) { 72 | throw new RuntimeException(e); 73 | } 74 | execute(i1, simpleService, histogram, concurrency); 75 | }) 76 | .subscribeOn(Schedulers.elastic()); 77 | }) 78 | .blockLast(); 79 | 80 | histogram.outputPercentileDistribution(System.out, 1000.0d); 81 | double completedMillis = (System.nanoTime() - start) / 1_000_000d; 82 | double rps = count / ((System.nanoTime() - start) / 1_000_000_000d); 83 | logger.info("test complete in {} ms", completedMillis); 84 | logger.info("test rps {}", rps); 85 | } 86 | 87 | private static void execute( 88 | int count, 89 | SimpleServiceGrpc.SimpleServiceStub simpleService, 90 | Histogram histogram, 91 | int concurrency) { 92 | Flux.range(1, count) 93 | .flatMap( 94 | integer -> { 95 | long s = System.nanoTime(); 96 | SimpleRequest request = SimpleRequest.newBuilder().setRequestMessage("hello").build(); 97 | return Flux.create( 98 | sink -> { 99 | simpleService.requestReply( 100 | request, 101 | new StreamObserver() { 102 | @Override 103 | public void onNext(SimpleResponse value) { 104 | sink.next(value); 105 | } 106 | 107 | @Override 108 | public void onError(Throwable t) { 109 | sink.error(t); 110 | } 111 | 112 | @Override 113 | public void onCompleted() { 114 | histogram.recordValue(System.nanoTime() - s); 115 | sink.complete(); 116 | } 117 | }); 118 | }); 119 | }, 120 | concurrency) 121 | .blockLast(); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /grpc/src/main/java/io/netifi/thunderdome/grpc/nonblocking/stock/GrpcRequestReplyClient.java: -------------------------------------------------------------------------------- 1 | package io.netifi.thunderdome.grpc.nonblocking.stock; 2 | 3 | import io.grpc.ManagedChannel; 4 | import io.grpc.ManagedChannelBuilder; 5 | import io.netifi.testing.protobuf.SimpleRequest; 6 | import io.netifi.testing.protobuf.SimpleServiceGrpc; 7 | import org.HdrHistogram.Histogram; 8 | import org.apache.logging.log4j.LogManager; 9 | import org.apache.logging.log4j.Logger; 10 | 11 | import java.util.concurrent.CountDownLatch; 12 | import java.util.concurrent.ForkJoinPool; 13 | 14 | public class GrpcRequestReplyClient { 15 | private static final Logger logger = LogManager.getLogger(GrpcRequestReplyClient.class); 16 | 17 | public static void main(String... args) throws Exception { 18 | int warmup = 10_000; 19 | int count = 1_000_000; 20 | 21 | String host = System.getProperty("host", "127.0.0.1"); 22 | int port = Integer.getInteger("port", 8001); 23 | 24 | ManagedChannel managedChannel = 25 | ManagedChannelBuilder.forAddress(host, port).usePlaintext().build(); 26 | SimpleServiceGrpc.SimpleServiceFutureStub simpleService = 27 | SimpleServiceGrpc.newFutureStub(managedChannel); 28 | 29 | CountDownLatch warmupLatch = new CountDownLatch(warmup); 30 | 31 | ForkJoinPool executorService = ForkJoinPool.commonPool(); 32 | logger.info("starting warmup..."); 33 | 34 | for (int i = 0; i < warmup; i++) { 35 | SimpleRequest hello = SimpleRequest.newBuilder().setRequestMessage("hello").build(); 36 | simpleService.requestReply(hello).addListener(warmupLatch::countDown, executorService); 37 | } 38 | 39 | warmupLatch.await(); 40 | logger.info("warmup complete"); 41 | 42 | logger.info("starting test - sending {}", count); 43 | CountDownLatch latch = new CountDownLatch(count); 44 | Histogram histogram = new Histogram(3600000000000L, 3); 45 | long start = System.nanoTime(); 46 | for (int i = 0; i < count; i++) { 47 | long s = System.nanoTime(); 48 | SimpleRequest hello = SimpleRequest.newBuilder().setRequestMessage("hello").build(); 49 | simpleService 50 | .requestReply(hello) 51 | .addListener( 52 | () -> { 53 | histogram.recordValue(System.nanoTime() - s); 54 | latch.countDown(); 55 | }, 56 | executorService); 57 | } 58 | 59 | double completedMillis = (System.nanoTime() - start) / 1_000_000d; 60 | double rps = count / ((System.nanoTime() - start) / 1_000_000_000d); 61 | logger.info("test complete in {} ms", completedMillis); 62 | logger.info("test rps {}", rps); 63 | latch.await(); 64 | managedChannel.shutdownNow(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /grpc/src/main/java/io/netifi/thunderdome/grpc/nonblocking/stock/GrpcServer.java: -------------------------------------------------------------------------------- 1 | package io.netifi.thunderdome.grpc.nonblocking.stock; 2 | 3 | import io.grpc.ServerBuilder; 4 | import io.grpc.stub.StreamObserver; 5 | import io.netifi.testing.protobuf.SimpleRequest; 6 | import io.netifi.testing.protobuf.SimpleResponse; 7 | import io.netifi.testing.protobuf.SimpleServiceGrpc; 8 | import io.netifi.thunderdome.grpc.nonblocking.rs.MultithreadedGrpcRequestReplyClient; 9 | import org.apache.logging.log4j.LogManager; 10 | import org.apache.logging.log4j.Logger; 11 | 12 | public class GrpcServer { 13 | private static final Logger logger = LogManager.getLogger(GrpcServer.class); 14 | 15 | static class DefaultService extends SimpleServiceGrpc.SimpleServiceImplBase { 16 | @Override 17 | public void requestReply(SimpleRequest request, StreamObserver responseObserver) { 18 | SimpleResponse response = SimpleResponse.newBuilder().setResponseMessage(request.getRequestMessage()).build(); 19 | responseObserver.onNext(response); 20 | responseObserver.onCompleted(); 21 | } 22 | } 23 | 24 | public static void main(String... args) throws Exception { 25 | logger.info("starting server"); 26 | 27 | String host = System.getProperty("host", "127.0.0.1"); 28 | int port = Integer.getInteger("port", 8001); 29 | 30 | io.grpc.Server start = ServerBuilder.forPort(port) 31 | .addService(new DefaultService()) 32 | .build() 33 | .start(); 34 | 35 | logger.info("server started"); 36 | start.awaitTermination(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /grpc/src/main/proto/io/netifi/thunderdome/grpc/nonblocking/stock/simpleservice.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package io.netifi.testing; 4 | 5 | import "google/protobuf/empty.proto"; 6 | 7 | option java_package = "io.netifi.testing.protobuf"; 8 | option java_outer_classname = "SimpleServiceProto"; 9 | option java_multiple_files = true; 10 | 11 | service SimpleService { 12 | // Request / Response 13 | rpc RequestReply (SimpleRequest) returns (SimpleResponse) {} 14 | 15 | // Fire-and-Forget 16 | rpc FireAndForget (SimpleRequest) returns (google.protobuf.Empty) {} 17 | 18 | // Single Request / Streaming Response 19 | rpc RequestStream (SimpleRequest) returns (stream SimpleResponse) {} 20 | 21 | // Streaming Request / Single Response 22 | rpc StreamingRequestSingleResponse (stream SimpleRequest) returns (SimpleResponse) {} 23 | 24 | // Streaming Request / Streaming Response 25 | rpc StreamingRequestAndResponse (stream SimpleRequest) returns (stream SimpleResponse) {} 26 | } 27 | 28 | message SimpleRequest { 29 | string requestMessage = 1; 30 | } 31 | 32 | message SimpleResponse { 33 | string responseMessage = 1; 34 | } -------------------------------------------------------------------------------- /grpc/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /ratpack/README.md: -------------------------------------------------------------------------------- 1 | # Ratpack 2 | 3 | ### 128 megs 4 | `java -Xmx128m -Xms128m -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -Dhost=172.16.0.6 -Dconcurrency=256 -Dcount=100000000 -cp ./ratpack-1.0.0-all.jar io.netifi.thunderdome.ratpack.RatpackRequestReply` 5 | 6 | `java -Xmx128m -Xms128m -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -Dhost=0.0.0.0 -cp ./ratpack-1.0.0-all.jar io.netifi.thunderdome.ratpack.RatpackTestServer` 7 | 8 | ### 2 gigs 9 | `java -Xmx2g -Xms2g -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -Dhost=172.16.0.6 -Dconcurrency=256 -Dcount=100000000 -cp ./ratpack-1.0.0-all.jar io.netifi.thunderdome.ratpack.RatpackRequestReply` 10 | 11 | `java -Xmx2g -Xms2g -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -Dhost=0.0.0.0 -cp ./ratpack-1.0.0-all.jar io.netifi.thunderdome.ratpack.RatpackTestServer` 12 | -------------------------------------------------------------------------------- /ratpack/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "io.ratpack.ratpack-java" version "1.6.0" 3 | id 'idea' 4 | } 5 | 6 | mainClassName = 'io.netifi.thunderdome.ratpack.RatpackTestServer' 7 | 8 | dependencies { 9 | compile "org.hdrhistogram:HdrHistogram:$hdrHistogramVersion" 10 | compile "io.projectreactor.netty:reactor-netty:$reactorNettyVersion" 11 | 12 | testCompile "junit:junit:$junitVersion" 13 | testCompile "org.mockito:mockito-core:$mockitoVersion" 14 | } 15 | -------------------------------------------------------------------------------- /ratpack/src/main/java/io/netifi/thunderdome/ratpack/RatpackRequestReply.java: -------------------------------------------------------------------------------- 1 | package io.netifi.thunderdome.ratpack; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import io.netty.buffer.ByteBuf; 6 | import io.netty.buffer.Unpooled; 7 | import org.HdrHistogram.Histogram; 8 | import org.apache.logging.log4j.LogManager; 9 | import org.apache.logging.log4j.Logger; 10 | import reactor.core.publisher.Flux; 11 | import reactor.core.publisher.Mono; 12 | import reactor.netty.http.client.HttpClient; 13 | import reactor.netty.resources.ConnectionProvider; 14 | 15 | import java.io.IOException; 16 | import java.io.InputStream; 17 | 18 | public class RatpackRequestReply { 19 | private static final Logger logger = LogManager.getLogger(RatpackRequestReply.class); 20 | 21 | public static void main(String... args) { 22 | int warmup = 1_000_000; 23 | 24 | int count = Integer.getInteger("count", 1_000_000); 25 | int concurrency = Integer.getInteger("concurrency", 16); 26 | 27 | String host = System.getProperty("host", "127.0.0.1"); 28 | int port = Integer.getInteger("port", 5050); 29 | 30 | ObjectMapper mapper = new ObjectMapper(); 31 | 32 | ConnectionProvider connectionProvider = ConnectionProvider 33 | .fixed("test", concurrency); 34 | HttpClient client = HttpClient 35 | .create(connectionProvider) 36 | .tcpConfiguration(c -> c.port(port).host(host)); 37 | 38 | logger.info("starting warmup..."); 39 | 40 | Flux.range(0, warmup) 41 | .flatMap( 42 | integer -> client 43 | .post() 44 | .uri("/") 45 | .send(newRequest(mapper)) 46 | .responseContent() 47 | .aggregate() 48 | .asInputStream() 49 | .map(content -> toResponse(mapper, content))) 50 | .doOnError(Throwable::printStackTrace) 51 | .blockLast(); 52 | logger.info("warmup complete"); 53 | 54 | long start = System.nanoTime(); 55 | Histogram histogram = new Histogram(3600000000000L, 3); 56 | logger.info("starting test - sending {}", count); 57 | Flux.range(0, count) 58 | .flatMap( 59 | integer -> { 60 | long s = System.nanoTime(); 61 | return client 62 | .post() 63 | .uri("/") 64 | .send(newRequest(mapper)) 65 | .responseContent() 66 | .aggregate() 67 | .asInputStream() 68 | .map(content -> toResponse(mapper, content)) 69 | .doOnNext(r -> histogram.recordValue(System.nanoTime() - s)); 70 | }, 71 | concurrency) 72 | .doFinally(s -> connectionProvider.dispose()) 73 | .blockLast(); 74 | histogram.outputPercentileDistribution(System.out, 1000.0d); 75 | double completedMillis = (System.nanoTime() - start) / 1_000_000d; 76 | double rps = count / ((System.nanoTime() - start) / 1_000_000_000d); 77 | logger.info("test complete in {} ms", completedMillis); 78 | logger.info("test rps {}", rps); 79 | } 80 | 81 | private static SimpleResponse toResponse(ObjectMapper mapper, InputStream response) { 82 | try { 83 | return mapper.readValue(response, SimpleResponse.class); 84 | } catch (IOException e) { 85 | logger.error(response, e); 86 | throw new RuntimeException(e); 87 | } 88 | } 89 | 90 | private static Mono newRequest(ObjectMapper mapper) { 91 | SimpleRequest request = new SimpleRequest(); 92 | request.setMessage("hello"); 93 | try { 94 | return Mono.just(Unpooled.wrappedBuffer(mapper.writeValueAsBytes(request))); 95 | } catch (JsonProcessingException e) { 96 | return Mono.error(e); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /ratpack/src/main/java/io/netifi/thunderdome/ratpack/RatpackTestServer.java: -------------------------------------------------------------------------------- 1 | package io.netifi.thunderdome.ratpack; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import ratpack.http.Request; 5 | import ratpack.http.Response; 6 | 7 | public class RatpackTestServer { 8 | 9 | public static void main(String... args) throws Exception { 10 | ObjectMapper mapper = new ObjectMapper(); 11 | ratpack.server.RatpackServer.start( 12 | server -> { 13 | server.handlers( 14 | chain -> { 15 | chain.post( 16 | "", 17 | ctx -> { 18 | Request request = ctx.getRequest(); 19 | request 20 | .getBody() 21 | .then( 22 | data -> { 23 | SimpleRequest simpleRequest = 24 | mapper.readValue(data.getInputStream(), SimpleRequest.class); 25 | SimpleResponse simpleResponse = new SimpleResponse(); 26 | simpleResponse.setMessage(simpleRequest.getMessage()); 27 | String s = mapper.writeValueAsString(simpleResponse); 28 | Response response = ctx.getResponse(); 29 | response 30 | .contentTypeIfNotSet("application/javascript") 31 | .status(200) 32 | .send(s); 33 | }); 34 | }); 35 | }); 36 | }); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ratpack/src/main/java/io/netifi/thunderdome/ratpack/SimpleRequest.java: -------------------------------------------------------------------------------- 1 | package io.netifi.thunderdome.ratpack; 2 | 3 | public class SimpleRequest { 4 | String message; 5 | 6 | public String getMessage() { 7 | return message; 8 | } 9 | 10 | public void setMessage(String message) { 11 | this.message = message; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ratpack/src/main/java/io/netifi/thunderdome/ratpack/SimpleResponse.java: -------------------------------------------------------------------------------- 1 | package io.netifi.thunderdome.ratpack; 2 | 3 | public class SimpleResponse { 4 | String message; 5 | 6 | public String getMessage() { 7 | return message; 8 | } 9 | 10 | public void setMessage(String message) { 11 | this.message = message; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ratpack/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /rsocket-rpc/README.md: -------------------------------------------------------------------------------- 1 | # RSocket RPC 2 | Requires Protobuf 3.6.1 3 | 4 | ### 92 megs 5 | `java -Xmx92m -Xms92m -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -verbose:gc -Dhost=172.16.0.6 -Dcount=100000000 -Dconcurrency=192 -Dthreads=16 -cp ./rsocket-rpc-1.0.0.jar io.netifi.thunderdome.rsocketrpc.MultithreadedRSocketRpcRequestReplyClient` 6 | 7 | `java -Xmx92m -Xms92m -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -verbose:gc -Dhost=0.0.0.0 -cp ./rsocket-rpc-1.0.0.jar io.netifi.thunderdome.rsocketrpc.RSocketRpcServer` 8 | 9 | ### 128 megs 10 | `java -Xmx128m -Xms128m -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -verbose:gc -Dhost=172.16.0.6 -Dcount=100000000 -Dconcurrency=192 -Dthreads=16 -cp ./rsocket-rpc-1.0.0.jar io.netifi.thunderdome.rsocketrpc.MultithreadedRSocketRpcRequestReplyClient` 11 | 12 | `java -Xmx128m -Xms128m -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -verbose:gc -Dhost=0.0.0.0 -cp ./rsocket-rpc-1.0.0.jar io.netifi.thunderdome.rsocketrpc.RSocketRpcServer` 13 | 14 | ### 2 gigs 15 | `java -Xmx2g -Xms2g -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -Dhost=172.16.0.6 -Dcount=100000000 -Dconcurrency=128 -Dthreads=16 -cp ./rsocket-rpc-1.0.0.jar io.netifi.thunderdome.rsocketrpc.MultithreadedRSocketRpcRequestReplyClient` 16 | 17 | `java -Xmx2g -Xms2g -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -Dhost=0.0.0.0 -cp ./rsocket-rpc-1.0.0.jar io.netifi.thunderdome.rsocketrpc.RSocketRpcServer` 18 | 19 | -------------------------------------------------------------------------------- /rsocket-rpc/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.google.protobuf' version '0.8.7' 3 | id 'idea' 4 | } 5 | 6 | dependencies { 7 | compile "org.hdrhistogram:HdrHistogram:$hdrHistogramVersion" 8 | compile "io.rsocket:rsocket-transport-netty:$rsocketVersion" 9 | compile "com.google.protobuf:protobuf-java:$protobufVersion" 10 | compile("io.rsocket.rpc:rsocket-rpc-core:$rsocketRpcVersion") { 11 | exclude group: 'org.slf4j', module: 'slf4j-api' 12 | } 13 | } 14 | 15 | sourceSets { 16 | main { 17 | proto { srcDir 'src/main/proto' } 18 | } 19 | 20 | test { 21 | proto { srcDir 'src/test/proto' } 22 | } 23 | } 24 | 25 | protobuf { 26 | generatedFilesBaseDir = "${projectDir}/src/generated" 27 | 28 | protoc { 29 | artifact = "com.google.protobuf:protoc:$protobufVersion" 30 | } 31 | plugins { 32 | rsocketRpc { 33 | artifact = "io.rsocket.rpc:rsocket-rpc-protobuf:$rsocketRpcVersion" 34 | } 35 | } 36 | generateProtoTasks { 37 | ofSourceSet('main')*.plugins { 38 | rsocketRpc {} 39 | } 40 | } 41 | } 42 | 43 | idea { 44 | module { 45 | sourceDirs += file("src/main/proto") 46 | sourceDirs += file("src/generated/main/java") 47 | sourceDirs += file("src/generated/main/rsocketRpc") 48 | 49 | generatedSourceDirs += file('src/generated/main/java') 50 | generatedSourceDirs += file('src/generated/main/rsocketRpc') 51 | } 52 | } 53 | 54 | clean { 55 | delete 'src/generated/main' 56 | } -------------------------------------------------------------------------------- /rsocket-rpc/src/main/java/io/netifi/thunderdome/rsocketrpc/MultithreadedRSocketRpcRequestReplyClient.java: -------------------------------------------------------------------------------- 1 | package io.netifi.thunderdome.rsocketrpc; 2 | 3 | import io.netifi.testing.protobuf.SimpleRequest; 4 | import io.netifi.testing.protobuf.SimpleServiceClient; 5 | import io.rsocket.Frame; 6 | import io.rsocket.RSocket; 7 | import io.rsocket.RSocketFactory; 8 | import io.rsocket.transport.netty.client.TcpClientTransport; 9 | import org.HdrHistogram.Histogram; 10 | import org.apache.logging.log4j.LogManager; 11 | import org.apache.logging.log4j.Logger; 12 | import reactor.core.publisher.Flux; 13 | import reactor.core.publisher.Mono; 14 | import reactor.core.scheduler.Schedulers; 15 | 16 | import java.time.Duration; 17 | import java.util.concurrent.CountDownLatch; 18 | 19 | public class MultithreadedRSocketRpcRequestReplyClient { 20 | private static final Logger logger = 21 | LogManager.getLogger(MultithreadedRSocketRpcRequestReplyClient.class); 22 | 23 | public static void main(String... args) { 24 | 25 | String host = System.getProperty("host", "127.0.0.1"); 26 | int port = Integer.getInteger("port", 8001); 27 | int count = Integer.getInteger("count", 1_000_000); 28 | int concurrency = Integer.getInteger("concurrency", 16); 29 | int threads = Integer.getInteger("threads", 3); 30 | 31 | Histogram histogram = new Histogram(3600000000000L, 3); 32 | 33 | logger.info("starting test - sending {}", count); 34 | CountDownLatch latch = new CountDownLatch(threads); 35 | long start = System.nanoTime(); 36 | Flux.range(1, threads) 37 | .flatMap( 38 | i -> { 39 | return Mono.fromRunnable( 40 | () -> { 41 | logger.info("start thread -> {}", i); 42 | RSocket rSocket = 43 | RSocketFactory.connect() 44 | .frameDecoder(Frame::retain) 45 | .keepAlive(Duration.ofSeconds(1), Duration.ofSeconds(5), 1) 46 | .transport(TcpClientTransport.create(host, port)) 47 | .start() 48 | .block(); 49 | 50 | SimpleServiceClient client = new SimpleServiceClient(rSocket); 51 | int i1 = count / threads; 52 | try { 53 | latch.countDown(); 54 | latch.await(); 55 | } catch (InterruptedException e) { 56 | throw new RuntimeException(e); 57 | } 58 | Flux.range(0, i1) 59 | .flatMap( 60 | integer -> { 61 | long s = System.nanoTime(); 62 | SimpleRequest request = 63 | SimpleRequest.newBuilder().setRequestMessage("hello").build(); 64 | 65 | return client 66 | .requestReply(request) 67 | .doFinally( 68 | simpleResponse -> { 69 | histogram.recordValue(System.nanoTime() - s); 70 | }); 71 | }, 72 | concurrency) 73 | .blockLast(); 74 | }) 75 | .subscribeOn(Schedulers.elastic()); 76 | }) 77 | .blockLast(); 78 | 79 | histogram.outputPercentileDistribution(System.out, 1000.0d); 80 | double completedMillis = (System.nanoTime() - start) / 1_000_000d; 81 | double rps = count / ((System.nanoTime() - start) / 1_000_000_000d); 82 | logger.info("test complete in {} ms", completedMillis); 83 | logger.info("test rps {}", rps); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /rsocket-rpc/src/main/java/io/netifi/thunderdome/rsocketrpc/RSocketRpcRequestReplyClient.java: -------------------------------------------------------------------------------- 1 | package io.netifi.thunderdome.rsocketrpc; 2 | 3 | import io.netifi.testing.protobuf.SimpleRequest; 4 | import io.netifi.testing.protobuf.SimpleServiceClient; 5 | import io.rsocket.Frame; 6 | import io.rsocket.RSocket; 7 | import io.rsocket.RSocketFactory; 8 | import io.rsocket.transport.netty.client.TcpClientTransport; 9 | import org.HdrHistogram.Histogram; 10 | import org.apache.logging.log4j.LogManager; 11 | import org.apache.logging.log4j.Logger; 12 | import reactor.core.publisher.Flux; 13 | 14 | import java.time.Duration; 15 | 16 | public class RSocketRpcRequestReplyClient { 17 | private static final Logger logger = LogManager.getLogger(RSocketRpcRequestReplyClient.class); 18 | 19 | public static void main(String... args) { 20 | 21 | String host = System.getProperty("host", "127.0.0.1"); 22 | int port = Integer.getInteger("port", 8001); 23 | int concurrency = Integer.getInteger("concurrency", 64); 24 | 25 | int warmup = 1_000_000; 26 | int count = 1_000_000; 27 | 28 | RSocket rSocket = 29 | RSocketFactory.connect() 30 | .frameDecoder(Frame::retain) 31 | .keepAlive(Duration.ofSeconds(1), Duration.ofSeconds(5), 1) 32 | .transport(TcpClientTransport.create(host, port)) 33 | .start() 34 | .block(); 35 | 36 | SimpleServiceClient client = new SimpleServiceClient(rSocket); 37 | 38 | logger.info("starting warmup..."); 39 | Flux.range(0, warmup) 40 | .flatMap( 41 | integer -> { 42 | SimpleRequest request = SimpleRequest.newBuilder().setRequestMessage("hello").build(); 43 | return client.requestReply(request); 44 | }) 45 | .doOnError(Throwable::printStackTrace) 46 | .blockLast(); 47 | logger.info("warmup complete"); 48 | 49 | long start = System.nanoTime(); 50 | Histogram histogram = new Histogram(3600000000000L, 3); 51 | logger.info("starting test - sending " + count); 52 | Flux.range(0, count) 53 | .flatMap( 54 | integer -> { 55 | long s = System.nanoTime(); 56 | SimpleRequest request = SimpleRequest.newBuilder().setRequestMessage("hello").build(); 57 | 58 | return client 59 | .requestReply(request) 60 | .doFinally( 61 | simpleResponse -> { 62 | histogram.recordValue(System.nanoTime() - s); 63 | }); 64 | }, 65 | concurrency) 66 | .blockLast(); 67 | histogram.outputPercentileDistribution(System.out, 1000.0d); 68 | double completedMillis = (System.nanoTime() - start) / 1_000_000d; 69 | double rps = count / ((System.nanoTime() - start) / 1_000_000_000d); 70 | logger.info("test complete in {} ms", completedMillis); 71 | logger.info("test rps {}", rps); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /rsocket-rpc/src/main/java/io/netifi/thunderdome/rsocketrpc/RSocketRpcServer.java: -------------------------------------------------------------------------------- 1 | package io.netifi.thunderdome.rsocketrpc; 2 | 3 | import com.google.protobuf.Empty; 4 | import io.netifi.testing.protobuf.SimpleRequest; 5 | import io.netifi.testing.protobuf.SimpleResponse; 6 | import io.netifi.testing.protobuf.SimpleService; 7 | import io.netifi.testing.protobuf.SimpleServiceServer; 8 | import io.rsocket.Frame; 9 | import io.rsocket.RSocketFactory; 10 | import io.rsocket.transport.netty.server.TcpServerTransport; 11 | import org.apache.logging.log4j.LogManager; 12 | import org.apache.logging.log4j.Logger; 13 | import org.reactivestreams.Publisher; 14 | import reactor.core.publisher.Flux; 15 | import reactor.core.publisher.Mono; 16 | 17 | import java.util.Optional; 18 | 19 | public class RSocketRpcServer { 20 | private static final Logger logger = LogManager.getLogger(RSocketRpcServer.class); 21 | 22 | public static void main(String... args) { 23 | String host = System.getProperty("host", "127.0.0.1"); 24 | int port = Integer.getInteger("port", 8001); 25 | RSocketFactory.receive() 26 | .frameDecoder(Frame::retain) 27 | .acceptor( 28 | (setup, sendingSocket) -> 29 | Mono.just( 30 | new SimpleServiceServer( 31 | new DefaultService(), Optional.empty(), Optional.empty()))) 32 | .transport(TcpServerTransport.create(host, port)) 33 | .start() 34 | .block() 35 | .onClose() 36 | .doOnSubscribe(s -> logger.info("server started")) 37 | .block(); 38 | } 39 | 40 | static class DefaultService implements SimpleService { 41 | @Override 42 | public Mono requestReply(SimpleRequest message, io.netty.buffer.ByteBuf metadata) { 43 | return Mono.create( 44 | sink -> { 45 | String requestMessage = message.getRequestMessage(); 46 | SimpleResponse response = 47 | SimpleResponse.newBuilder().setResponseMessage(requestMessage).build(); 48 | sink.success(response); 49 | }); 50 | } 51 | 52 | @Override 53 | public Mono fireAndForget(SimpleRequest message, io.netty.buffer.ByteBuf metadata) { 54 | return notImplementedMono(); 55 | } 56 | 57 | @Override 58 | public Flux requestStream(SimpleRequest message, io.netty.buffer.ByteBuf metadata) { 59 | return notImplementedFlux(); 60 | } 61 | 62 | @Override 63 | public Mono streamingRequestSingleResponse(Publisher messages, io.netty.buffer.ByteBuf metadata) { 64 | return notImplementedMono(); 65 | } 66 | 67 | @Override 68 | public Flux streamingRequestAndResponse(Publisher messages, io.netty.buffer.ByteBuf metadata) { 69 | return notImplementedFlux(); 70 | } 71 | 72 | private static Mono notImplementedMono() { 73 | return Mono.error(new UnsupportedOperationException("Not implemented")); 74 | } 75 | 76 | private static Flux notImplementedFlux() { 77 | return Flux.error(new UnsupportedOperationException("Not implemented")); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /rsocket-rpc/src/main/proto/io/netifi/thunderdome/rsocketrpc/simpleservice.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package io.netifi.testing; 4 | 5 | import "google/protobuf/empty.proto"; 6 | 7 | option java_package = "io.netifi.testing.protobuf"; 8 | option java_outer_classname = "SimpleServiceProto"; 9 | option java_multiple_files = true; 10 | 11 | service SimpleService { 12 | // Request / Response 13 | rpc RequestReply (SimpleRequest) returns (SimpleResponse) {} 14 | 15 | // Fire-and-Forget 16 | rpc FireAndForget (SimpleRequest) returns (google.protobuf.Empty) {} 17 | 18 | // Single Request / Streaming Response 19 | rpc RequestStream (SimpleRequest) returns (stream SimpleResponse) {} 20 | 21 | // Streaming Request / Single Response 22 | rpc StreamingRequestSingleResponse (stream SimpleRequest) returns (SimpleResponse) {} 23 | 24 | // Streaming Request / Streaming Response 25 | rpc StreamingRequestAndResponse (stream SimpleRequest) returns (stream SimpleResponse) {} 26 | } 27 | 28 | message SimpleRequest { 29 | string requestMessage = 1; 30 | } 31 | 32 | message SimpleResponse { 33 | string responseMessage = 1; 34 | } -------------------------------------------------------------------------------- /rsocket-rpc/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'rpc-thunderdome' 2 | include 'grpc' 3 | include 'rsocket-rpc' 4 | include 'ratpack' --------------------------------------------------------------------------------