Standardize ruby binstubs

This commit is contained in:
Mike Perham 2022-01-26 15:33:23 -08:00
parent 1efbaddcef
commit 255b492725
3 changed files with 57 additions and 59 deletions

View File

@ -4,7 +4,7 @@
# RUBYOPT=-w bundle exec sidekiq
$TESTING = false
require_relative '../lib/sidekiq/cli'
require_relative "../lib/sidekiq/cli"
def integrate_with_systemd
return unless ENV["NOTIFY_SOCKET"]
@ -32,8 +32,8 @@ begin
rescue => e
raise e if $DEBUG
if Sidekiq.error_handlers.length == 0
STDERR.puts e.message
STDERR.puts e.backtrace.join("\n")
warn e.message
warn e.backtrace.join("\n")
else
cli.handle_exception e
end

View File

@ -4,18 +4,18 @@
# RUBYOPT=-w bundle exec sidekiq
$TESTING = false
#require 'ruby-prof'
require 'bundler/setup'
# require "ruby-prof"
require "bundler/setup"
Bundler.require(:default, :load_test)
require_relative '../lib/sidekiq/cli'
require_relative '../lib/sidekiq/launcher'
require_relative "../lib/sidekiq/cli"
require_relative "../lib/sidekiq/launcher"
Sidekiq.configure_server do |config|
config.options[:concurrency] = 10
config.redis = { db: 13, port: 6380}
#config.redis = { db: 13, port: 6380, driver: :hiredis}
config.options[:queues] << 'default'
config.redis = {db: 13, port: 6380}
# config.redis = { db: 13, port: 6380, driver: :hiredis}
config.options[:queues] << "default"
config.logger.level = Logger::ERROR
config.average_scheduled_poll_interval = 2
config.reliable! if defined?(Sidekiq::Pro)
@ -28,9 +28,9 @@ class LoadWorker
1
end
def perform(idx, ts=nil)
puts(Time.now.to_f - ts) if ts != nil
#raise idx.to_s if idx % 100 == 1
def perform(idx, ts = nil)
puts(Time.now.to_f - ts) if !ts.nil?
# raise idx.to_s if idx % 100 == 1
end
end
@ -38,43 +38,41 @@ end
# brew install toxiproxy
# gem install toxiproxy
# run `toxiproxy-server` in a separate terminal window.
require 'toxiproxy'
require "toxiproxy"
# simulate a non-localhost network for realer-world conditions.
# adding 1ms of network latency has an ENORMOUS impact on benchmarks
Toxiproxy.populate([{
"name": "redis",
"listen": "127.0.0.1:6380",
"upstream": "127.0.0.1:6379"
name: "redis",
listen: "127.0.0.1:6380",
upstream: "127.0.0.1:6379"
}])
self_read, self_write = IO.pipe
%w(INT TERM TSTP TTIN).each do |sig|
begin
trap sig do
self_write.puts(sig)
end
rescue ArgumentError
puts "Signal #{sig} not supported"
%w[INT TERM TSTP TTIN].each do |sig|
trap sig do
self_write.puts(sig)
end
rescue ArgumentError
puts "Signal #{sig} not supported"
end
Sidekiq.redis {|c| c.flushdb}
Sidekiq.redis { |c| c.flushdb }
def handle_signal(launcher, sig)
Sidekiq.logger.debug "Got #{sig} signal"
case sig
when 'INT'
when "INT"
# Handle Ctrl-C in JRuby like MRI
# http://jira.codehaus.org/browse/JRUBY-4637
raise Interrupt
when 'TERM'
when "TERM"
# Heroku sends TERM and then waits 30 seconds for process to exit.
raise Interrupt
when 'TSTP'
when "TSTP"
Sidekiq.logger.info "Received TSTP, no longer accepting new work"
launcher.quiet
when 'TTIN'
when "TTIN"
Thread.list.each do |thread|
Sidekiq.logger.warn "Thread TID-#{(thread.object_id ^ ::Process.pid).to_s(36)} #{thread['label']}"
Sidekiq.logger.warn "Thread TID-#{(thread.object_id ^ ::Process.pid).to_s(36)} #{thread["label"]}"
if thread.backtrace
Sidekiq.logger.warn thread.backtrace.join("\n")
else
@ -98,37 +96,37 @@ iter.times do
count.times do |idx|
arr[idx][0] = idx
end
Sidekiq::Client.push_bulk('class' => LoadWorker, 'args' => arr)
Sidekiq::Client.push_bulk("class" => LoadWorker, "args" => arr)
end
Sidekiq.logger.error "Created #{count*iter} jobs"
Sidekiq.logger.error "Created #{count * iter} jobs"
start = Time.now
Monitoring = Thread.new do
while true
sleep 0.2
qsize = Sidekiq.redis do |conn|
conn.llen "queue:default"
end
total = qsize
#Sidekiq.logger.error("RSS: #{Process.rss} Pending: #{total}")
if total == 0
Sidekiq.logger.error("Done, #{iter * count} jobs in #{Time.now - start} sec")
Sidekiq.logger.error("Now here's the latency for three jobs")
LoadWorker.perform_async(1, Time.now.to_f)
LoadWorker.perform_async(2, Time.now.to_f)
LoadWorker.perform_async(3, Time.now.to_f)
sleep 0.2
exit(0)
end
while true
sleep 0.2
qsize = Sidekiq.redis do |conn|
conn.llen "queue:default"
end
total = qsize
# Sidekiq.logger.error("RSS: #{Process.rss} Pending: #{total}")
if total == 0
Sidekiq.logger.error("Done, #{iter * count} jobs in #{Time.now - start} sec")
Sidekiq.logger.error("Now here's the latency for three jobs")
LoadWorker.perform_async(1, Time.now.to_f)
LoadWorker.perform_async(2, Time.now.to_f)
LoadWorker.perform_async(3, Time.now.to_f)
sleep 0.2
exit(0)
end
end
end
begin
#RubyProf::exclude_threads = [ Monitoring ]
#RubyProf.start
# RubyProf::exclude_threads = [ Monitoring ]
# RubyProf.start
events = Sidekiq.options[:lifecycle_events][:startup]
events.each(&:call)
events.clear
@ -144,14 +142,14 @@ begin
end
end
rescue SystemExit => e
#Sidekiq.logger.error("Profiling...")
#result = RubyProf.stop
#printer = RubyProf::GraphHtmlPrinter.new(result)
#printer.print(File.new("output.html", "w"), :min_percent => 1)
# Sidekiq.logger.error("Profiling...")
# result = RubyProf.stop
# printer = RubyProf::GraphHtmlPrinter.new(result)
# printer.print(File.new("output.html", "w"), :min_percent => 1)
# normal
rescue => e
raise e if $DEBUG
STDERR.puts e.message
STDERR.puts e.backtrace.join("\n")
warn e.message
warn e.backtrace.join("\n")
exit 1
end

View File

@ -1,6 +1,6 @@
#!/usr/bin/env ruby
require 'sidekiq/monitor'
require "sidekiq/monitor"
section = "all"
section = ARGV[0] if ARGV.size == 1