ByteCode.News
Submit RSS Atom Sign in

Back to the channels

#java

  1. * metalmaniac joined #java
  2. * Fiji joined #java
  3. * troydm joined #java
  4. * Fiji_ joined #java
  5. * bdkl joined #java
  6. * xeno joined #java
  7. * justyb11 joined #java
  8. * fgarcia joined #java
  9. * lockdown joined #java
  10. * rvalue- joined #java
  11. * MrHAPPY joined #java
  12. * Deneb joined #java
  13. * ptomli joined #java
  14. * stfstfm joined #java
  15. * rvalue- joined #java
  16. * jonp` joined #java
  17. * rvalue joined #java
  18. * fstd joined #java
  19. * Everything joined #java
  20. * Everything joined #java
  21. Bombe I don’t think that even compiles, which makes it doubly worthless!
  22. jreicher It's art, apparently. Heathen.
  23. Bombe Can’t argue with that, I guess.
  24. * ptomli2 joined #java
  25. * Everything joined #java
  26. * Everything joined #java
  27. * JazzJackalope joined #java
  28. * enoq joined #java
  29. 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
  30. 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?
  31. Para Use the cache, Luke :)
  32. 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
  33. 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.
  34. Para And definitely do things cache first, adding them as an afterthought is not fun.
  35. 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?
  36. enoq ernimril, I don't have data yet for concurrent users; customer is very performance sensitive and has set ms response time goals
  37. Para Then remove Hibernate entirely.
  38. enoq technically you could ofc also spin up multiple servlet apps
  39. ernimril "ms response time goals"? as in 999 ms or as in 1 ms?
  40. enoq below 100 IIRC
  41. 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.
  42. ernimril enoq, on average or worst case?
  43. Para Or is that 99%?
  44. enoq ernimril, great question, I think it's probably an average but would have to look into it
  45. 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... :-)
  46. 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... :)
  47. 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)
  48. enoq right, the thing that sorta gives me headaches is that we potentially have a nextjs server app in front as well
  49. enoq we're gonna host in the same data center though (Azure) so I hope latencies will be low
  50. 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
  51. enoq sure
  52. 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
  53. 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.
  54. 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)
  55. enoq classic case of premature optimization?
  56. ernimril measure, then fix, but try to plan well so you get good algorithmic complexity
  57. * jbosmans joined #java
  58. * MikeBux joined #java
  59. jreicher Measuring is really hard for stuff like this, which is why the method of measurement needs to be planned and instrumented.
  60. * hwpplayer1 joined #java
  61. 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
  62. enoq I mean yeah, virtual threads work really well
  63. deebo as long as you're on jdk24+ to avoid pinning issues, there's really no need to do rx and get cancer
  64. enoq just more concernced about parallel requests
  65. enoq also looking into Kotlin coroutines btw
  66. deebo does't really matter, we just mostly do CompletableFuture.supplyAsync(() -> api.call(), virtualThreadsExecutor), but on spring @async would work just as fine
  67. deebo one service is graphql which does one root query, then massive amounts of parallel queries to fill the graph
  68. 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
  69. dreamreal enoq: virtual threads in spring are very good
  70. dreamreal what problems are you actually having
  71. enoq dreamreal, I don't want reactive but I want to make use of parallel http requests/db calls
  72. enoq my impression was that I need to wait for structured concurrency in the jdk first to get that
  73. enoq but looks like spring has @Async
  74. dreamreal you don't need any of it
  75. dreamreal just write ordinary blocking servlets
  76. dreamreal then turn on virtual threads
  77. dreamreal (requires java 21 or later)
  78. 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
  79. dreamreal and your code complexity will drop like a stone.
  80. dreamreal Easier to debug, easier to reason about, easier to read, easier to do everything.
  81. * sponkz joined #java
  82. enoq right, I just need an escape hatch if I ever need to optimize that use case
  83. dreamreal Are you working for netflix, amazon, anyone like that?
  84. 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
  85. 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
  86. enoq or at least have good arguments set aside if it comes up
  87. enoq software architecture itself is a tricky topic to navigate since there's so much dogma floating around
  88. 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.
  89. enoq correct, try to argue that against a competitor who throws performant async style programming requests at you ;D
  90. 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."
  91. enoq + nodejs
  92. dreamreal enoq: competitor... internally or externally? nodejs' async programming isn't exactly a panacea, plus it's nodejs
  93. enoq external; exactly, nodejs is way slower, still need a way to quickly play the bullshit bingo
  94. dreamreal what the heck? Get an SLA, meet it. Your external competitor is going to be dust.
  95. dreamreal Turn on virtual threads, boom, you have "industry standard scalability" with commodity programmers.
  96. * Betal joined #java
  97. 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
  98. enoq fully agree; as mentioned, I just need a back up argument, but @Async looks like it will provide that
  99. dreamreal Why
  100. dreamreal spring.threads.virtual.enabled=true # provides that with no source change
  101. 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.
  102. deebo in my experience you get the most out of it as long as you have http and db connection pooling
  103. enoq julemand101, I don't except any number crunching; almost everything will be I/O, be it REST calls or db queries
  104. dreamreal enoq: then smart caching of consistent resources is going to be your next lever
  105. dreamreal this is not rocket surgery, it's barely brain salad
  106. 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
  107. deebo but for high availability we have "excess" capacity that's just idle :) virtual threads are basically magic in these types of services
  108. 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?
  109. enoq julemand101, no rewrite happening
  110. julemand101 Ah so there are no backend at the moment?
  111. enoq customer wants to transition to a cloud provider which the current backend does not support
  112. dreamreal okay, now I'm concerned.
  113. 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
  114. Drixtan ke Java virtual threads or Golang green-threads for example. This approach does not color your code, so it eliminate duplication of code.
  115. dreamreal enoq: ... you need to define scope and roles here
  116. 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.
  117. enoq I think we're going off on a huge tangent here based off a misunderstanding
  118. 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
  119. dreamreal enoq: yes, agreed.
  120. 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.
  121. dreamreal BUT I have NO insight into the app or the SLA.
  122. 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.
  123. dreamreal the only person with skin in the game here is YOU.
  124. enoq right, I fully agree with that
  125. 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.
  126. 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.
  127. enoq how do you handle slow parallel requests to different REST endpoints then?
  128. dreamreal depends on what "slow" means! Virtual thread dispatch means that each blocking call blocks *only its virtual thread*
  129. 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?
  130. 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
  131. dreamreal node and python treat *threads* as scarce resources, so async makes sense
  132. dreamreal enoq: why? Why are they executing sequentially?
  133. enoq that's my question: what's the recommended way to parallelize this using virtual threads
  134. dreamreal turn on virtual threads.
  135. dreamreal That's the recommended way to parallelize that.
  136. dreamreal that's all.
  137. dreamreal ... that is, in spring.
  138. Para Yeah, it took over a decade to materialize as a feature because they wanted it to be a turnkey thing.
  139. Para Flip the switch and move on :)
  140. enoq the 100ms requests are launched inside spring, not the frontend
  141. dreamreal enoq: right.
  142. dreamreal enoq: dude, I've done this. For a long time.
  143. enoq so just turning on virtual threads will not solve this, you need to fork off threads or similar stuff
  144. dreamreal why?
  145. dreamreal Why do YOU need to fork off threads, if the framework does it for you?
  146. enoq oh, I think I might have misunderstood how they work
  147. Drixtan enoq: spring 3.2+ the request handler is a virtual thread, imagine you have an "infinite" amount of "threads"
  148. 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?
  149. enoq is it intelligent enough to realize that both method calls have no dependency on each other and can execute in parallel?
  150. dreamreal yes, in fact you have to work to get it to NOT run in parallel
  151. Para ...lock pool
  152. dreamreal we've been TRYING to give you good advice here
  153. enoq I see, I was under the impression that it suspended execution immediately once it hit the first I/O call
  154. dreamreal oh god no
  155. dreamreal that'd be bonkers mad
  156. Para I/O is not magical, despite especially functional programming folks wanting to make it seem like it :P
  157. dreamreal that's why I said that you get most of what you want with the single flag
  158. dreamreal maybe not all of it: if you're netflix or amazon or a very few others, well, you want to manage concurrency differentl
  159. enoq thank you, that cleared things up massively :)
  160. enoq and tbh makes it even more impressive
  161. Para I bet someone's been crazy enough to make lmax disruptor to manage tasks in Spring somewhere at some point but...don't :)
  162. 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.
  163. dreamreal Para: that's a bet you'd win, plus EAI is a thing
  164. * ChaiTRex joined #java
  165. deebo seeing one reactive stack trace should put you off the concept entirely
  166. 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
  167. dreamreal and as far as annoyances go, that one's pretty mild.
  168. dreamreal at least, in my experience.
  169. 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
  170. jreicher Para: I/O might not be magical, but it doesn't exist within any language.
  171. jreicher That's not specific to functional programming.
  172. Para jreicher: FP people are insufferable about I/O at times, is my point :)
  173. jreicher I think they're just defensive. They don't want to admit they're bad at explaining their preferred paradigm.
  174. dreamreal or that their holy writ has giant chasms that undercut their magic claims
  175. dreamreal FP is incredibly useful and I wish they wouldn't keep trying to sell people on it
  176. dreamreal just back up your shit, that's enough
  177. jreicher I believe FP is as good as some people say, but there are other people who make false claims about it
  178. * metalmaniac joined #java
  179. dreamreal FP's great
  180. deebo i'm just a highly paid data plumber (actual plumbers might make more!), the more functional and immutable stuff is the easier :)
  181. cheeser if you're strong enough
  182. dreamreal deebo: sure, like I said, FP's great
  183. dreamreal it's just not MAGIC
  184. dreamreal magic's not real, just like unicorns aren't real, wendigos aren't real, birds aren't real
  185. cheeser finland isn't real
  186. 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
  187. * fgarcia joined #java
  188. jreicher deebo: what "doesn't work" about the paradigm for you? (I have a vested interested in this question)
  189. Para deebo: Time to descend another level and start using nixos, then.
  190. Para I'm self-projecting, I have a used laptop arriving soon which I'll be installing nixos onto.
  191. * hwpplayer1 joined #java
  192. * Anaphaxeton joined #java
  193. * jamezp joined #java
  194. * marcel joined #java
  195. * five618480339176 joined #java
  196. * stfstfm joined #java
  197. * acidsys joined #java
  198. * kathadris joined #java
  199. * jwisbell35 joined #java
  200. deebo jreicher: i just can't read it, with haskells custom operators it's even worse
  201. 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?
  202. Para Mock the call, probably.
  203. dreamreal for THAT, mock the call, although I personally prefer spinning up a fake server that returns predetermined data
  204. enoq any reasons why you wouldn't use test data from the live system?
  205. Para Legal.
  206. dreamreal ^^^
  207. dreamreal you don't want to rely on the live system
  208. enoq thank you
  209. * Odyss3us joined #java
  210. * henbruas joined #java
  211. 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
  212. * hwpplayer1 joined #java
  213. * mindCrime joined #java
  214. * Anaphaxeton joined #java
  215. * ChaiTRex joined #java
  216. * JazzJackalope joined #java
  217. * Anaphaxaway joined #java
  218. * leppard joined #java
  219. * stfstfm joined #java
  220. * monkeyPlus joined #java
  221. * tmm88 joined #java
  222. jreicher deebo: interesting. Is it any better when do notation is used?
  223. * mindCrime joined #java
  224. * llanhmock joined #java
  225. * Anaphaxaway joined #java
  226. * Pixi` joined #java
  227. * iwtga joined #java
  228. * internecine joined #java
  229. * marcel joined #java