Skip to content

Commit 08ea572

Browse files
committed
Make service unavailable while checking heap
1 parent 1665a37 commit 08ea572

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ func (t *transport) RoundTrip(request *http.Request) (*http.Response, error) {
100100
func (t *transport) checkHeap() {
101101
// This wait pending could occur only at GC time. It is here because
102102
// we don't the heap checking to interfere with the request processing.
103+
if !atomic.CompareAndSwapInt32(&t.isAvailable, 0, 1) {
104+
return
105+
}
103106
defer func() {
104107
atomic.StoreInt32(&t.isAvailable, 0)
105108
}()
@@ -173,6 +176,7 @@ func (t *transport) gc(gen generation) {
173176
ioutil.ReadAll(resp.Body)
174177
resp.Body.Close()
175178
}
179+
println("GC FINISHED: GEN", gen.string())
176180
}
177181

178182
////////// PROXY
@@ -216,6 +220,10 @@ func main() {
216220
tGen := flag.Uint64("tgen", 0, "Invalid tenured generation size.")
217221
flag.Parse()
218222

223+
if *yGen == 0 || *tGen == 0 {
224+
log.Fatalf("Neither ygen nor tgen can be 0. ygen:%d tgen:%d", *yGen, *tGen)
225+
}
226+
219227
proxy := newProxy(*redirectURL, *yGen, *tGen)
220228

221229
router := httprouter.New()
@@ -281,7 +289,7 @@ func randomSign(r *rand.Rand) int64 {
281289
////////// SAMPLE WINDOW
282290
const (
283291
// Default sample size should be fairly small, so big requests get checked up quickly.
284-
defaultSampleSize = uint64(64)
292+
defaultSampleSize = uint64(32)
285293
// Max sample size can not be very big because of peaks.
286294
// The algorithm is fairly conservative, but we never know.
287295
maxSampleSize = uint64(512)

0 commit comments

Comments
 (0)