I write this code:
get "/attachment":
attachment "public/root/test.rar "
resp readFile "public/root/test.rar "
build on nim 0.15.2 , windows 7
run started : memeory used: 744KiB
test.rar is about 5.158MiB, after download :memeory used: 46.855MiB
It's totally unacceptable.
So my question is : how to use attatchment effectively or correctly in jester?
Thank you!
Yes, it keep growing if I download next file, it seems to be a leak, maybe readFile under async condition ? I really need help or have to give up towards golang. Thank you!
import jester, asyncdispatch, htmlgen,strutils
routes:
get "/":
resp h1("Hello world")
get "/download":
attachment "public/root/test.rar"
resp readFile "public/root/test.rar"
runForever()
build with --gc:markAndSweep, nothing changed.
build with --gc:boehm, error occurred:
lib\pure\asyncdispatch.nim(198, 14) Error: undeclared identifier: 'ForeignCell'
I see the same behaviour using Rosencrantz, hence I believe it is a bug in asyncfile.
I tried using a ~50MB file, and the usage grows with every download. It stays bounded, though: at around 400MB the GC kicks in and the memory used never grows more than 500MB.
For reference
import asynchttpserver, asyncdispatch, rosencrantz
let handler = get[
path("/download")[
file("test.tar.gz")
]
]
let server = newAsyncHttpServer()
waitFor server.serve(Port(8080), handler)