Fork me on GitHub
#beginners
<
2020-12-18
>
roelof09:12:13

I have this challenge from the book "Clojure from the ground up"

Write a function which, in a dosync transaction, removes the first number in work and adds it to sum.
Then, in two futures, call that function over and over again until there's no work left. Verify that @sum is 4999950000
anyone a idea what the two futures should do and why 2 futures So far I have this :
(def work (ref (apply list (range 1e5))))

(def sum4 (ref 0))

(defn sum_sync [] 
  (dosync
   (let [first (first work)
         rest (rest work)]
     alter sum4 + first)
   ))

chrisblom10:12:24

the 2 futures execute the processing in separate threads, i guess it is to demonstrate that changes within a transaction are atomic

chrisblom11:12:28

also, you should update work in your code

chrisblom11:12:51

and alter sum4 + first is missing parens now

roelof11:12:22

oke, so one future for updating sum and one for removing a item from work ? @chrisblom

chrisblom11:12:03

no, write a function that takes one item from the work list, adds it to the sum

phoenixjj11:12:05

How to check for performance issue or where time is being spent? I have 2.3 million rows in db. Loaded one column of big decimal type and running cumulative sum on it and then passing it to incanter line charts. It's been going on more than an hour, but no result so far.

> (def csum (cumulative-sum
           (map #(:resp %)
                (jdbc/execute! ds ["select resp from train_data"]
                               {:builder-fn rs/as-unqualified-lower-maps}))))

> (charts/line-chart (range 0 (count csum)) csum)
Using Visualvm I can see on heapspace chart moving up and down. also object count is pretty much constant by looking at multiple heap dump. Only 8GB of ram is used and also htop shows only 1 core active out of 8.

jumar12:12:28

1. csum is fully realized at the point you call line-chart? 2. If you evaluate all the 2M rows I guess incanter can have issues producing a chart with so many values.

phoenixjj17:12:33

yes. It is taking around 6 minutes to produce 100K charts.

chrisblom11:12:11

such that both sum and work are updated in the transaction

chrisblom11:12:46

then call that function in 2 futures until the work list is empty

chrisblom11:12:19

@phoenixai2082 did you try profiling or sampling in visualvm?

phoenixjj11:12:48

tried profiling, but it is stuck at 75% from 40 minutes

andarp11:12:28

As a brand new Clojure programmer and IntelliJ/Cursive user... How do I profile my code to figure out what is eating up CPU cycles or allocations?

val_waeselynck11:12:04

clj-async-profiler

3
jumar12:12:01

^ That's a good one. Assuming that the bottleneck is CPU. Here's a very recent and long webinar about Async Profiler https://www.youtube.com/playlist?list=PLNCLTEx3B8h4Yo_WvKWdLvI9mj1XpTKBr

andarp11:12:17

I can get my code running with a "Run/Debug Configuration" no problem, but the "Run with CPU profiler" option tells me Deferred configurations cannot be run with standard runners and I'm not sure I get what that means...

bnstvn13:12:43

what does a symbol do in a function position?

('+ 1 2)
=> 2

bnstvn13:12:54

ah, like keyword

('+ {'+ :hmm})
=> :hmm

👍 3
bronsa13:12:31

it looks itself up on the first argument

bronsa13:12:52

the second argument is not-found

👍 3
Tuan-Anh13:12:05

Hi, I don't know if this is the right channel to ask this but here goes I'm planning on developing a mobile app. I could just work with JavaScript and React Native, but I want to try ClojureScript with React Native. Does anyone here have any experience developing mobile app with ClojureScript and React Native, either through work or personal project? I would love to know what framework I should use. I've been doing research but seems like re-natal is no longer maintained and krell is too early in development with not that much documentation?

Tuan-Anh13:12:40

Any advices/help would be greatly appreciated!

borkdude13:12:23

@tuananh.le #cljsrn would be the channel for React Native + CLJS

Tuan-Anh14:12:55

Gotcha, thanks @borkdude, I will post my question there

Michaël Salihi14:12:35

@tuananh.le Yes and in addition to the channel, you add this website/page https://cljsrn.org/ There have been 2 very good videos recently added in the "Talks & Videos" section.

6
Tuan-Anh15:12:57

Thank @UFBL6R4P3! I will check out that webpage and watch those videos.

👍 3