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
Run
**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
Run
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`:
* dlHttpClient (virt=6220, **res=4104** , shr=2476)
* dlCurl (virt=137708 **res=9624** shr=8256)
Replacing "1Mb" with "1Gb"
([etc](https://androidtipszoneapk.blogspot.com/2015/04/download-test-files-100kb-1mb-10mb.html))
in `grabUrl`, memory usage remains reasonable.