-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
in this commit: - chunks out the http request body to avoid making very large allocations. - establishes a limit for the maximum http request body size that the listener will accept. - utilizes a pool of byte buffers to reduce GC pressure.
- Loading branch information
Showing
2 changed files
with
143 additions
and
34 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package http_listener | ||
|
||
type pool struct { | ||
n int | ||
buffers chan []byte | ||
} | ||
|
||
func NewPool() *pool { | ||
return &pool{ | ||
buffers: make(chan []byte, 50), | ||
} | ||
} | ||
|
||
func (p *pool) get() []byte { | ||
select { | ||
case b := <-p.buffers: | ||
return b | ||
default: | ||
return make([]byte, MAX_ALLOCATION_SIZE) | ||
} | ||
} | ||
|
||
func (p *pool) put(b []byte) { | ||
select { | ||
case p.buffers <- b: | ||
default: | ||
// drop it | ||
} | ||
} |
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