Skip to content

Instantly share code, notes, and snippets.

View zanker's full-sized avatar

Zachary Anker zanker

  • San Francisco, CA
View GitHub Profile
started_at = Time.now.to_f # 00:00
# Context switch to another thread
# 00:05, Context switch back 5 seconds later
response = HTTP.post("/users/create") # 00:06
report_time("users.create", (Time.now.to_f - started_at) * 1000) # 00:06
started_at = Time.now.to_f
response = HTTP.post("/users/create")
report_time("users.create", (Time.now.to_f - started_at) * 1000)
response
Thread.new do
started_at = Time.now.to_f
sleep 1
report_time("thread.contention", (Time.now.to_f - started_at - 1) * 1000)
end
# Thread 1
total = 0
loop do
total = total + 1
end
# Thread 2
response = HTTP.post("/users/create")
data = JSON.parse(response.body)
HTTP.post("/update-profile/#data['user_id']}")
def <<(work)
@mutex.synchronize do
if @shutdown
raise "Unable to add work while shutting down"
end
@todo << work
if @waiting < @todo.size and @spawned < @max
spawn_thread
if io = sock.accept_nonblock
client = Client.new io, @binder.env(sock)
if remote_addr_value
client.peerip = remote_addr_value
elsif remote_addr_header
client.remote_addr_header = remote_addr_header
end
pool << client
pool.wait_until_not_full unless queue_requests
require 'http'
started_at = Time.now
threads = 10.times.map do |i|
sleep 0.1
Thread.new do
begin
started_at = Time.now
response = HTTP.get("http://localhost:8001/#{i}")
@zanker
zanker / nginx.conf
Last active November 23, 2017 14:51
daemon off;
worker_processes 1;
error_log /dev/stdout debug;
pid /tmp/nginx.pid;
events {
worker_connections 8192;
}
@zanker
zanker / gist:683c9346af06453a8b14
Created March 11, 2016 21:59
raven-ruby base
Measure Mode: wall_time
Thread ID: 70262938909220
Fiber ID: 70262945578140
Total Time: 12.474074363708496
Sort by: total_time
%total %self total self wait child calls Name
--------------------------------------------------------------------------------
100.00% 0.00% 12.474 0.000 0.000 12.474 1 Global#[No method]
12.474 0.002 0.000 12.472 1/1 Integer#times
@zanker
zanker / gist:5278a25a2904f7542150
Created March 11, 2016 21:59
raven-ruby optimizations
Measure Mode: wall_time
Thread ID: 70319499115040
Fiber ID: 70319529395800
Total Time: 1.1018621921539307
Sort by: total_time
%total %self total self wait child calls Name
--------------------------------------------------------------------------------
100.00% 0.00% 1.102 0.000 0.000 1.102 1 Global#[No method]
1.102 0.001 0.000 1.100 1/1 Integer#times