Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Crystal 1.8.2 https://crystal-lang.org/:

    n = ARGV.first.to_i32
    finished = Channel(Nil).new
    n.times do
      spawn do
        sleep(10.seconds)
        finished.send(nil)
      end
    end
    n.times { finished.receive }
Memory usage determined with `ps ax -o pid,rss,args`. Runtime measured with `/usr/bin/time -v`. (Had to run `sudo sysctl vm.max_map_count=2500000` to get the final two rows.) Results:

    N        Runtime(s)  RSS(kiB)  RSS(MiB)
    =======================================
          1       10.01      1792         2
       1000       10.01      6016         6
      10000       10.11     45184        44
     100000       11.00    435840       426
    1000000       20.25   4336768      4235
"System time" rather than "user time" is the majority (7.94s system time, 2.83s user time in the 20.25s wall time run). Is this pointing to memory allocations?

Crystal Fiber docs https://crystal-lang.org/api/1.8.2/Fiber.html says "A Fiber has a stack size of 8 MiB which is usually also assigned to an operating system thread. But only 4KiB are actually allocated at first so the memory footprint is very small." -- and perhaps unsurprisingly, 4KiB times 1000000 is approximately 4 GiB. Nice when the math works out like that :)

To me this is useful as a baseline for something like a websocket server, with some number of idle connections, each Websocket connection mapped to a Fiber that is waiting for I/O activity but mostly idle.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: