Ruby Thread and Process
Tag: Ruby
Tag: Rails
Category: jekyll
Category: update
Category: git
Category: database
Category: PostgreSQL
Category: websocket
Category: ruby
Category: projects
Category: Redis
Category: mysql
Category: Mac
Category: Node
Category: NPM
Category: PM2
Category: nodejs
Category: Meteor
Category: Nginx
Category: gitLab
Category: Rails
- Why Ruby on Rails is better than Python Django?
- How to use Hotwire turbo in Rails 6 with Webpacker?
- Rails 6 Credentials (master.key and credentials.yml.enc)
- Rails Console
- JIRA-Atlassian-Connect-App-Django
- Rails 4 5.0 Session Cookie AuthenticityToken
- Rails Active Storage
- Rails 5 Source code Research
- 微信支付
- Rails零星笔记
Category: Homebrew
Category: CentOS
Category: FreeSwitch
Category: Ruby
- Ruby on Rails 8
- RESTful API
- Ruby on Rails 7
- Study from Ruby official website
- Ruby-Metaprogramming
- Ruby连数据库的问题
- rbenv使用
Category: Vim
Category: javascript
Category: React-Native
Category: Wechat
Category: homeland
Category: JavaScript
Category: Docker
Category: RubyMine
Category: Authorization
Category: RESTful-API
Category: Proxy
Category: Deploy
Category: Devise
Category: Bootstrap
Category: Active_Storage
Category: github
Category: Android
Category: cloud
Category: ssh
Category: python
Category: reactjs
Category: markdown
Category: ShadowSocks
Category: Code
Category: rails
Category: code
Category: Django
Category: Python
Category: DRF
Category: Fish
Category: Yarn
Category: Material-UI
Category: CSS
Category: aws
Category: uwsgi
Category: nginx
Category: docker
Category: React
Category: Enzyme
Category: Jira
Category: Interview
Category: JetBrain
Category: PyCharm
Category: ESLint
Category: Rails6
Category: NVM
Category: ssl
Category: tencent
Category: CI
Category: jenkins
Category: GitHub
Category: Credentials
Category: master.key
Category: Webpacker
Category: Turbo
Category: Hotwire
Category: Bootstrap5
Category: Flutter
Category: Clash
Category: Tor
Category: proxy
Category: Build
Category: SwitchyOmega
Category: Chrome-extension
Category: SQLAlchemy
Category: Algorithm
Category: Rails7
Category: Data
Category: Structure
Category: CPP
Category: Languages
Category: Golang
Category: Typescript
Category: Rails 8
-
$ NUM=
ps M <pid> | wc -l | xargs
&& expr $NUM - 1 #Mac下查看一个process下的线程数 -
个人理解:rails和thin等web app frameworks 需要通过web server来启动,也就是说web server会启动进程,该进程会把rails加在到进程的内存,在有请求过来时将请求交给rails处理。rails进程其实就是加载它的web server的进程(或线程)。
-
Unicorn 是进程式的,即如果加sleep在某个controller中,会直接导致线程卡住,所有请求全部卡住。即在此时任何浏览器访问任何页面都无效,因为unicorn默认只启动一个进程,并且一个进程只有1个线程。所以必须要通过多启动几个workers的方式(每个worker都是一个进程)来完成其他请求的并发处理(这样就不会卡住了)。而puma、thin(通过ruby xx.rb方式)启动不会出现这种问题。只在访问该controller的request会被卡住,因为他们是一个进程中包含多个线程的。
-
可以通过在任意程序中加入
::Process.pid
来查看当前的进程,也可以通过$ ps
$ ps -p pid
$ ps aux
查看。 -
eventmachine是通过在initialize/eventmachine.rb 中加入 Thread.new { EventMachine.run } 来完成启动的,所以它其实和rails其实是在同一个进程中。
-
http://rubylearning.com/satishtalim/ruby_threads.html
When a Ruby program terminates, all threads are killed, regardless of their states.
-
hutch是需要启动一个新的进程来监听rabbitmq的,可以查看它的源代码来看如何通过命令行启动一个新的进程。http://localhost:15672/#/connections 可以看到rabbitmq的连接情况。
-
Rabbitmq的生产者们和消费者们的往往都不在同一个进程中,可能在不同的机器上,特别是在复杂的系统中。