Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
153d4a5a
Commit
153d4a5a
authored
Dec 28, 2016
by
Leonard Hecker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proxy: Improved handling of bufferPool
parent
20483c23
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
17 deletions
+22
-17
caddyhttp/proxy/reverseproxy.go
caddyhttp/proxy/reverseproxy.go
+22
-17
No files found.
caddyhttp/proxy/reverseproxy.go
View file @
153d4a5a
...
@@ -27,15 +27,28 @@ import (
...
@@ -27,15 +27,28 @@ import (
"github.com/mholt/caddy/caddyhttp/httpserver"
"github.com/mholt/caddy/caddyhttp/httpserver"
)
)
var
defaultDialer
=
&
net
.
Dialer
{
var
(
Timeout
:
30
*
time
.
Second
,
defaultDialer
=
&
net
.
Dialer
{
KeepAlive
:
30
*
time
.
Second
,
Timeout
:
30
*
time
.
Second
,
}
KeepAlive
:
30
*
time
.
Second
,
}
var
bufferPool
=
sync
.
Pool
{
New
:
createBuffer
}
bufferPool
=
sync
.
Pool
{
New
:
createBuffer
}
)
func
createBuffer
()
interface
{}
{
func
createBuffer
()
interface
{}
{
return
make
([]
byte
,
32
*
1024
)
return
make
([]
byte
,
0
,
32
*
1024
)
}
func
pooledIoCopy
(
dst
io
.
Writer
,
src
io
.
Reader
)
{
buf
:=
bufferPool
.
Get
()
.
([]
byte
)
defer
bufferPool
.
Put
(
buf
)
// CopyBuffer only uses buf up to its length and panics if it's 0.
// Due to that we extend buf's length to its capacity here and
// ensure it's always non-zero.
bufCap
:=
cap
(
buf
)
io
.
CopyBuffer
(
dst
,
src
,
buf
[
0
:
bufCap
:
bufCap
])
}
}
// onExitFlushLoop is a callback set by tests to detect the state of the
// onExitFlushLoop is a callback set by tests to detect the state of the
...
@@ -234,10 +247,8 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request,
...
@@ -234,10 +247,8 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request,
}
}
defer
backendConn
.
Close
()
defer
backendConn
.
Close
()
go
func
()
{
go
pooledIoCopy
(
backendConn
,
conn
)
// write tcp stream to backend
io
.
Copy
(
backendConn
,
conn
)
// write tcp stream to backend.
pooledIoCopy
(
conn
,
backendConn
)
// read tcp stream from backend
}()
io
.
Copy
(
conn
,
backendConn
)
// read tcp stream from backend.
}
else
{
}
else
{
defer
res
.
Body
.
Close
()
defer
res
.
Body
.
Close
()
for
_
,
h
:=
range
hopHeaders
{
for
_
,
h
:=
range
hopHeaders
{
...
@@ -252,9 +263,6 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request,
...
@@ -252,9 +263,6 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request,
}
}
func
(
rp
*
ReverseProxy
)
copyResponse
(
dst
io
.
Writer
,
src
io
.
Reader
)
{
func
(
rp
*
ReverseProxy
)
copyResponse
(
dst
io
.
Writer
,
src
io
.
Reader
)
{
buf
:=
bufferPool
.
Get
()
.
([]
byte
)
defer
bufferPool
.
Put
(
buf
)
if
rp
.
FlushInterval
!=
0
{
if
rp
.
FlushInterval
!=
0
{
if
wf
,
ok
:=
dst
.
(
writeFlusher
);
ok
{
if
wf
,
ok
:=
dst
.
(
writeFlusher
);
ok
{
mlw
:=
&
maxLatencyWriter
{
mlw
:=
&
maxLatencyWriter
{
...
@@ -267,10 +275,7 @@ func (rp *ReverseProxy) copyResponse(dst io.Writer, src io.Reader) {
...
@@ -267,10 +275,7 @@ func (rp *ReverseProxy) copyResponse(dst io.Writer, src io.Reader) {
dst
=
mlw
dst
=
mlw
}
}
}
}
pooledIoCopy
(
dst
,
src
)
// `CopyBuffer` only uses `buf` up to it's length and
// panics if it's 0 => Extend it's length up to it's capacity.
io
.
CopyBuffer
(
dst
,
src
,
buf
[
:
cap
(
buf
)])
}
}
// skip these headers if they already exist.
// skip these headers if they already exist.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment