Hi everyone! I'm new to nim and have a question about this
So I have this server on my network that has an encoded video that I download whenever it changes to my device. i used to have a python script that does this, but decided to do it in a new language just for fun. so far I really like nim but I have a problem where if I keep the program running the mem doesnt go down like it does in python so it just goes very high
this is my code
var client = newHttpClient()
while true:
client.downloadfile("http://192.168.1.15/video.mp4", "updated.mp4")
sleep(60000)
someone told me I should add client.close but that doesn't fix it and my ram used is still high do I need to use the gcfullcollect function? I tried it and it didn't work... I'm not used to system languages :/
thanks everyone!
I couldn't reproduce the problem, neither on nim v0.19.0 release nor today's #devel, running under Ubuntu 18-10.
For my test I created two basic download loop daemons:
dlHttpClient.nim using Nim stdlib as above -
import os, times, httpClient
var client = newHttpClient()
let outName = getAppFilename() & ".out"
const grabUrl = "http://speedtest.ftp.otenet.gr/files/test1Mb.db"
while true:
echo "Fetching " & grabUrl & " ..."
var startTime = cpuTime()
client.downloadFile grabUrl, outName
var workSec = (cpuTime() - startTime) * 1000
echo "... finished in " & $workSec & " sec\n"
sleep 10*1000
dlCurl.nim using libcurl -
import os, times, libCurl
var outFile: File
let outName = getAppFilename() & ".out"
const grabUrl = "http://speedtest.ftp.otenet.gr/files/test1Mb.db"
proc checkCurl(code: Code) =
if code != E_OK:
raise newException(AssertionError, "CURL failed: " & $easy_strerror(code))
while true:
echo "Fetching " & grabUrl & " ..."
var startTime = cpuTime()
var curl = libCurl.easy_init()
discard outFile.open(outName, fmWrite)
checkCurl curl.easySetOpt(OPT_URL, grabUrl)
checkCurl curl.easySetOpt(OPT_FOLLOWLOCATION, 1)
checkCurl curl.easySetOpt(OPT_WRITEDATA, outFile)
checkCurl curl.easyPerform()
curl.easyCleanup()
outFile.close()
var workSec = (cpuTime() - startTime) * 1000
echo "... finished in " & $workSec & " sec\n"
sleep 10*1000
After looping for a while, both used a reasonable and stable amount of memory, with the curl version using a little bit more. Pasting from top:
Replacing "1Mb" with "1Gb" (etc) in grabUrl, memory usage remains reasonable.