Skip to content

Instantly share code, notes, and snippets.

@nikushi
nikushi / bad.md
Last active August 29, 2015 13:56

How to reproduce:

  • GrowthForecast replies with HTTP/1.1 and Transfer-Encoding: chunked header.
  • A client requests with HTTP/1.0 and a client does not support HTTP/1.1

The problem:

  • rack-streaming-proxy reploy with chunked body, but HTTP/1.0 client can not de-chunk the body.

https://www.ietf.org/rfc/rfc2616.txt

  3.If a Content-Length header field (section 14.13) is present, its
     decimal value in OCTETs represents both the entity-length and the
     transfer-length. The Content-Length header field MUST NOT be sent
     if these two lengths are different (i.e., if a Transfer-Encoding


Rack::Test::Methods 使って get を mock app に対して発行すると、MockResponseがContent-Lengthを勝手につける仕様だった。

[27, 36] in /Users/nikushi.nobuhiro/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rack-test-0.6.2/lib/rack/mock_session.rb
   27:     def request(uri, env)
   28:       env["HTTP_COOKIE"] ||= cookie_jar.for(uri)
   29:       @last_request = Rack::Request.new(env)
   30:       status, headers, body = @app.call(@last_request.env)
   31:
```
--- a/lib/rack/streaming_proxy/proxy.rb
+++ b/lib/rack/streaming_proxy/proxy.rb
@@ -75,7 +75,7 @@ class Rack::StreamingProxy::Proxy
end
# Notify client http version to the instance of Response class.
- response.client_http_version = env['HTTP_VERSION'].sub(/HTTP\//, '')
+ response.client_http_version = env['HTTP_VERSION'].sub(/HTTP\//, '') if env.has_key?('HTTP_VERSION')
@nikushi
nikushi / launch-fluentd-on-httpconf.md
Last active August 29, 2015 13:58
FluentdをHTTP経由でコンフィグロードして起動させるワンライナーhack

FluentdをHTTP経由でコンフィグロードして起動させるワンライナーhack

fluentd -i "include http://localhost:3000/fluentd.conf" -c /dev/null 

or

curl -s -S http://localhost:3000/fluentd.conf | fluentd -i - -c /dev/null 

bin/yohoushiからunicorn, serverengineを起動する直前まで

bin/yohoushi
 |
 v
lib/yohoushi/cli.rb

   options[:config]    = File.expand_path('config/yohoushi.god', ENV['RAILS_ROOT']) # yohoushi custom
   require File.expand_path('vendor/extensions/god/cli/run', ENV['RAILS_ROOT']) # yohoushi custom

USR1 works?

config/serverengine.god watch memory usage
|
v
triggered!
|
v
God send USR1 to serverengine

embeded mode

se = ServerEngine.create(nil, MyWorker, {
  :daemonize => true,
  :log => 'myserver.log',
  :pid_path => 'myserver.pid',
})
se.run
@nikushi
nikushi / test
Created April 28, 2014 01:53
test
test
Count: 1  Time=0.25s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), yohoushi[yohoushi]@localhost
  SELECT  `nodes`.* FROM `nodes`  WHERE `nodes`.`type` IN ('S') AND `nodes`.`path` = 'S' LIMIT N

Count: 1922  Time=0.23s (450s)  Lock=0.00s (0s)  Rows=0.0 (0), yohoushi[yohoushi]@localhost
  SELECT  `nodes`.* FROM `nodes`  WHERE `nodes`.`type` IN ('S') AND `nodes`.`path` = 'S'  ORDER BY `nodes`.`id` ASC LIMIT N

Count: 8017  Time=0.09s (749s)  Lock=0.00s (0s)  Rows=0.9 (7563), yohoushi[yohoushi]@localhost
  SELECT  id FROM `nodes`  WHERE `nodes`.`type` IN ('S') AND `nodes`.`path` = 'S'  ORDER BY `nodes`.`id` ASC LIMIT N