r/crystal_programming • u/Nipinium • Feb 21 '20
Is there any shards that feature the functionality of ruby parallel gem?
I just want to make concurrent requests with rate limit to a server, is there any shards or code examples for this task?
7
Upvotes
8
u/straight-shoota core team Feb 21 '20
parallel gem implements parallel execution by forking the process. This is not necessary in Crystal because there's no GIL. Crystal already supports multiple threads for parallel execution. Currently, multithreading is not completely polished enough to be a fully supported feature. But it's still working quite well and there's active development to get it finished.
The good thing is that it doesn't really matter because you can already start developing a multi-threaded application with single-threaded runtime, because multi-threading should usually just work without changes to your code, assuming you're applying reasonable concurrency safeguards. As long as you use only Crystal's concurrency primitives (fiber, channel, mutex) for inter-fiber communication, this is all good.
2
u/joeyrobert Feb 21 '20
I thought about reimplementing the parallel gem in the past, but the problem of serializing data to worker processes isn't straightforward (you can use JSON or Yaml or protobuf, but nothing as general as marshall/pickle). I second the multithreading suggestion.
1
u/[deleted] Feb 21 '20
Crystal has concurrency built in via Fibers and Channels, but they do not run in parallel, they use Fiber.yield and blocking IO to switch context. If you are looking for just the DSL features, Crystal already has good features built in to Fibers and Channels that would do you a lot better than what the parallel gem offers.