This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-22
Channels
- # arachne (8)
- # bangalore-clj (1)
- # beginners (72)
- # boot (95)
- # braveandtrue (5)
- # business (1)
- # capetown (1)
- # cider (180)
- # cljs-dev (8)
- # cljsrn (20)
- # clojure (104)
- # clojure-art (1)
- # clojure-brasil (8)
- # clojure-czech (1)
- # clojure-greece (15)
- # clojure-korea (13)
- # clojure-poland (2)
- # clojure-russia (53)
- # clojure-sg (5)
- # clojure-spec (60)
- # clojure-uk (35)
- # clojurescript (186)
- # community-development (3)
- # core-async (24)
- # cursive (18)
- # datascript (11)
- # datomic (39)
- # devcards (4)
- # emacs (2)
- # events (1)
- # funcool (23)
- # hoplon (148)
- # juxt (1)
- # ldnclj (2)
- # luminus (1)
- # off-topic (22)
- # om (27)
- # onyx (35)
- # overtone (2)
- # pedestal (7)
- # perun (8)
- # protorepl (2)
- # rdf (6)
- # re-frame (15)
- # reagent (2)
- # ring-swagger (10)
- # untangled (54)
Can anyone see what’s wrong here:
(go
(<! (clojure.core.async/timeout 7500))
;; Handling in separate thread, making sure to log exception
(taoensso.timbre/logged-future
(handle-updates param1 param2)))
Sometimes the work going on inside of handle-updates
kill my app for many seconds (rendering it unavailable), until the underlying thread dies. I get an OutOfMemoryError: Java heap space
.
I know it may be difficult to answer right away, but since I’m new to core.async
I hope I’ve just missed something basic.
you are doing stuff in a loop as fast as possible, and nothing in the loop is throttling or blocking
like (while true ...your example code...) would generate go blocks and futures as fast as the cpu could handle it with no brakes
The reason I create the future is because I want to get it out of core.async, that - as I think I’ve understood - have a limited amount of ressources.
if handle-updates is blocking on io, then sure, but if handle-updates is cpu bound, then running it in a go block likely to be fine
To provide some context: This is actually part of a throttling function. Updates come in. I use an atom to store the updates. If the atom is empty, I start the go block above. Then when the timeout has been reached, I read the value of the atom, reset the atom, and pass the value to the handle-updates function.
As a side note: I haven’t seen the OOM before I started sending the updates to the database. If I just logged the newest update, the OOM didn’t occur.
(I use Datomic BTW, it's the peer library of Datomic that throws the OOM - but only after a while, not immediately - so I think you’re right about the creation of many go loops or similar - I just can’t find the cause, and I don’t use go loops further down the stream)
what I would do is run a single thread (using the thread macro or logged-future) that loops over a channel, and reads from the channel and writes to the database
make that channel use a windowed buffer or whatever, and only do the loop every seven and a half seconds
so now instead of spinning off all these waiting go routines and futures, you have one reusable io thread