Mitigate heap fragmentation when lots of concurrent http2 sessions run

This commit is contained in:
Tatsuhiro Tsujikawa 2014-03-02 16:32:07 +09:00
parent 6f0b9128b4
commit 979feaecc6
2 changed files with 27 additions and 25 deletions

View File

@ -26,7 +26,7 @@
int nghttp2_pq_init(nghttp2_pq *pq, nghttp2_compar compar) int nghttp2_pq_init(nghttp2_pq *pq, nghttp2_compar compar)
{ {
pq->capacity = 4096; pq->capacity = 128;
pq->q = malloc(pq->capacity * sizeof(void*)); pq->q = malloc(pq->capacity * sizeof(void*));
if(pq->q == NULL) { if(pq->q == NULL) {
return NGHTTP2_ERR_NOMEM; return NGHTTP2_ERR_NOMEM;

View File

@ -239,6 +239,28 @@ static int nghttp2_session_new(nghttp2_session **session_ptr,
/* next_stream_id is initialized in either /* next_stream_id is initialized in either
nghttp2_session_client_new2 or nghttp2_session_server_new2 */ nghttp2_session_client_new2 or nghttp2_session_server_new2 */
rv = nghttp2_pq_init(&(*session_ptr)->ob_pq, nghttp2_outbound_item_compar);
if(rv != 0) {
goto fail_ob_pq;
}
rv = nghttp2_pq_init(&(*session_ptr)->ob_ss_pq, nghttp2_outbound_item_compar);
if(rv != 0) {
goto fail_ob_ss_pq;
}
rv = nghttp2_hd_deflate_init(&(*session_ptr)->hd_deflater);
if(rv != 0) {
goto fail_hd_deflater;
}
rv = nghttp2_hd_inflate_init(&(*session_ptr)->hd_inflater);
if(rv != 0) {
goto fail_hd_inflater;
}
rv = nghttp2_map_init(&(*session_ptr)->streams);
if(rv != 0) {
goto fail_map;
}
(*session_ptr)->next_seq = 0; (*session_ptr)->next_seq = 0;
if((opt_set_mask & NGHTTP2_OPT_NO_AUTO_STREAM_WINDOW_UPDATE) && if((opt_set_mask & NGHTTP2_OPT_NO_AUTO_STREAM_WINDOW_UPDATE) &&
@ -267,26 +289,6 @@ static int nghttp2_session_new(nghttp2_session **session_ptr,
if(server) { if(server) {
(*session_ptr)->server = 1; (*session_ptr)->server = 1;
} }
rv = nghttp2_hd_deflate_init(&(*session_ptr)->hd_deflater);
if(rv != 0) {
goto fail_hd_deflater;
}
rv = nghttp2_hd_inflate_init(&(*session_ptr)->hd_inflater);
if(rv != 0) {
goto fail_hd_inflater;
}
rv = nghttp2_map_init(&(*session_ptr)->streams);
if(rv != 0) {
goto fail_map;
}
rv = nghttp2_pq_init(&(*session_ptr)->ob_pq, nghttp2_outbound_item_compar);
if(rv != 0) {
goto fail_ob_pq;
}
rv = nghttp2_pq_init(&(*session_ptr)->ob_ss_pq, nghttp2_outbound_item_compar);
if(rv != 0) {
goto fail_ob_ss_pq;
}
(*session_ptr)->aob.framebuf = malloc (*session_ptr)->aob.framebuf = malloc
(NGHTTP2_INITIAL_OUTBOUND_FRAMEBUF_LENGTH); (NGHTTP2_INITIAL_OUTBOUND_FRAMEBUF_LENGTH);
@ -318,16 +320,16 @@ static int nghttp2_session_new(nghttp2_session **session_ptr,
return 0; return 0;
fail_aob_framebuf: fail_aob_framebuf:
nghttp2_pq_free(&(*session_ptr)->ob_ss_pq);
fail_ob_ss_pq:
nghttp2_pq_free(&(*session_ptr)->ob_pq);
fail_ob_pq:
nghttp2_map_free(&(*session_ptr)->streams); nghttp2_map_free(&(*session_ptr)->streams);
fail_map: fail_map:
nghttp2_hd_inflate_free(&(*session_ptr)->hd_inflater); nghttp2_hd_inflate_free(&(*session_ptr)->hd_inflater);
fail_hd_inflater: fail_hd_inflater:
nghttp2_hd_deflate_free(&(*session_ptr)->hd_deflater); nghttp2_hd_deflate_free(&(*session_ptr)->hd_deflater);
fail_hd_deflater: fail_hd_deflater:
nghttp2_pq_free(&(*session_ptr)->ob_ss_pq);
fail_ob_ss_pq:
nghttp2_pq_free(&(*session_ptr)->ob_pq);
fail_ob_pq:
free(*session_ptr); free(*session_ptr);
fail_session: fail_session:
return rv; return rv;