TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Leveraging Rust in our Java database

151 pointsby jerrinotover 1 year ago

9 comments

amunra__over 1 year ago
I&#x27;m the author of the blog post.<p>The focus of the article really is about JNI in Rust.<p>I see most questions are about &quot;Why did you not use X language instead?&quot;, so let me try and address this.<p>To answer the &quot;Why not just Rust&quot;, I should first mention that Rust was still in its early days (before 1.0), and it was a risky bet to choose an emerging language.<p>The project was started by Vlad (our CEO) who had a background writing high performance Java in the trading space. The Zero-GC techniques - whilst uncommon in open source software - are mature and a staple of writing high performance code in the financial industry. The product evolved organically, feature after feature.<p>I personally joined the team from a C and C++ background, having previously moved from a project that suffered from minute-long compile times from single .cpp files due to template overuse. Whilst I do miss how expressive high-level C++ can be, Java has really good tooling support.<p>When writing systems-style software most of what matters in terms of performance is how we call system calls, manage memory and debug and profile. This is an area where Java really shines. Don&#x27;t get me wrong: In the absolute sense I think C++ tools tend to be better (Linux Perf is awesome!), but Java tooling is _there_. IntelliJ makes it trivially easy to run a test under the debugger reliably and consistently. It&#x27;s equally easy to run a profiler and to get code coverage. The same tools work across all platforms too, might I add. It&#x27;s not necessarily better, but it&#x27;s easier. Turns out that while a little quaint, using Java turned out to be a pretty good choice in my opinion in practice.<p>Times have moved on. The Rust community really cares about tooling, and it&#x27;s one of the reasons why we&#x27;ve picked it over expanding our existing C++ codebase: We just want to get stuff done and have enough time left in our dev cycle to properly debug and profile our code.
评论 #37583944 未加载
评论 #37585514 未加载
评论 #37588018 未加载
评论 #37584061 未加载
评论 #37584021 未加载
pronover 1 year ago
&gt; We seldom use the new keyword and objects are designed to be pooled and reused.<p>Just note that depending on the selection of the GC, this kind of usage may make the GC work <i>more</i> than when allocating new objects, not less. In particular, with the newer GCs -- G1 and ZGC -- mutating existing objects may be more costly than allocating new ones depending on circumstances. In general, the new GCs are optimised to work the least and give the best performance when the allocation rate is neither too high nor too low; the new GCs also reuse memory better than object pools. Reusing objects also precludes scalarization optimisations, i.e. not every `new Foo` actually results in a heap allocation, and can be optimised to work directly in registers.<p>So while on very old JVMs (such as Java 8) a &quot;zero allocation&quot; strategy may result in better performance and in &quot;zero GC&quot;, on newer JVMs it may result in worse performance and <i>more</i> GC work (in fact, it will almost surely not yield zero GC). While it depends on many variables, I would advise against a zero allocation strategy on newer JVMs as the default path toward better performance or even better latency. It&#x27;s an approach that seems to be very strongly coupled to the way the JVM was designed over a decade ago, but a lot has changed since then.<p>Additionally, Java now offers manual memory management and efficient FFI that are significantly better than what JNI offered: <a href="https:&#x2F;&#x2F;openjdk.org&#x2F;jeps&#x2F;442" rel="nofollow noreferrer">https:&#x2F;&#x2F;openjdk.org&#x2F;jeps&#x2F;442</a>
评论 #37585562 未加载
评论 #37586985 未加载
评论 #37585377 未加载
nu11ptrover 1 year ago
I mean no disrespect to the authors, but this seems like an extremely painful way to write an application. How common is it to write Java apps this way? It seems like there must have been a better language choice than trying to work against the GC and rewriting parts of the standard lib? And now adding in Rust via JNI? It just feels very painful to me.
评论 #37583858 未加载
评论 #37583309 未加载
评论 #37583405 未加载
klausercover 1 year ago
Very interesting to see how the Rust-JNI interface gets used in a production environment (e.g., the topic of unifying logging typically doesn&#x27;t come up in &quot;your first Rust-JNI app&quot; tutorials, for instance)<p>I do have one question around the assignment to `static mut CALL_STATE`. Don&#x27;t you need some form of synchronization&#x2F;memory fence&#x2F;memory barrier to make sure that other threads see that assignment?<p>On x86&#x2F;x64 it probably doesn&#x27;t matter (total store order), but other architectures are less lenient.
评论 #37584563 未加载
wmielover 1 year ago
I&#x27;m not sure I understand why they&#x27;re using java if they avoid GC? Doesn&#x27;t sound like the best fit, especially the foreign memory in java isn&#x27;t too pleasant to work with.
评论 #37584000 未加载
评论 #37583754 未加载
评论 #37583530 未加载
评论 #37583464 未加载
评论 #37583396 未加载
评论 #37583290 未加载
exabrialover 1 year ago
I&#x27;ve never heard of QuestDB until this post, but I very much like what you guys are doing.<p>InfluxDB 1.x had a chance to be great: the wrote a time series database that used a SQL-like dialect, they had a really nice alerting platform, they had a really nice visiualization tool. Then they abandoned all of that to jump on the hype train of &quot;Write a new programming language!&quot; which was the hot thing like 5 or 6 hype cycles ago. We&#x27;ve _never_ upgraded to their 2.x product because it literally threw away our investment.<p>I think if you guys get pick up where they departed you&#x27;ll be tremendously successful.
评论 #37585444 未加载
评论 #37587213 未加载
exabrialover 1 year ago
&gt; JNI<p>Have you guys benchmarked FFI in Java 21 (preview, now release) yet? :) Yes I know it&#x27;s super new, but I&#x27;m curious if there is a benefit in terms of:<p>1. performance<p>2. ease of maintenance<p>3. ease of finding production problems
LispSporks22over 1 year ago
I needed to call Rust from Java a few years ago. The approach was build a straightforward .so and call into it via JNA. It seemed way less complicated
评论 #37584674 未加载
crustycoderover 1 year ago
Nowadays there&#x27;s a much better technology than JNI for doing this sort of thing in Java.<p><a href="https:&#x2F;&#x2F;docs.oracle.com&#x2F;en&#x2F;graalvm&#x2F;jdk&#x2F;21&#x2F;docs&#x2F;reference-manual&#x2F;native-image&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;docs.oracle.com&#x2F;en&#x2F;graalvm&#x2F;jdk&#x2F;21&#x2F;docs&#x2F;reference-man...</a>
评论 #37586206 未加载