It seems many people are saying OCaml does not have a good capacity for concurrency and it is also not good for web server applications.
I am currently learning ocaml's manual. It seems that OCaml provide concurrency now.
Can I know why OCaml's concurrency/threading is considered as bad?
Can I develop server application in OCaml? What problems may I meet?
Many tasks may be compute bound, but still not practical to use a multithreaded approach because the process must synchronise on the entire state. Such a program cannot benefit from multithreading because no work can be performed concurrently.
When using threads, it can cause increased complexity, and debugging your code can become much more difficult. It is possible to add logic to make sure data is synchronized across threads, but too much reliance on synchronization can lead to performance issues, which affects an application's scalability.
Only one thread at a time is allowed to run OCaml code, hence opportunities for parallelism are limited to the parts of the program that run system or C library code. However, threads provide concurrency and can be used to structure programs as several communicating processes.
On a single core microprocessor (uP), it is possible to run multiple threads, but not in parallel. Although conceptually the threads are often said to run at the same time, they are actually running consecutively in time slices allocated and controlled by the operating system.
See Concurrency vs. parallelism — What's the difference?. OCaml's threads offer concurrency, as you can have the next function start before the previous one is finished. But OCaml does not offer parallelism, so when that second function starts, the first one has to be put on hold. Two threads cannot run simultaneously, so multiple CPU-bound computations in a process will block each other, and you can't max out all your CPU cores in one process.
That's people's beef with OCaml's threading. Does it mean you can't use OCaml for something like a server? No. It's something you will have to take into account in your server design, but it's not generally a showstopper. Heck, Node.js is straight-up single-threaded, yet its main purpose is creating servers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With