Skip to content

Instantly share code, notes, and snippets.

@akitaonrails
Last active October 1, 2019 18:20
Show Gist options
  • Save akitaonrails/f0cd567a39164447340bbbda24fa68d0 to your computer and use it in GitHub Desktop.
Save akitaonrails/f0cd567a39164447340bbbda24fa68d0 to your computer and use it in GitHub Desktop.

Revisions

  1. akitaonrails revised this gist Oct 1, 2019. 2 changed files with 15 additions and 21 deletions.
    22 changes: 1 addition & 21 deletions spawning_fibers.txt → output.txt
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,3 @@
    ```ruby
    channel = Channel(Int32).new
    n = 101_000

    n.times do |_|
    spawn do
    sleep 0.001 # io block 1ms
    channel.send 1
    end
    end

    total = 0
    n.times do
    total += channel.receive
    end
    ```

    ```
    Unhandled exception: Cannot allocate new fiber stack: Cannot allocate memory (Errno)
    GC Warning: Failed to expand heap by 2834432 bytes
    GC Warning: Failed to expand heap by 790528 bytes
    @@ -33,6 +15,4 @@ Invalid memory access (signal 11) at address 0x60018
    [0x5614ba59cd15] ???
    [0x5614ba583b42] main +50
    [0x7fd6dd442b97] __libc_start_main +231
    [0x5614ba57ff1a] _start +42
    [0x0] ???
    ```
    [0x5614ba57ff1a] _start +42
    14 changes: 14 additions & 0 deletions spawning_fibers.cr
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    channel = Channel(Int32).new
    n = 101_000

    n.times do |_|
    spawn do
    sleep 0.001 # io block 1ms
    channel.send 1
    end
    end

    total = 0
    n.times do
    total += channel.receive
    end
  2. akitaonrails renamed this gist Oct 1, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. akitaonrails created this gist Oct 1, 2019.
    38 changes: 38 additions & 0 deletions spawning_fibers.cr
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    ```ruby
    channel = Channel(Int32).new
    n = 101_000
    n.times do |_|
    spawn do
    sleep 0.001 # io block 1ms
    channel.send 1
    end
    end
    total = 0
    n.times do
    total += channel.receive
    end
    ```

    ```
    Unhandled exception: Cannot allocate new fiber stack: Cannot allocate memory (Errno)
    GC Warning: Failed to expand heap by 2834432 bytes
    GC Warning: Failed to expand heap by 790528 bytes
    GC Warning: Out of Memory! Heap size: 5 MiB. Returning NULL!
    Invalid memory access (signal 11) at address 0x60018
    [0x5614ba5a4176] ???
    [0x5614ba5a3e8f] __crystal_sigfault_handler +479
    [0x7fd6dde91890] ???
    [0x5614ba5931d5] ???
    [0x5614ba59259b] ???
    [0x5614ba591a06] ???
    [0x5614ba587560] ???
    [0x5614ba585272] ???
    [0x5614ba59e5db] ???
    [0x5614ba59cd15] ???
    [0x5614ba583b42] main +50
    [0x7fd6dd442b97] __libc_start_main +231
    [0x5614ba57ff1a] _start +42
    [0x0] ???
    ```