a program in execution. It consist of state context(which is about allocated memory, opened file descriptors) and execution context(which is about sequence of instructions that should be performed). A run process has at least one thread.
of CPU utilization, consisting of a program counter, a stack, and a set of registers. Basically, it’s a set of commands that can be executed by a core. Threads share a process’ memory, opened files. One process can have several threads.
program which is working constantly. Since the moment you started a web server, it listens to a port or a socket, reads request data, processing it, and writes response data.
That map language-level threads directly to OS threads(Ruby, Java). Basically, it means if you run 100 threads in your app it will create 100 threads in OS. And OS is responsible for their scheduling. You can only set priorities. 2. That have their own concurrency abstraction levels and their own schedulers(Go, Erlang, Elixir). If you create 100 threads it won’t create the same amount. It depends how your VM is configured.
which written in C. It reads source files, tokenizes, parses them, compiles and puts into Ruby VM execution stack. It keeps info about everything existing in your program, variables, constants, classes.
context switching. It makes Ruby thread-safe internally but it doesn’t guarantee that your programs will be thread safe. So, the only thread can work per a unit of time
• Synchronization between threads are much easier because threads share the single memory • Design, it’s possible that sidekiq’s algorithms are written much better • Something else...
call external commands you do IO. Real world IO examples: • Working with files. • Listening to ports/sockets • Making HTTP calls • Querying DG(Postgres, MySQL, Redis, Elastic)
Ruby can’t control the context switch, it can only provide hints for OS • GIL is a mechanism which helps Ruby VM not to be corrupted between context switches • GIL makes the Ruby itself thread-safe but it doesn’t make our code thread safe • Threads are beneficial when you do a lot of IO because Ruby VM uses async IO.