ByteCode.News
Submit RSS Atom Sign in

Back to the channels

#java

  1. Bombe I don’t think that even compiles, which makes it doubly worthless!
  2. jreicher It's art, apparently. Heathen.
  3. Bombe Can’t argue with that, I guess.
  4. enoq so we're gonna build a backend for frontend application pretty soon; looking at virtual threads, we could use spring servlet APIs and get a lot of performance out for free, but I'm unsure if that's a good idea if most of your application will do I/O and potentially wants to do API requests in parallel
  5. enoq from what I've seen structured concurrency APIs are in preview and I don't really know how easy/well those would integrate into a classic spring boot servlet server; do I want to go with reactive instead?
  6. Para Use the cache, Luke :)
  7. enoq one issue I could see when going reactive is probably hibernate; there's a reactive version available, but I'm unsure how well those work; I'll definitely go for stateless sessions btw
  8. Para FWIW I've found Guava's caches really useful in that. Create a cache loader which has the heavy operation inside it and let requests wait/park until result is fetched by the first caller and value result is cached.
  9. Para And definitely do things cache first, adding them as an afterthought is not fun.
  10. ernimril enoq, how many concurrent users are you planning to have? how long time does each request take? Do you have to care about thread handling?
  11. enoq ernimril, I don't have data yet for concurrent users; customer is very performance sensitive and has set ms response time goals
  12. Para Then remove Hibernate entirely.
  13. enoq technically you could ofc also spin up multiple servlet apps
  14. ernimril "ms response time goals"? as in 999 ms or as in 1 ms?
  15. enoq below 100 IIRC
  16. Para You'll also need proper tracing to detect hotspots, design a multi-layered cache as well. Avoid distributed caches such as memcached, their worst case scenarios/faults will kill you.
  17. ernimril enoq, on average or worst case?
  18. Para Or is that 99%?
  19. enoq ernimril, great question, I think it's probably an average but would have to look into it
  20. ernimril these things matter a lot. if it is average you can do almost anything a 100 ms is a _long_ time for a computer... :-)
  21. Para On tracing, you need to be able to prove _your_ part. If the request takes 60ms to come from client to your backend and that is counted as part of it, you definitely want to be able to say that someone else ate your quota... :)
  22. ernimril now, if you connect to a database over a filtering tunnel and going through another country you may still have problems (yes, this has happened to me)
  23. enoq right, the thing that sorta gives me headaches is that we potentially have a nextjs server app in front as well
  24. enoq we're gonna host in the same data center though (Azure) so I hope latencies will be low
  25. Para I did as an exercise an opentelemetry tracing Spring aspect some time ago, I could share that if you're interested. And I can find it, it's in my pile of experiments :P
  26. enoq sure
  27. enoq the reason why I'm asking is because I think the need for webflux might go away once we've got structured concurrency in java
  28. jreicher enoq: I'm probably saying something Para has already said a different way, but make sure you solve observability for your performance metrics if that's something you care about. Realistic workloads are difficult to reproduce so if you see something weird happening, that'll probably be your only chance to know why it happened.
  29. ernimril enoq, with the loose requirements you have today I would probably just go with whatever seems most easy (spring boot if you know and use that already, but perhaps quarkus)
  30. enoq classic case of premature optimization?
  31. ernimril measure, then fix, but try to plan well so you get good algorithmic complexity
  32. jreicher Measuring is really hard for stuff like this, which is why the method of measurement needs to be planned and instrumented.
  33. deebo enoq: we use spring boot 3 and 4 exclusively with virtual threads in a microservice architecture where everything is just waiting for io most of the time
  34. enoq I mean yeah, virtual threads work really well
  35. deebo as long as you're on jdk24+ to avoid pinning issues, there's really no need to do rx and get cancer
  36. enoq just more concernced about parallel requests
  37. enoq also looking into Kotlin coroutines btw
  38. deebo does't really matter, we just mostly do CompletableFuture.supplyAsync(() -> api.call(), virtualThreadsExecutor), but on spring @async would work just as fine
  39. deebo one service is graphql which does one root query, then massive amounts of parallel queries to fill the graph
  40. deebo we don't really even do caches, except for apis that were not designed to be used like this and for example return all data at once without any filtering
  41. dreamreal enoq: virtual threads in spring are very good
  42. dreamreal what problems are you actually having
  43. enoq dreamreal, I don't want reactive but I want to make use of parallel http requests/db calls
  44. enoq my impression was that I need to wait for structured concurrency in the jdk first to get that
  45. enoq but looks like spring has @Async
  46. dreamreal you don't need any of it
  47. dreamreal just write ordinary blocking servlets
  48. dreamreal then turn on virtual threads
  49. dreamreal (requires java 21 or later)
  50. dreamreal You'll get 95%+ or better of the reactive performance just by doing that, and that remaining percentage affects a remarkably small number of apps
  51. dreamreal and your code complexity will drop like a stone.
  52. dreamreal Easier to debug, easier to reason about, easier to read, easier to do everything.
  53. enoq right, I just need an escape hatch if I ever need to optimize that use case
  54. dreamreal Are you working for netflix, amazon, anyone like that?
  55. dreamreal Is who you're working for expecting to become netflix, amazon, anyone like that? I mean, I know we all plan for it, but even so
  56. enoq no, they are using Magento and other PHP based software right now and migrate off because of performance issues, so it's an important topic to be able to handle that
  57. enoq or at least have good arguments set aside if it comes up
  58. enoq software architecture itself is a tricky topic to navigate since there's so much dogma floating around
  59. dreamreal well. Here's more: YAGNI applies. For 99.999% of apps, including every damn one of mine, virtual threads in spring will provide everything you're looking at reactive programming to give you.
  60. enoq correct, try to argue that against a competitor who throws performant async style programming requests at you ;D
  61. dreamreal The thread mentions caching, and maybe caching can help, too, but that's to reduce certain aspects of the process, and I don't know what you're doing, so I can't point at caching and say "yes, you want that too."
  62. enoq + nodejs
  63. dreamreal enoq: competitor... internally or externally? nodejs' async programming isn't exactly a panacea, plus it's nodejs
  64. enoq external; exactly, nodejs is way slower, still need a way to quickly play the bullshit bingo
  65. dreamreal what the heck? Get an SLA, meet it. Your external competitor is going to be dust.
  66. dreamreal Turn on virtual threads, boom, you have "industry standard scalability" with commodity programmers.
  67. dreamreal You don't get to use the kickiest, hippest new apis, I guess, and you're not at the mercy of structured concurrency Feature O' Th' Day, and you don't get to claim to be one of the thousands of projects underusing reactive programming, I suppose, but personally I don't consider those weaknesses, I'd rather get stuff done
  68. enoq fully agree; as mentioned, I just need a back up argument, but @Async looks like it will provide that
  69. dreamreal Why
  70. dreamreal spring.threads.virtual.enabled=true # provides that with no source change
  71. julemand101 enoq: What is your backend doing that would require CPU cycles? In most applications, the slow part is going to be IO and especially database queries so if the same is the case for you, then changing to Java would not really give much benefits.
  72. deebo in my experience you get the most out of it as long as you have http and db connection pooling
  73. enoq julemand101, I don't except any number crunching; almost everything will be I/O, be it REST calls or db queries
  74. dreamreal enoq: then smart caching of consistent resources is going to be your next lever
  75. dreamreal this is not rocket surgery, it's barely brain salad
  76. deebo we could run our 5+ country multitenant systems main data service on 1vcpu and 2GB mem since it's mostly io with no actual cpu work
  77. deebo but for high availability we have "excess" capacity that's just idle :) virtual threads are basically magic in these types of services
  78. julemand101 enoq: Ok, so it is really the best way to spend your time/money to rewrite your backend into a different language? I mean, it sounds like you don't have a good understanding of where your performance bottlenecks are if you suspect your PHP code when your application are mostly IO bound?
  79. enoq julemand101, no rewrite happening
  80. julemand101 Ah so there are no backend at the moment?
  81. enoq customer wants to transition to a cloud provider which the current backend does not support
  82. dreamreal okay, now I'm concerned.
  83. Drixtan enoq: there are 2 ways of handling the blocking IO problem: green threads and the "async" model (which is a stateful machine behind the scene). The "async" model, which has been popularized by C#, is known to "color" your methods with the "async" keyword (see typescript, rust, C#...). This put the code in a situation that you often have to duplicate the code: one async, one sync - where the "function coloring". The second method to manage the blocking IO is li
  84. Drixtan ke Java virtual threads or Golang green-threads for example. This approach does not color your code, so it eliminate duplication of code.
  85. dreamreal enoq: ... you need to define scope and roles here
  86. Drixtan enoq: as per webflux vs virtual threads, webflux was created before the virtual threads to manage this IO blocking problem, so enjoy the new pattern and use the virtual threads.
  87. enoq I think we're going off on a huge tangent here based off a misunderstanding
  88. dreamreal enoq: relying on #java for architecture is ... not the worst advice, I guess, in that we CAN know what we're talking about, but it's certainly still terrible advice
  89. dreamreal enoq: yes, agreed.
  90. dreamreal enoq: everything you've said looks TO ME like you have a spring boot app to write, and you want it to scale horizontally as well as vertically, which is pretty easy - and the easiest performance spice in spring is to write simple code with simple services (a traditional architecture) with virtual threads turned on.
  91. dreamreal BUT I have NO insight into the app or the SLA.
  92. dreamreal that *approach*, plus caching resources that are expensive to retrieve but are generally constant otherwise, catches *a ton* of response time issues. But I don't know the problem space being talked about, so ANY advice has to be taken with a lot of salt and an eye to how much you've paid for it.
  93. dreamreal the only person with skin in the game here is YOU.
  94. enoq right, I fully agree with that
  95. Drixtan I think the real question was: are you safe going with Java? I think you get the answer: yes you are - performance won't be an issue, you always have a good way to optimize, you are not painting yourself in a corner.
  96. dreamreal enoq: @Async does not help - it creates an analog to a pattern you DO NOT NEED. You can use it, but doing so is mostly doing node-like things in Java, as opposed to java-like things in java. Do java-like things in java.
  97. enoq how do you handle slow parallel requests to different REST endpoints then?
  98. dreamreal depends on what "slow" means! Virtual thread dispatch means that each blocking call blocks *only its virtual thread*
  99. dreamreal like, okay, thread-1927 is taking 4ms to run this blocking call, oh no, while thread-1938 executes the same blocking call in ANOTHER thread, where's the competition for scarce resources?
  100. enoq let's imagine you need up to date data from endpoint a and b and both take 100ms to complete; if you write it naively using virtual threads, you'll end up with 200ms
  101. dreamreal node and python treat *threads* as scarce resources, so async makes sense
  102. dreamreal enoq: why? Why are they executing sequentially?
  103. enoq that's my question: what's the recommended way to parallelize this using virtual threads
  104. dreamreal turn on virtual threads.
  105. dreamreal That's the recommended way to parallelize that.
  106. dreamreal that's all.
  107. dreamreal ... that is, in spring.
  108. Para Yeah, it took over a decade to materialize as a feature because they wanted it to be a turnkey thing.
  109. Para Flip the switch and move on :)
  110. enoq the 100ms requests are launched inside spring, not the frontend
  111. dreamreal enoq: right.
  112. dreamreal enoq: dude, I've done this. For a long time.
  113. enoq so just turning on virtual threads will not solve this, you need to fork off threads or similar stuff
  114. dreamreal why?
  115. dreamreal Why do YOU need to fork off threads, if the framework does it for you?
  116. enoq oh, I think I might have misunderstood how they work
  117. Drixtan enoq: spring 3.2+ the request handler is a virtual thread, imagine you have an "infinite" amount of "threads"
  118. dreamreal I mean, with virtual threads turned on in spring, requests a and b will both spin up a thread without you doing anything, and they'll both run parallel; is the "up to date data" the blocking point? Can IT handle only one request at a time?
  119. enoq is it intelligent enough to realize that both method calls have no dependency on each other and can execute in parallel?
  120. dreamreal yes, in fact you have to work to get it to NOT run in parallel
  121. Para ...lock pool
  122. dreamreal we've been TRYING to give you good advice here
  123. enoq I see, I was under the impression that it suspended execution immediately once it hit the first I/O call
  124. dreamreal oh god no
  125. dreamreal that'd be bonkers mad
  126. Para I/O is not magical, despite especially functional programming folks wanting to make it seem like it :P
  127. dreamreal that's why I said that you get most of what you want with the single flag
  128. dreamreal maybe not all of it: if you're netflix or amazon or a very few others, well, you want to manage concurrency differentl
  129. enoq thank you, that cleared things up massively :)
  130. enoq and tbh makes it even more impressive
  131. Para I bet someone's been crazy enough to make lmax disruptor to manage tasks in Spring somewhere at some point but...don't :)
  132. dreamreal one of my clients was saying "oh nooo what if we have to arrrgh" and I told them that if we could measure against their SLA and we could saturate within 10% of what the actually expected I'd not only eat my hat but I'd buy the hat to eat it AND we'd go reactive. Didn't happen. At all.
  133. dreamreal Para: that's a bet you'd win, plus EAI is a thing
  134. deebo seeing one reactive stack trace should put you off the concept entirely
  135. deebo only annoyance with virtual threads i've run into, is that at least with sampling tracing in yourkit, you don't get proper grouping of samples, due to the way it's actually run on a few platform threads you get weirdly disconnected results
  136. dreamreal and as far as annoyances go, that one's pretty mild.
  137. dreamreal at least, in my experience.
  138. deepy only annoyance I got with virtual threads is that they worked so well that I forgot my app was running on a slow single vCPU in a constrained environment and then it very unexpectedly crashed under load
  139. jreicher Para: I/O might not be magical, but it doesn't exist within any language.
  140. jreicher That's not specific to functional programming.
  141. Para jreicher: FP people are insufferable about I/O at times, is my point :)
  142. jreicher I think they're just defensive. They don't want to admit they're bad at explaining their preferred paradigm.
  143. dreamreal or that their holy writ has giant chasms that undercut their magic claims
  144. dreamreal FP is incredibly useful and I wish they wouldn't keep trying to sell people on it
  145. dreamreal just back up your shit, that's enough
  146. jreicher I believe FP is as good as some people say, but there are other people who make false claims about it
  147. dreamreal FP's great
  148. deebo i'm just a highly paid data plumber (actual plumbers might make more!), the more functional and immutable stuff is the easier :)
  149. cheeser if you're strong enough
  150. dreamreal deebo: sure, like I said, FP's great
  151. dreamreal it's just not MAGIC
  152. dreamreal magic's not real, just like unicorns aren't real, wendigos aren't real, birds aren't real
  153. cheeser finland isn't real
  154. deebo yep, the full paradigm just doesn't work for me, i've used xmonad (haskell based window manager) for like 15 years or something, and i still have no clue how my configuration works, just glad it does
  155. jreicher deebo: what "doesn't work" about the paradigm for you? (I have a vested interested in this question)
  156. Para deebo: Time to descend another level and start using nixos, then.
  157. Para I'm self-projecting, I have a used laptop arriving soon which I'll be installing nixos onto.
  158. deebo jreicher: i just can't read it, with haskells custom operators it's even worse
  159. enoq let's say your app calls a couple of REST APIs that you don't control (but you can add test data); what's your preferred way to test that? spin up a mock rest server? mock the http call? add test data to said REST API?
  160. Para Mock the call, probably.
  161. dreamreal for THAT, mock the call, although I personally prefer spinning up a fake server that returns predetermined data
  162. enoq any reasons why you wouldn't use test data from the live system?
  163. Para Legal.
  164. dreamreal ^^^
  165. dreamreal you don't want to rely on the live system
  166. enoq thank you
  167. sbalmos the most advanced company I worked at for a year contractually had a mostly-automated weekly system that took a snapshot of prod on Saturday nights overnight and sanitized as much as it could into normative names etc
  168. jreicher deebo: interesting. Is it any better when do notation is used?