* [PATCH 1/2] request: drop to_path support
@ 2016-11-05 2:07 Eric Wong
2016-11-05 2:07 ` [PATCH 2/2] explicitly clear large buf when it is obviously safe Eric Wong
0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2016-11-05 2:07 UTC (permalink / raw)
To: http_spew-public
It is too complex for sockets due to unknown response lengths
and no actively developed servers take advantage of it.
---
lib/http_spew/request.rb | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/lib/http_spew/request.rb b/lib/http_spew/request.rb
index 63bac64..3c3ef7e 100644
--- a/lib/http_spew/request.rb
+++ b/lib/http_spew/request.rb
@@ -2,8 +2,7 @@
# This is the base class actually capable of making a normal HTTP request
class HTTP_Spew::Request
- # May be called by some Rack servers such as Rainbows! to bypass
- # +to_path+ calls and avoid path lookups.
+ # May be called by IO.select or for use with IO#wait_*able
attr_reader :to_io
# Stores any exception that was raised in another thread (e.g.
@@ -95,12 +94,6 @@ class HTTP_Spew::Request
@response = r << self
end
- # Used by some Rack-compatible servers to optimize transfers
- # by using IO.copy_stream
- def to_path
- "/dev/fd/#{@to_io.fileno}"
- end
-
def too_big! # :nodoc:
raise HTTP_Spew::RequestError.new(self), "response headers too large", []
end
--
EW
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] explicitly clear large buf when it is obviously safe
2016-11-05 2:07 [PATCH 1/2] request: drop to_path support Eric Wong
@ 2016-11-05 2:07 ` Eric Wong
0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2016-11-05 2:07 UTC (permalink / raw)
To: http_spew-public
We can reduce memory pressure on the GC by explicitly
calling String#clear after we're done with a buffer.
This will hopefully reduce malloc fragmentation as
well as improving locality.
---
lib/http_spew/content_md5.rb | 1 +
lib/http_spew/input_spray.rb | 1 +
lib/http_spew/request.rb | 4 +++-
3 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/http_spew/content_md5.rb b/lib/http_spew/content_md5.rb
index ed68523..153ad86 100644
--- a/lib/http_spew/content_md5.rb
+++ b/lib/http_spew/content_md5.rb
@@ -42,6 +42,7 @@ class HTTP_Spew::ContentMD5
digest.update(buf)
wr.write(buf << "\r\n".freeze)
end while input.read(0x4000, buf)
+ buf.clear
end
if expect_len && expect_len.to_i != @bytes_digested
raise HTTP_Spew::LengthError,
diff --git a/lib/http_spew/input_spray.rb b/lib/http_spew/input_spray.rb
index a12d569..dfd23c4 100644
--- a/lib/http_spew/input_spray.rb
+++ b/lib/http_spew/input_spray.rb
@@ -35,6 +35,7 @@ class HTTP_Spew::InputSpray
@pipes.delete_if { |rd, wr| write_fail?(rd, wr, buf) }.empty? and
raise HTTP_Spew::NoWritersError, "all writers have died", []
end
+ buf.clear
rescue => e
@pipes.each { |rd, _| rd.error = e }
ensure
diff --git a/lib/http_spew/request.rb b/lib/http_spew/request.rb
index 3c3ef7e..1d02a98 100644
--- a/lib/http_spew/request.rb
+++ b/lib/http_spew/request.rb
@@ -38,7 +38,7 @@ class HTTP_Spew::Request
def resume
if @buf
case rv = @to_io.kgio_trywrite(@buf)
- when String
+ when String # unlikely
@buf = rv # loop retry, socket buffer could've expanded
when Symbol
return rv
@@ -60,6 +60,7 @@ class HTTP_Spew::Request
if @input
@to_io.write(buf) while @input.read(0x4000, buf)
end
+ buf.clear
timeout -= (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0)
while :wait_readable == (rv = read_response) && timeout >= 0.0
t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@@ -104,6 +105,7 @@ class HTTP_Spew::Request
while @to_io.kgio_read(0x4000, buf)
yield buf
end
+ buf.clear
end
# Used internally by various HTTP_Spew elements to report errors
--
EW
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-11-05 2:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-05 2:07 [PATCH 1/2] request: drop to_path support Eric Wong
2016-11-05 2:07 ` [PATCH 2/2] explicitly clear large buf when it is obviously safe Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/http_spew.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox