Hi,
I’m coming to ruby from other programming languages like C# and Swift
where you can handle web async calls with built in feature like
async/await, so you can fetch db result, wait them to perform an
operation once the result are returned, but still be able to do other
things while waiting for the results.
On Ruby, if I want to query a database and not block the system, without
necessarily creating a new thread, is it possible ? What are the common
ways in this language ?
but in general how do people deal with this ?I come from a native app
iOS background, where I run blocking tasks in the background, that is in
another thread so the user is never stuck.
On a server level, a single user can block all other users if they try
to do concurrent tasks. So for example, if a user upload a file and that
takes 5 seconds, or run a long query, during those seconds, the server
can’t serve any other users. Is that correct ? Or am I missing something
?
I never did server side programming yet, and this seems to be a huge
issue, yet I don’t find much documentation about it.
How do people deal with concurrency in ruby usually, they just create
other threads ? I visited many site running ruby, or pythong, and they
are not particularly slow, yet I can’t understand how, considering the
fact that those systems can’t run concurrent tasks.
I come from a native app
iOS background, where I run blocking tasks in the background,
that is in another thread so the user is never stuck.<
The principles are the same everywhere. In your previous programming
language, you say that threads are created to run tasks that don’t block
the main process, but for ruby your requirement is that no additional
threads/processes can be used?
I visited many site running ruby, or pythong, and they
are not particularly slow, yet I can’t understand how, considering the
fact that those systems can’t run concurrent tasks.
Both ruby and python can run concurrent tasks.
The websites you visited are probably not using a ruby/python server
anyway. You don’t need a server written in ruby/python to execute
ruby/python programs. For instance, Apache can run ruby/python
programs.
On Ruby, if I want to query a database and not block the system,
without necessarily creating a new thread,<
You either have to create a new thread or a new process. See the
following:
IO#popen
Open3 module
Socket module
EventMachine
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.