-
-
Save Hamled/cab41245abd208b4f6cb67026f135e34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns buffers-test | |
(:require [manifold.deferred :as d])) | |
(defn buffers-for [n size] | |
(for [n (range n)] | |
(java.nio.ByteBuffer/allocate size))) | |
(defn buffers [size] | |
(lazy-seq | |
(cons (java.nio.ByteBuffer/allocate size) | |
(buffers size)))) | |
(defn loop-buffers [bs] | |
(loop [bs bs] | |
(when-not (empty? bs) | |
(println (.capacity (first bs))) | |
(recur (rest bs))))) | |
(defn d-loop-buffers [bs] | |
@(d/loop [bs bs] | |
(when-not (empty? bs) | |
(println (.capacity (first bs))) | |
(d/recur (rest bs))))) | |
(defn d-loop-buffers-fut [bs] | |
(d/future | |
@(d/loop [bs bs] | |
(when-not (empty? bs) | |
(println (.capacity (first bs))) | |
(d/recur (rest bs)))))) | |
; Run this with -Xmx1G | |
; or otherwise set SIZE to a value so that | |
; 10 * SIZE bytes is enough to OOM | |
(def SIZE (* 250 1024 1024)) | |
; These work fine | |
(loop-buffers (take 10 (buffers SIZE))) | |
(d-loop-buffers (take 10 (buffers SIZE))) | |
@(d/future (d-loop-buffers (take 10 (buffers SIZE)))) | |
; These result in OOM | |
(loop-buffers (buffers-for 10 SIZE)) | |
(d-loop-buffers (buffers-for 10 SIZE)) | |
@(d-loop-buffers-fut (take 10 (buffers SIZE))) | |
@(d-loop-buffers-fut (buffers-for 10 SIZE)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment