Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure lots of threads

Tags:

clojure

I just got done watching Rick Hickey's "Clojure Concurrency" talk, and I have a few questions about threads.

Let's say I have a situation with lots of Agents, let's say 10,000 of them running one machine. I'd rather not have 10,000 CPU threads running at once, but I don't want threads to be blocked by the actions of other threads.

In this example I won't really be waiting for replies, instead each Agent will be sending a message or two, and then waiting until it gets a message.

How would I structure a program like this without getting 10k OS threads which would probably end up slowing the system down.

like image 712
Timothy Baldridge Avatar asked Jun 14 '10 19:06

Timothy Baldridge


People also ask

Is clojure multithreaded?

Clojure simplifies multi-threaded programming in several ways. Because the core data structures are immutable, they can be shared readily between threads. However, it is often necessary to have state change in a program.

Does future create new thread?

If no existing thread is available, a new thread will be created and added to the pool. Threads that have not been used for sixty seconds are terminated and removed from the cache.

What is arrow in Clojure?

Threading macros, also known as arrow macros, convert nested function calls into a linear flow of function calls, improving readability.

What is thread in Java with example?

What is a Thread in Java? A thread in Java is the direction or path that is taken while a program is being executed. Generally, all the programs have at least one thread, known as the main thread, that is provided by the JVM or Java Virtual Machine at the starting of the program's execution.


1 Answers

Keep in mind that Clojure is running on top of a JVM. So you may have 10,000 Java threads, but that doesn't equate to 10,000 OS processes. I suspect that the garbage collector could end up being your bottleneck, so I would focus on tuning the footprints of each agent. (It goes without saying that you should test and verify this before tuning.)

like image 116
G__ Avatar answered Oct 31 '22 05:10

G__