What is the difference between molding and threading in the background process?

Reading the documentation for the gemstone belt, he points out:

By default, spawn will use fork to create child processes. You can configure it for streaming processing by specifying the appearance method when you invoke it or configure the environment. For example, this is how you can say that spawn uses threads when called,

What is the difference between using a plug or thread, what are the implications of any decision, and how can I know what to use?

+4
source share
2 answers

Threading means that you are running code in another thread in the same process, while forking means that you are deploying a separate process.

Threading generally means that you will use less memory since you will not have a separate instance of the application (this advantage is reduced if you have a copy for recording a friendly ruby โ€‹โ€‹such as ree). Communication between threads is also a bit easier.

Depending on your ruby โ€‹โ€‹interpreter, ruby โ€‹โ€‹cannot effectively use additional kernels (jruby is good, MRI is much worse), so the appearance of many additional threads will affect the performance of your web application and will not fully utilize your resources - MRI only launches one stream at a time

Forking creates separate instances of ruby, so you can better use multiple cores. You are also less likely to adversely affect the main application. You should be a little careful when branching when sharing open file descriptors when you use fork, so usually you want to reopen database connections, memcache connections, etc.

With MRI, I would use forking, with jruby there is more to do that you had to do for threading

+4
source

Fork creates another process, and processes are generally designed to work no matter what else happens in your application. Processes do not share resources.

Threads, however, are for another purpose. You want to use a thread if you want to parallelize a specific task.

"fork () induces a relationship between parents and children between two processes. Creating a thread causes a peer-to-peer relationship between all threads of the process.

Read a more detailed explanation of this link .

+3
source

All Articles