gpt4 book ai didi

mysql - 是我的代码问题还是 Sidekiq 速度慢,因为它不应该访问 Rails 模型?

转载 作者:行者123 更新时间:2023-11-29 10:00:21 25 4
gpt4 key购买 nike

我曾经将很多代码包装在 Thread.new {} 中,然后开始偶然发现 Sidekiq 以使后台任务变得更容易一些。几周后,情况令人失望,我不知道这是否是我将代码放入我的 sidekiq 工作人员的方式或交易是什么。

例如,

[1] pry(#<DomainWorker>)> domain = Domain.find_by(unique_id: @unique_id)
[2] pry(#<DomainWorker>)> urls
=> [{:url=>"http://admin.example.com/"}, {:url=>"http://example.com/"}, {:url=>"http://www.example.com/"}, {:url=>"https://admin.example.com/"}, {:url=>"https://example.com/"}, {:url=>"https://www.example.com/"}]
[3] pry(#<DomainWorker>)> domain.domain_urls.build(urls)
=> [#<DomainUrl:0x0000557c97f2a3c8 id: nil, domain_id: 32, url: "http://admin.example.com/", created_at: nil, updated_at: nil>,
#<DomainUrl:0x0000557c97cc6e38 id: nil, domain_id: 32, url: "http://example.com/", created_at: nil, updated_at: nil>,
#<DomainUrl:0x0000557c97cadd70 id: nil, domain_id: 32, url: "http://www.example.com/", created_at: nil, updated_at: nil>,
#<DomainUrl:0x0000557c97c9c8e0 id: nil, domain_id: 32, url: "https://admin.example.com/", created_at: nil, updated_at: nil>,
#<DomainUrl:0x0000557c97c7ed18 id: nil, domain_id: 32, url: "https://example.com/", created_at: nil, updated_at: nil>,
#<DomainUrl:0x0000557c97c43df8 id: nil, domain_id: 32, url: "https://www.example.com/", created_at: nil, updated_at: nil>]

仅仅运行domain.domain_urls.build(urls)命令就需要大约15秒的时间来执行。如果我打开rails c,该命令会立即运行。

这是否违反了操纵 sidekiq 工作人员模型或其他内容的最佳实践?不知道为什么有时需要 15-20 秒,下一次需要 5 秒,等等。这是非常不一致的。我什至有一个 MailWorker,有时需要 2 秒或 2 分钟才能发送电子邮件。不确定这笔交易是什么。

这是我的 config/sidekiq.yml 配置文件:

development:  
:concurrency: 50
production:
:concurrency: 50
:queues:
- default

这是我的代码还是 Sidekiq 不擅长完成这些任务?我在这里缺少什么?

编辑

在我的开发环境中简单地禁用 eager_load 似乎取得了一些进展。

config/environments/development.rb中:

改变了

config.eager_load = false

config.eager_load = true

它可以工作一段时间,但在一堆任务排队并完成后,它又开始挂起。现在又卡住了。

如果我在 MySQL 中运行 show processlist,我会看到以下内容:

mysql> show full processlist;
+----+------------+-----------+-------------------+---------+------+----------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------------+-----------+-------------------+---------+------+----------+-----------------------+
| 31 | app_dev | localhost | app_portal_dev | Sleep | 1017 | | NULL |
| 50 | root | localhost | NULL | Query | 0 | starting | show full processlist |
| 55 | app_dev | localhost | app_portal_dev | Sleep | 1059 | | NULL |
| 57 | app_dev | localhost | app_portal_dev | Sleep | 1028 | | NULL |
| 58 | app_dev | localhost | app_portal_dev | Sleep | 420 | | NULL |
| 61 | app_dev | localhost | app_portal_dev | Sleep | 1078 | | NULL |
| 62 | app_dev | localhost | app_portal_dev | Sleep | 425 | | NULL |
| 63 | app_dev | localhost | app_portal_dev | Sleep | 191 | | NULL |
+----+------------+-----------+-------------------+---------+------+----------+-----------------------+
8 rows in set (0.00 sec)

此外,如果我向 Sidekiq 工作程序发送终止 TTIN 信号,则输出如下:

2018-11-03T03:20:29.415Z 65977 TID-gsr3safel WARN: Thread TID-gsr4jqd7l processor
2018-11-03T03:20:29.415Z 65977 TID-gsr3safel WARN: /home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:68:in `select'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:68:in `rescue in _read_from_socket'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:64:in `_read_from_socket'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:56:in `gets'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:363:in `read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:263:in `block in read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:251:in `io'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:262:in `read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:118:in `block in call'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:232:in `block (2 levels) in process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:370:in `ensure_connected'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:222:in `block in process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:307:in `logging'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:221:in `process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:118:in `call'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:210:in `block in call_with_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:281:in `with_socket_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:209:in `call_with_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1172:in `block in _bpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:45:in `block in synchronize'
/home/myuser/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:45:in `synchronize'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1169:in `_bpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1214:in `brpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/fetch.rb:36:in `block in retrieve_work'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq.rb:95:in `block in redis'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:65:in `block (2 levels) in with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:64:in `handle_interrupt'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:64:in `block in with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:61:in `handle_interrupt'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:61:in `with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq.rb:92:in `redis'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/fetch.rb:36:in `retrieve_work'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:89:in `get_one'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:99:in `fetch'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:82:in `process_one'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:71:in `run'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/util.rb:16:in `watchdog'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/util.rb:25:in `block in safe_thread'
2018-11-03T03:20:29.416Z 65977 TID-gsr3safel WARN: Thread TID-gsr4jqddx processor
2018-11-03T03:20:29.416Z 65977 TID-gsr3safel WARN: /home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:68:in `select'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:68:in `rescue in _read_from_socket'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:64:in `_read_from_socket'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:56:in `gets'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:363:in `read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:263:in `block in read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:251:in `io'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:262:in `read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:118:in `block in call'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:232:in `block (2 levels) in process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:370:in `ensure_connected'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:222:in `block in process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:307:in `logging'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:221:in `process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:118:in `call'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:210:in `block in call_with_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:281:in `with_socket_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:209:in `call_with_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1172:in `block in _bpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:45:in `block in synchronize'
/home/myuser/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:45:in `synchronize'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1169:in `_bpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1214:in `brpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/fetch.rb:36:in `block in retrieve_work'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq.rb:95:in `block in redis'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:65:in `block (2 levels) in with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:64:in `handle_interrupt'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:64:in `block in with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:61:in `handle_interrupt'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:61:in `with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq.rb:92:in `redis'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/fetch.rb:36:in `retrieve_work'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:89:in `get_one'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:99:in `fetch'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:82:in `process_one'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:71:in `run'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/util.rb:16:in `watchdog'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/util.rb:25:in `block in safe_thread'
2018-11-03T03:20:29.416Z 65977 TID-gsr3safel WARN: Thread TID-gsr4jqdh1 processor
2018-11-03T03:20:29.416Z 65977 TID-gsr3safel WARN: /home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:68:in `select'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:68:in `rescue in _read_from_socket'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:64:in `_read_from_socket'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:56:in `gets'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:363:in `read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:263:in `block in read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:251:in `io'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:262:in `read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:118:in `block in call'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:232:in `block (2 levels) in process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:370:in `ensure_connected'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:222:in `block in process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:307:in `logging'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:221:in `process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:118:in `call'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:210:in `block in call_with_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:281:in `with_socket_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:209:in `call_with_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1172:in `block in _bpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:45:in `block in synchronize'
/home/myuser/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:45:in `synchronize'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1169:in `_bpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1214:in `brpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/fetch.rb:36:in `block in retrieve_work'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq.rb:95:in `block in redis'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:65:in `block (2 levels) in with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:64:in `handle_interrupt'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:64:in `block in with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:61:in `handle_interrupt'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:61:in `with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq.rb:92:in `redis'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/fetch.rb:36:in `retrieve_work'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:89:in `get_one'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:99:in `fetch'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:82:in `process_one'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:71:in `run'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/util.rb:16:in `watchdog'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/util.rb:25:in `block in safe_thread'
2018-11-03T03:20:29.417Z 65977 TID-gsr3safel WARN: Thread TID-gsr4jqcuh processor
2018-11-03T03:20:29.417Z 65977 TID-gsr3safel WARN: /home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:68:in `select'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:68:in `rescue in _read_from_socket'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:64:in `_read_from_socket'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:56:in `gets'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:363:in `read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:263:in `block in read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:251:in `io'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:262:in `read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:118:in `block in call'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:232:in `block (2 levels) in process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:370:in `ensure_connected'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:222:in `block in process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:307:in `logging'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:221:in `process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:118:in `call'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:210:in `block in call_with_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:281:in `with_socket_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:209:in `call_with_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1172:in `block in _bpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:45:in `block in synchronize'
/home/myuser/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:45:in `synchronize'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1169:in `_bpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1214:in `brpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/fetch.rb:36:in `block in retrieve_work'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq.rb:95:in `block in redis'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:65:in `block (2 levels) in with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:64:in `handle_interrupt'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:64:in `block in with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:61:in `handle_interrupt'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:61:in `with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq.rb:92:in `redis'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/fetch.rb:36:in `retrieve_work'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:89:in `get_one'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:99:in `fetch'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:82:in `process_one'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:71:in `run'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/util.rb:16:in `watchdog'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/util.rb:25:in `block in safe_thread'
2018-11-03T03:20:29.417Z 65977 TID-gsr3safel WARN: Thread TID-gsr4jqd4p processor
2018-11-03T03:20:29.417Z 65977 TID-gsr3safel WARN: /home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:68:in `select'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:68:in `rescue in _read_from_socket'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:64:in `_read_from_socket'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:56:in `gets'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:363:in `read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:263:in `block in read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:251:in `io'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:262:in `read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:118:in `block in call'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:232:in `block (2 levels) in process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:370:in `ensure_connected'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:222:in `block in process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:307:in `logging'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:221:in `process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:118:in `call'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:210:in `block in call_with_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:281:in `with_socket_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:209:in `call_with_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1172:in `block in _bpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:45:in `block in synchronize'
/home/myuser/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:45:in `synchronize'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1169:in `_bpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1214:in `brpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/fetch.rb:36:in `block in retrieve_work'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq.rb:95:in `block in redis'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:65:in `block (2 levels) in with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:64:in `handle_interrupt'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:64:in `block in with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:61:in `handle_interrupt'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:61:in `with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq.rb:92:in `redis'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/fetch.rb:36:in `retrieve_work'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:89:in `get_one'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:99:in `fetch'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:82:in `process_one'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:71:in `run'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/util.rb:16:in `watchdog'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/util.rb:25:in `block in safe_thread'
2018-11-03T03:20:29.418Z 65977 TID-gsr3safel WARN: Thread TID-gsr4jqcn5 processor
2018-11-03T03:20:29.418Z 65977 TID-gsr3safel WARN: /home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:68:in `select'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:68:in `rescue in _read_from_socket'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:64:in `_read_from_socket'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:56:in `gets'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/connection/ruby.rb:363:in `read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:263:in `block in read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:251:in `io'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:262:in `read'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:118:in `block in call'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:232:in `block (2 levels) in process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:370:in `ensure_connected'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:222:in `block in process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:307:in `logging'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:221:in `process'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:118:in `call'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:210:in `block in call_with_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:281:in `with_socket_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis/client.rb:209:in `call_with_timeout'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1172:in `block in _bpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:45:in `block in synchronize'
/home/myuser/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:45:in `synchronize'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1169:in `_bpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/redis-4.0.2/lib/redis.rb:1214:in `brpop'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/fetch.rb:36:in `block in retrieve_work'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq.rb:95:in `block in redis'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:65:in `block (2 levels) in with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:64:in `handle_interrupt'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:64:in `block in with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:61:in `handle_interrupt'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/connection_pool-2.2.2/lib/connection_pool.rb:61:in `with'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq.rb:92:in `redis'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/fetch.rb:36:in `retrieve_work'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:89:in `get_one'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:99:in `fetch'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:82:in `process_one'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:71:in `run'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/util.rb:16:in `watchdog'
/home/myuser/.rvm/gems/ruby-2.5.1/gems/sidekiq-5.2.2/lib/sidekiq/util.rb:25:in `block in safe_thread'

最佳答案

Rails 开发模式自动加载是单线程的。您可以将 Sidekiq 设置为您想要的任何并发数,但您仍然会有一个巨大的互斥锁来单线程您的作业,以便它们可以安全地自动加载。打开 eager_load 或切换到生产模式会禁用自动加载。

并发:50 太高了。不要将其设置高于 25。

也可能您有大量线程,但数据库连接数量不同,请在 config/database.yml 中设置 pool: 25

关于mysql - 是我的代码问题还是 Sidekiq 速度慢,因为它不应该访问 Rails 模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53127788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com