Repository navigation
Make go faster (also format using gofmt and remove extra semicolons) - #7
Conversation
|
There was an earlier pull request #4 Is there a good consensus among the Go community about which one of these changes we should use? Otherwise we can attempt to benchmark them and simply choose the fastest. |
|
"Otherwise we can attempt to benchmark them and simply choose the fastest." The logic behind this change was to avoid chunking and content sniffing. Something the other change does not do. |
|
Do both? I don't know much about http, but I do know about json encoding. I eliminated the allocation -> []byte -> string -> []byte steps. |
|
Doing both is not as easy without introducing another buffer (which will be more expensive by far). Also, my code does eliminate the string part of the allocations. This should be tested of course, but I think the gains from eliminating chunking and content sniffing are going to be large compared to an extra small allocation. |
|
I won't contest this :) |
|
A bigger problem lurks in setup.py -> "go run hello.go" <- this compiles the sources inside a test run. edit 2: @skelterjohn I should take a look at how many http requests must be processed here. |
|
I imagine that what's being measured is the http throughput. The startup On Thursday, March 28, 2013, shogg wrote:
|
|
@skelterjohn: I agree compilation is a one time cost, but it should be fixed so that people don't blame Go not winning on it. 😺 |
|
@TechEmpower : Any remaining concerns related to pulling this? |
|
@tarndt We tested this change along with #4 and found that they both provided ~1 - 2% increase. We don't have a preference one way or the other since they both perform similarly, if the Go community has any thoughts, that would be helpful. We're still running our tests off version 1.0.3, so both of these changes may have different results on the latest tip, but we can't yet confirm that. |
|
@TechEmpower , Thanks. I guess I should not be too surprised since the output will end up in one chunk and the output is so small the "net/http" can probably quickly sniff the content type. In real world applications these changes matter and I think they would have an effect if the ouput data was larger. One note, the setting of the Content-Type is compatible with the other code, so if you go that route you can still add that. As for using Go tip, unless you have spare time, you might as well wait for the Go 1.1 RC to be out next month. I imagine you will want to do a benchmarks part 2 blog where you have applied all your feedback from the various language communities. One additional concern is that all of the languages should be using the same URL for the json path, otherwise the test case is so small that path routing will be benchmarked much more heavily than is realistic. |
|
Based on this comment "In real world applications these changes matter and I think they would have an effect if the ouput data was larger.", we feel that it makes sense to use this as representative of production ready code. Thanks @tarndt for the changes! |
|
Great, thanks for being response about this. Keep an eye out for go1.1 - it will speed this benchmark up significantly. On Mon, Apr 1, 2013 at 10:11 AM, TechEmpower [email protected]:
|
|
s/response/responsive/ On Mon, Apr 1, 2013 at 10:13 AM, John Asmuth [email protected] wrote:
|
Here's an example of the error output from before this change: Unhandled exception: Bad state: Stream was already listened to #0 _RawServerSocket.listen (dart:io-patch/socket_patch.dart:1106) TechEmpower#1 new _ForwardingStreamSubscription (dart:async/stream_pipe.dart:123) TechEmpower#2 _ForwardingStream._createSubscription (dart:async/stream_pipe.dart:91) TechEmpower#3 _ForwardingStream.listen (dart:async/stream_pipe.dart:86) TechEmpower#4 _ServerSocket.listen (dart:io-patch/socket_patch.dart:1351) TechEmpower#5 _HttpServer.listen (dart:io/http_impl.dart:2278) TechEmpower#6 _startServer.<anonymous closure> (file:///server.dart:88:12) TechEmpower#7 _RootZone.runUnary (dart:async/zone.dart:1371) TechEmpower#8 _FutureListener.handleValue (dart:async/future_impl.dart:129) TechEmpower#9 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:636) TechEmpower#10 _Future._propagateToListeners (dart:async/future_impl.dart:665) TechEmpower#11 _Future._completeWithValue (dart:async/future_impl.dart:478) TechEmpower#12 Future.wait.<anonymous closure> (dart:async/future.dart:362) TechEmpower#13 _RootZone.runUnary (dart:async/zone.dart:1371) TechEmpower#14 _FutureListener.handleValue (dart:async/future_impl.dart:129) TechEmpower#15 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:636) TechEmpower#16 _Future._propagateToListeners (dart:async/future_impl.dart:665) TechEmpower#17 _Future._completeWithValue (dart:async/future_impl.dart:478) TechEmpower#18 Future.wait.<anonymous closure> (dart:async/future.dart:362) TechEmpower#19 _RootZone.runUnary (dart:async/zone.dart:1371) TechEmpower#20 _FutureListener.handleValue (dart:async/future_impl.dart:129) TechEmpower#21 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:636) TechEmpower#22 _Future._propagateToListeners (dart:async/future_impl.dart:665) TechEmpower#23 _Future._completeWithValue (dart:async/future_impl.dart:478) TechEmpower#24 _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:510) TechEmpower#25 _microtaskLoop (dart:async/schedule_microtask.dart:41) TechEmpower#26 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50) TechEmpower#27 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:99) TechEmpower#28 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:152)
Here's an example of the error output from before this change: Unhandled exception: Bad state: Stream was already listened to #0 _RawServerSocket.listen (dart:io-patch/socket_patch.dart:1106) #1 new _ForwardingStreamSubscription (dart:async/stream_pipe.dart:123) #2 _ForwardingStream._createSubscription (dart:async/stream_pipe.dart:91) #3 _ForwardingStream.listen (dart:async/stream_pipe.dart:86) #4 _ServerSocket.listen (dart:io-patch/socket_patch.dart:1351) #5 _HttpServer.listen (dart:io/http_impl.dart:2278) #6 _startServer.<anonymous closure> (file:///server.dart:88:12) #7 _RootZone.runUnary (dart:async/zone.dart:1371) #8 _FutureListener.handleValue (dart:async/future_impl.dart:129) #9 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:636) #10 _Future._propagateToListeners (dart:async/future_impl.dart:665) #11 _Future._completeWithValue (dart:async/future_impl.dart:478) #12 Future.wait.<anonymous closure> (dart:async/future.dart:362) #13 _RootZone.runUnary (dart:async/zone.dart:1371) #14 _FutureListener.handleValue (dart:async/future_impl.dart:129) #15 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:636) #16 _Future._propagateToListeners (dart:async/future_impl.dart:665) #17 _Future._completeWithValue (dart:async/future_impl.dart:478) #18 Future.wait.<anonymous closure> (dart:async/future.dart:362) #19 _RootZone.runUnary (dart:async/zone.dart:1371) #20 _FutureListener.handleValue (dart:async/future_impl.dart:129) #21 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:636) #22 _Future._propagateToListeners (dart:async/future_impl.dart:665) #23 _Future._completeWithValue (dart:async/future_impl.dart:478) #24 _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:510) #25 _microtaskLoop (dart:async/schedule_microtask.dart:41) #26 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50) #27 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:99) #28 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:152)
…nt modules and adding new benchmark portions for the Expesed Vert.x SQL Client along with R2DBC and Exposed R2DBC as comparisons (#10560) * Bump all dependencies and toolchains to the latest * Migrate to Vert.x 5 APIs and bump Kotlin to 2.3.0-RC2 to support Java 25 * Update catching the "connection" reset exceptions * Try setting `date` with kotlinx-datetime but it doesn't work as expected Got `java.lang.IllegalStateException: Field offsetHours is not set`. * Remove the kotlinx-datetime dependency and update the comment See commit 9cf28f1 for a failed attempt to try using kotlinx-datetime. * Get setting `date` with `kotlinx-datetime` to work ref: huanshankeji#1 * Review and port some of the changes in `FrameworkBenchmarks/frameworks/Java/vertx/` from commit 057c25b to commit 1838aa5, and fix some typos Some changes are not ported. There is about 5% performance improvement in the JSON test as tested on my device. * Increase the io_uring completion queue size to resolve warnings and improve the plaintext test performance ``` io.netty.channel.uring.IoUringIoHandler processCompletionsAndHandleOverflow vertx: WARNING: CompletionQueue overflow detected, consider increasing size: 4096 ``` This is still one warning when the value is set to 8192 as tested on my device, instead of many for the default 4096. * Benchmark Approach 1 and Approach 3 in `jsonResponseCoHandler` again and fix capitalization BTW The "Requests/sec" result of Approach 1 is only 40% of Approach 3 as tested on my device. * Remove an outdated comment as found by Gemini Code Assist * Use the "connection reset" error code from Netty instead of hard-coding it and also catch Java NIO `SocketException` for developing on other OSs such as macOS and Windows Tested with the `tfb` command on both macOS and Linux. * Run `./tfb --new` and update manually * Copy files from `frameworks/Kotlin/vertx-web-kotlinx`, merge, and update * Fix some errors and keep things updated in benchmark_config.json and README.md * Add the exposed-vertx-sql-client dependencies * Initially adapt the benchmark with some code copied from `frameworks/Kotlin/ktor/ktor-exposed` The following exception occurs when running the benchmark: ``` org.postgresql.util.PSQLException: Transaction isolation level 0 not supported. ``` * Fix `org.postgresql.util.PSQLException: Transaction isolation level 0 not supported.` with huanshankeji/exposed-vertx-sql-client@bb69856 published to Maven local, and fix some remaining issues in the benchmark code debugging with `tfb` Here are some results with max parameters (threads, connections, number of queries) of interest as benchmarked on my device. The "single query" result is only 65% of that of `vertx-web-kotlinx`, which is not ideal. The "updates" result exceeds that of `vertx-web-kotlinx` by about 10%-15%, which needs to be looked into further. Setting `validateBatch = false` does not make noticeable difference. * Use lower case table names PostgreSQL table names are case-insensitive. * Port commit e487900 of `vertx-web-kotlinx` here, using one Kotlin `XorWowRandom` `Random` instance every `Verticle * Rename the project directory to `vertx-web-kotlinx-exposed-vertx-sql-client` to more explicitly compare with the `vertx-web-kotlinx` portion * Update the project configuration files correspondingly * Remove the `hasDb` command-line argument Tests without the database are not needed here in this portion. * Update the benchmark name in code * Copy the optimized kotlinx-serialization `Json` configuration from the `ktor` portion * Merge the `vertx-web-kotlinx-exposed-vertx-sql-client` portion project into the `vertx-web-kotlinx` portion and update the project structure Changes: * Split the project into multiple modules/subprojects. * Update the project structure following a new project generated with `gradle init`. * Partially adapt to Gradle version catalog (putting only the versions). * Bump Kotlin to 2.3.0 which is just released BTW. Common code is not extracted yet. * Put the serialization plugin in the version catalog too * Extract common code and refactor for better abstraction Bump the Vert.x version to 5.0.6 BTW. * Inline `initDbResources` * Rename project ":with-db:common" to ":with-db:with-db-common" to resolve jar name conflicts * Fix Gradle errors of projects without directories ``` Configuring project '...' without an existing directory is not allowed. The configured projectDirectory '...' does not exist, can't be written to or is not a directory. ``` Add an `r2dbc` module BTW. * Set the main class for the `vertx-web-kotlinx` portion which was forgotten * Apply Kotlin JVM 2.3.0 explicitly in `buildSrc` to resolve the `Kotlin does not yet support 25 JDK target, falling back to Kotlin JVM_24 JVM target` warning * Initially complete the `r2dbc` and `exposed-r2dbc` portions Add a comment for commit effc46a BTW. Update README.md BTW. * Set username and password which was forgotten and extract the common constants * Call `suspendTransaction` in the `exposed-r2dbc` portion * Disable `strictThreadMode` to resolve `java.lang.IllegalStateException: Only the context thread can write a message in the R2DBC portions * Put all the dependencies in `libraries` of the Gradle version catalog First performed by Copilot and updated by me to fix some minor issues, reorder, and adjust the format. * Move the R2DBC `connectionFactory` to the `r2dbc-common` module and share it for the `exposed` module as well, and set `reactor.bufferSize.small` to try resolving `io.r2dbc.postgresql.client.ReactorNettyClient$RequestQueueException: [08006] Cannot exchange messages because the request queue limit is exceeded` * Set the explicit dialect which is necessary * Fix `java.lang.IllegalStateException: Bound parameter count does not match parameters in SQL statement` in the `r2dbc` `updates` test with Copilot * Fix a bug where `awaitLast` should be called instead of `awaitSingle` * Fix `io.r2dbc.postgresql.client.ReactorNettyClient$RequestQueueException: [08006] Cannot exchange messages because the request queue limit is exceeded` alternatively by not using pipelining * Update the comments * Remove the TODO as it's tried in commit 4602312f7c9e6575a5c3dfb75cb78e226aa4c9a1 * Move a comment's location * Fix the `update` test timeout issue * Close the R2DBC connection This doesn't fix the `r2dbc` `update` failure though. * Fix some warnings * Use an R2DBC connection pool each `Verticle` in `exposed-r2dbc`, and run the test several times to determine the optimal pool size * Share one transaction for all the queries in a request in `exposed-r2dbc`, refactoring `CommonWithDbVerticle` to support optional transactions * Fix format * Benchmark the `vertx-web-kotlinx` `json` test and `vertx-web-kotlinx-postgresql` `db` test several times with different (original and reverted) code before and after abstraction (introducing abstract classes and interfaces), Kotlin and Vert.x versions, and kotlinx-serialization `Json` configurations to investigate possible performance regressions Results show no noticeable performance regressions. I first noticed some in the `db` test but they appear to be just measurement errors. The optimized `Json` improves the `json` test throughput with max parameters by about 5% as tested on my device but there is no noticeable difference in the `db` test. * Use the newly released version 0.7.0 of `exposed-vertx-sql-client` * Temporarily remove 'update_url' from benchmark_config.json whose corresponding test fails See #10432 which is not fixed yet. * Revert "Temporarily remove 'update_url' from benchmark_config.json whose corresponding test fails" This reverts commit 3f1e03e. The wrong `update_url` was removed. * Fix vertx-web-kotlinx-r2dbc-postgresql update test by consuming batch Result publishers (#7) * Initial plan * Fix updateSortedWorlds to properly consume R2DBC batch update results Co-authored-by: ShreckYe <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: ShreckYe <[email protected]> * Update endpoint URLs to match the code as suggested by Copilot * Comment out `mavenLocal()` * Update an outdated relative path as suggested by Copilot * Fix the `orm` field of `r2dbc-postgresql` which was copied here Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: ShreckYe <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
No description provided.