简体   繁体   English

Redis 在弹性豆茎中运行 sidekiq 时出现连接超时错误

[英]Redis connection timeout error when running sidekiq in elastic beanstalk

I'm trying to set up sidekiq to connect to redis elasticache (in-transit encryption enabled) from my AWS elastic beanstalk (Amazon Linux 2) instance.我正在尝试设置 sidekiq 以从我的 AWS 弹性豆茎(Amazon Linux 2)实例连接到 redis elasticache(已启用传输中加密)。 I've followed links such as this , but am getting a 'Redis::TimeoutError: Connection timed out' when I do so.我已经关注了这样的链接,但是当我这样做时,我得到了一个“Redis::TimeoutError: Connection timed out”。 So now instead of deploying the scripts that run the 'bundle exec sidekiq -e production' command, I am just running that command in the /var/app/current directory of my ec2 instance with root privileges.因此,现在我没有部署运行“bundle exec sidekiq -e production”命令的脚本,而是使用 root 权限在我的 ec2 实例的 /var/app/current 目录中运行该命令。 Unfortunately that error is still appearing, and I am unsure why.不幸的是,该错误仍然出现,我不确定为什么。 My security groups are all configured correctly, and I can confirm the endpoint is correct.我的安全组都配置正确,我可以确认端点是正确的。

The weird part is, I can connect to my redis endpoint on elasticache by running this command: openssl s_client -quiet -connect my_redis_endpoint:6379 and it works correctly.奇怪的是,我可以通过运行以下命令连接到 elasticache 上的 redis 端点:openssl s_client -quiet -connect my_redis_endpoint:6379 并且它工作正常。 But sidekiq will fire up, then time out when I run that.但是 sidekiq 会启动,然后当我运行它时会超时。 Here is that output:这是output:


[root@ip-10-0-2-138 current]# bundle exec sidekiq -e production 2020-12-04T05:30:39.930Z pid=2910 tid=2xygu INFO: Booting Sidekiq 6.0.0 with redis options {:url=>"redis://master.redisproductionelasticache.bmxvqz.use2.cache.amazonaws.com:6379/12", :ssl=>true, :network_timeout=>5, :id=>"Sidekiq-server-PID-2910"} [root@ip-10-0-2-138 current]# bundle exec sidekiq -e production 2020-12-04T05:30:39.930Z pid=2910 tid=2xygu 信息:使用 redis 选项启动 Sidekiq 6.0.0 {:url =>"redis://master.redisproductionelasticache.bmxvqz.use2.cache.amazonaws.com:6379/12", :ssl=>true, :network_timeout=>5, :id=>"Sidekiq-server-PID-2910 "}

2020-12-04T05:31:04.271Z pid=2910 tid=1e7u1a class=MessageBroadcastJob jid=82dd4217186de283e9d9bb70 elapsed=10.251 INFO: fail 2020-12-04T05:31:04.271Z pid=2910 tid=1e7u1a class=MessageBroadcastJob jid=82dd4217186de283e9d9bb70 elapsed=10.251 信息:失败

2020-12-04T06:10:30.391Z pid=2910 tid=1e7wm6 WARN: {"context":"Job raised exception","job":{"class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper","wrapped":"MessageBroadcastJob","queue":"default","args":[{"job_class":"MessageBroadcastJob","job_id":"4d7d5195-7444-44c9-81c7-7f9a0c6b1f75","provider_job_id":null,"queue_name":"default","priority":null,"arguments":[{"_aj_globalid":"gid://e-wagers/Message/57bed09a-ef2d-4963-8288-65fe733347ba"}],"executions":0,"locale":"en"}],"retry":true,"jid":"a8f258e1feeecbf8c40a21a5","created_at":1607059284.1670992,"enqueued_at":1607062220.2854364,"error_message":"Connection timed out","error_class":"Redis::TimeoutError","failed_at":1607059284.1989071,"retry_count":6,"retried_at":1607060724.9108222},"jobstr":" 2020-12-04T06:10:30.391Z pid=2910 tid=1e7wm6 WARN: {"context":"作业引发异常","job":{"class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper" "wrapped":"MessageBroadcastJob","queue":"default","args":[{"job_class":"MessageBroadcastJob","job_id":"4d7d5195-7444-44c9-81c7-7f9a0c6b1f75","provider_job_id" :null,"queue_name":"default","priority":null,"arguments":[{"_aj_globalid":"gid://e-wagers/Message/57bed09a-ef2d-4963-8728888}- ,"executions":0,"locale":"en"}],"retry":true,"jid":"a8f258e1feeecbf8c40a21a5","created_at":1607059284.1670992,"enqueued_at":1607062220.2854364,"error_message":"连接定时out","error_class":"Redis::TimeoutError","failed_at":1607059284.1989071,"retry_count":6,"retried_at":1607060724.9108222},"jobstr":"


Here are my configuration files:这是我的配置文件:

# config/initializers/sidekiq.rb

require 'sidekiq'
require 'sidekiq/web'

rails_root = Rails.root || File.dirname(__FILE__) + '/../..'
rails_env = Rails.env || 'development'
redis_config = YAML.load_file(rails_root.to_s + '/config/redis.yml')
redis_config.merge! redis_config.fetch(Rails.env, {})
redis_config.symbolize_keys!

Sidekiq.configure_server do |config|
 config.redis = { url: "redis://#{redis_config[:host]}:#{redis_config[:port]}/12", ssl: true, network_timeout: 5 }
end

Sidekiq.configure_client do |config|
 config.redis = { url: "redis://#{redis_config[:host]}:#{redis_config[:port]}/12", ssl: true, network_timeout: 5 }
end
development:
  host: 'localhost'
  port: 6379
  db: 5
production:
  host: 'master.my_redis_endpoint.bmxvqz.use2.cache.amazonaws.com'
  port: 6379
  db: 5
# config/sidekiq.yml

:concurrency: 25
:queues:
  - [mailers, 3]
  - ["priority", 2]
  - ["default", 1]

Any ideas what could be causing this?有什么想法可能导致这种情况吗? Unfortunately there are not a lot of resources online concerning sidekiq with elasticache, elastic beanstalk, and the newer Amazon Linux 2 platform.不幸的是,关于 sidekiq 与 elasticache、elastic beanstalk 和更新的 Amazon Linux 2 平台的在线资源并不多。

Have you tried to use rediss:// instead of redis://您是否尝试过使用rediss://而不是redis://

Since your Sidekiq process is receiving a job from the server, it is able to connect to Redis.由于您的 Sidekiq 进程正在从服务器接收作业,因此能够连接到 Redis。 What you're probably seeing is another gem's connection to Redis failing due to an overly-aggressive timeout.您可能看到的是另一个 gem 与 Redis 的连接由于过度激进的超时而失败。 In my case, that gem was Redlock, which was setting a 100ms timeout (a little too slow for the Elasticache connection, which had ~120ms latency): https://github.com/leandromoreira/redlock-rb/blob/40756981932ca53c3e32bf3c68aa5ea9b772ef16/lib/redlock/client.rb#L9在我的例子中,那个 gem 是 Redlock,它设置了一个 100 毫秒的超时(对于 Elasticache 连接来说有点太慢了,它有大约 120 毫秒的延迟): https://github.com/leandromoreira/redlock-rb/blob/40756981932ca53c3e32bf3c68aa5ea9b772ef lib/redlock/client.rb#L9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM