ByteCode.News
Submit RSS Atom Sign in

Back to the channels

#java

  1. * yaboishady2 joined #java
  2. * OmniRadix698 joined #java
  3. * Fiji_ joined #java
  4. * Bharton joined #java
  5. * lockdown joined #java
  6. * LtHummus joined #java
  7. * Bharton joined #java
  8. * Bharton joined #java
  9. * Bharton joined #java
  10. * llanhmock joined #java
  11. * t3ch joined #java
  12. * stfstfm joined #java
  13. * hwpplayer1 joined #java
  14. * julemand101 joined #java
  15. * gurrkin joined #java
  16. * Cae2 joined #java
  17. * gurrkin joined #java
  18. * jreicher joined #java
  19. * MikeBux joined #java
  20. * Anaphaxeton joined #java
  21. * MikeBux joined #java
  22. * stewi joined #java
  23. * dob1 joined #java
  24. * jwisbell35 joined #java
  25. * mwnaylor left #java (ERC 5.6.0.30.1 (IRC client for GNU Emacs 30.2))
  26. * johnjay joined #java
  27. * Betal joined #java
  28. * Anaphaxaway joined #java
  29. * GreenResponse joined #java
  30. * metalmaniac joined #java
  31. * jbosmans joined #java
  32. * jamezp joined #java
  33. * hwpplayer1 joined #java
  34. * RootSipher joined #java
  35. * RootSipher left #java (WeeChat 4.9.2)
  36. * enoq joined #java
  37. enoq so I asked about virtual threads (spring) and parallel http requests a couple days ago; turns out by default it's not parallelized (which is what I expected) https://dpaste.com/EXBWBMSAN
  38. enoq when I curl the endpoint, it waits for 20s
  39. enoq what's the recommended way to deal with that? wrap in CompletableFuture.supplyAsync?
  40. enoq (not 100% sure if that approach loses ThreadLocal context)
  41. enoq there's also @Async btw
  42. Para huh, my firewall says dpaste is a dangerous website
  43. enoq ~pastebin list options
  44. javabot enoq, what does that even *mean*?
  45. enoq ~pastebin
  46. javabot Please paste your code and any errors online. For runnable classes, try https://ideone.com/ . For general code and errors, use https://gist.github.com or https://dpaste.org/
  47. nevet Discover gists
  48. enoq dpaste.org is down
  49. enoq https://gist.github.com/BernhardPosselt/a5638b26987519fdb60b2fdd414f5443
  50. nevet ProductController.kt
  51. Para So, it does exactly what it should?
  52. enoq right, I think we had another misunderstanding back then
  53. enoq virtual threads don't parallelize IO in the same thread
  54. Para I mean... you've literally written "wait 10 seconds, then wait 10 seconds" :)
  55. enoq since I'll be aggregating a lot of different rest endpoints, this makes me wonder if I should go reactive and maybe Kotlin coroutines
  56. Para That sounds like quite a leap to conclusion. You've written synchronous code, that will not magically turn into asynchronous.
  57. enoq spring.threads.virtual.enabled=true btw
  58. enoq so it will spin off a virtual thread per request
  59. * Cae2 joined #java
  60. enoq so it should be async, just not parallel
  61. Para You're solving the wrong problem. You need to change your programming pattern if you want async/parallel execution.
  62. enoq right, so this is how I understand it you could do it using servlet tech https://gist.github.com/BernhardPosselt/a5638b26987519fdb60b2fdd414f5443
  63. nevet ProductController.kt
  64. enoq basically use CompletableFuture.supplyAsync
  65. enoq just not 100% sure if this makes sense
  66. Para I don't see how "servlet tech" relates to this at all.
  67. Para But yeah, that's what futures are for.
  68. enoq servlet as in: not reactive style
  69. * MikeBux joined #java
  70. dreamreal enoq: did you turn on virtual threads, and you're seeing *subsequent* invocation?
  71. enoq I did turn it on, yes
  72. enoq Thread.currentThread().isVirtual() is true
  73. enoq and they're happening one after another
  74. dreamreal okay, so let me make sure what's being described: you have AN ENDPOINT, and you're calling it twice, AND it's executing sequentially such that a 10s call is taking 2(10)s, not 10s twice
  75. dreamreal you would expect *some* deviation (the time between the "two calls" being started plus a slight deviation for wire transfer time) but those would be pretty small
  76. * jonp` joined #java
  77. enoq I tried to simulate 2 REST endpoints that each take 10s to respond; I want both endpoints to be called in parallel to reduce it from 20s to 10s; later on I'll need to aggregate data from various different services
  78. enoq if I used Thread.sleep() wrong, let me know
  79. dreamreal enoq: You shouldn't see sequential behavior from those servlets *even without* virtual threads
  80. dreamreal something else is going on
  81. enoq I'm calling the /testwait endpoint btw
  82. enoq from my understanding, Thread.sleep in a virtual thread should suspend, correct?
  83. dreamreal should suspend THAT THREAD, yes
  84. dreamreal but even without virtual threads you shouldn't be seeing one-after-the-other execution
  85. dreamreal OH
  86. dreamreal testwait() is what's blocking, yeah?
  87. enoq yes
  88. dreamreal those ARE sequential for that thread
  89. dreamreal you're not executing two calls at the same time
  90. enoq right, that's what I was trying to communicate, we probably talked by each other
  91. dreamreal no worries, I'm in a meeting and attention is spread
  92. dreamreal so this behavior is *correct* for that code
  93. enoq I don't care too much about being able to serve 100k requests at once, I'm more interested in cutting down on sequential async calls
  94. dreamreal you run one, then you run the other: 10s twice. That's correct and expected.
  95. dreamreal You're not running those calls at the same time.
  96. dreamreal Your *code* doesn't run them at the same time.
  97. dreamreal create a list of completion results, then resolve them.
  98. enoq right, so would you still stick with servlet if that was the main thing your application did and sprinkle in CompletableFutures?
  99. enoq my guess is that many requests can't be parallel because they'll depend on previous requests, but there might a good chunk that could
  100. dreamreal yeah, you're literally needing to spread out the calls, this is where you actually DO get to multiplex requests
  101. dreamreal It's not DIFFICULT: create a set of requests and start them, then collect the results
  102. * summerisle joined #java
  103. * ErikT joined #java
  104. * rensenwxre joined #java
  105. * [twisti] joined #java
  106. * tkjay joined #java
  107. * IceMichael joined #java
  108. * chiselfuse joined #java
  109. * braxas joined #java
  110. * leonardus joined #java
  111. * CodeGeek joined #java
  112. * waz joined #java
  113. * kinabalu joined #java
  114. * APic joined #java
  115. * gas51627 joined #java
  116. * ptomli joined #java
  117. * sponkz joined #java
  118. * stfstfm_ joined #java
  119. * metalmaniac joined #java
  120. * hwpplayer1 joined #java
  121. * magla joined #java
  122. * ForeverDreaming joined #java
  123. * Nemu64- joined #java
  124. * Odyss3us joined #java
  125. * Anaphaxaway joined #java
  126. * monkeyPlus joined #java
  127. * ztevoz joined #java
  128. * geli joined #java
  129. * hwpplayer1 joined #java
  130. * sambalala joined #java
  131. sambalala -+\
  132. dreamreal I actually disagree
  133. ernimril ^~!
  134. dreamreal no, no, you *!@
  135. dreamreal Thou offendsth me
  136. * Ragnor joined #java
  137. * LtHummus joined #java
  138. * five618480339176 joined #java
  139. * lockdown joined #java
  140. * victori joined #java
  141. * hwpplayer1 joined #java
  142. * Anaphaxaway joined #java
  143. * MikeBux joined #java
  144. * mindCrime joined #java
  145. * Maxxed joined #java
  146. * Maxxed joined #java
  147. * sambalala joined #java
  148. * Bharton joined #java
  149. * ForeverDreaming joined #java
  150. * Odyss3us joined #java
  151. * mapperr joined #java
  152. * iwtga7 joined #java
  153. * bionade24 joined #java
  154. NeXeN concurrency != parallel
  155. NeXeN enoq: and don't fall into the forkjoinpool trap. always lean on your StructuredTaskScope and ExecutorService https://download.java.net/java/early_access/loom/docs/api/java.base/java/util/concurrent/StructuredTaskScope.html and https://download.java.net/java/early_access/loom/docs/api/java.base/java/util/concurrent/ExecutorService.html btw that's loom docs. don't try and use a spliterator or something or you'll end up waiting 10 seconds blocking
  156. NeXeN the rest of the world
  157. javabot NeXeN's titles: "StructuredTaskScope (Java SE 25 & JDK 25 [build 1])" | "ExecutorService (Java SE 25 & JDK 25 [build 1])"
  158. nevet https://download.java.net/java/early_access/loom/docs/api/java.base/java/util/concurrent/StructuredTaskScope.html "StructuredTaskScope (Java SE 25 & JDK 25 [build 1])" || https://download.java.net/java/early_access/loom/docs/api/java.base/java/util/concurrent/ExecutorService.html "ExecutorService (Java SE 25 & JDK 25 [build 1])"