Fork me on GitHub
#ring
<
2020-09-12
>
antonmos02:09:05

ive got kind of an obscure question 🙂 I have 2 apps, both with jetty/ring-adapter 1.8.1, muuntaja 0.6.7 for transit. I’d like to stream it all the way to the browser. the browser calls app A, which calls app B using clj-http 3.10.1 and with the following options

(defn as-stream [params]
  (-> params
      (assoc :as :stream :decompress-body false)
      (update :headers assoc :accept-encoding "gzip")))
to avoid unziping and rezipping the response. App B pulls a large dataset from the db. I just enabled streaming in muuntaja with :return :output-stream When i call app B directly via curl, i get the response within a reasonable time. When i call app A, the streaming happens very very slowly, with multi second pauses. Does this ring any bells for anyone?

antonmos02:09:34

cc @U055NJ5CC because muuntaja is involved

antonmos03:09:13

google has led me to http://jetty.4.x6.nabble.com/Streaming-proxy-of-content-using-jetty-and-jetty-client-with-end-to-end-flow-control-td4967006.html#a4967012 which seems potentially relevant except that i just want to proxy the response, not the request

ikitommi07:09:20

Not sure how transit & clj-http play together when streaming. The :as :stream might be blocking operation as I think is the transit write (but, with different streams). Might also be a bug in muuntaja-streamong-transit. If there is a jsva-side reverse proxy code available, I would anyway go with that.

ikitommi07:09:48

for async clj-proxy, I believe you need: - run server in (ring-)async-mode - use the async mode in clj-http - stream out asynchronously: ring1 only defines blocking writes, but usually this is not a problem. You could bypass ring here and write lazily to the underlaying java web servers channel etc.

ikitommi07:09:19

@U0BKWMG5B is the best person to help I guess