This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
daemon off; | |
worker_processes 1; | |
error_log /dev/stdout debug; | |
pid /tmp/nginx.pid; | |
events { | |
worker_connections 8192; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
started_at = Time.now.to_f | |
response = HTTP.post("/users/create") | |
report_time("users.create", (Time.now.to_f - started_at) * 1000) | |
response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Thread.new do | |
started_at = Time.now.to_f | |
sleep 1 | |
report_time("thread.contention", (Time.now.to_f - started_at - 1) * 1000) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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']}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder