ring-clojure / ring-json

Ring middleware for handling JSON
313 stars 47 forks source link

Use streamed responses instead of strings. #24

Closed AeroNotix closed 10 years ago

AeroNotix commented 10 years ago

Correct me where I am wrong but I was under the impression that using streams instead of strings allows the webserver to stream the response to the client more easily.

weavejester commented 10 years ago

generate-stream returns a BufferedWriter, not an InputStream. This patch won't work with Ring.

AeroNotix commented 10 years ago

Is there any point in pursuing this? Will webservers be able to take advantage of streams?

weavejester commented 10 years ago

It depends on what Cheshire and Jackson are doing being the scenes. If they're loading the data structure into memory before writing it, then there would be less benefit to using streams.

In order for this to work, you'd need to pipe the output of the writer to a new inputstream. This might take more time than simply returning a string, especially JSON under 4096 bytes, or whatever the default buffer size is.

Really, the one way to be certain is to benchmark it and see what works, but I suspect that this would actually be less performant for the majority of JSON responses, which tend to be only several kilobytes in size.

AeroNotix commented 10 years ago

Closing, then.