Effectively revert 03c4092862

This is not mandated by spec.  Also it may work badly with Firefox
style dependency tree usage.
This commit is contained in:
Tatsuhiro Tsujikawa 2015-04-16 22:34:54 +09:00
parent 7323d4c639
commit 57644e0256
3 changed files with 20 additions and 78 deletions

View File

@ -63,7 +63,6 @@ void nghttp2_stream_init(nghttp2_stream *stream, int32_t stream_id,
stream->effective_weight = stream->weight; stream->effective_weight = stream->weight;
stream->sum_dep_weight = 0; stream->sum_dep_weight = 0;
stream->sum_norest_weight = 0; stream->sum_norest_weight = 0;
stream->sum_top_weight = 0;
stream->roots = roots; stream->roots = roots;
stream->root_prev = NULL; stream->root_prev = NULL;
@ -174,18 +173,6 @@ int32_t nghttp2_stream_dep_distributed_effective_weight(nghttp2_stream *stream,
return nghttp2_max(1, weight); return nghttp2_max(1, weight);
} }
static int32_t
stream_dep_distributed_top_effective_weight(nghttp2_stream *stream,
int32_t weight) {
if (stream->sum_top_weight == 0) {
return stream->effective_weight;
}
weight = stream->effective_weight * weight / stream->sum_top_weight;
return nghttp2_max(1, weight);
}
static void stream_update_dep_set_rest(nghttp2_stream *stream); static void stream_update_dep_set_rest(nghttp2_stream *stream);
/* Updates effective_weight of descendant streams in subtree of /* Updates effective_weight of descendant streams in subtree of
@ -195,10 +182,9 @@ static void stream_update_dep_effective_weight(nghttp2_stream *stream) {
nghttp2_stream *si; nghttp2_stream *si;
DEBUGF(fprintf(stderr, "stream: update_dep_effective_weight " DEBUGF(fprintf(stderr, "stream: update_dep_effective_weight "
"stream(%p)=%d, weight=%d, sum_norest_weight=%d, " "stream(%p)=%d, weight=%d, sum_norest_weight=%d\n",
"sum_top_weight=%d\n",
stream, stream->stream_id, stream->weight, stream, stream->stream_id, stream->weight,
stream->sum_norest_weight, stream->sum_top_weight)); stream->sum_norest_weight));
/* stream->sum_norest_weight == 0 means there is no /* stream->sum_norest_weight == 0 means there is no
NGHTTP2_STREAM_DPRI_TOP under stream */ NGHTTP2_STREAM_DPRI_TOP under stream */
@ -207,10 +193,6 @@ static void stream_update_dep_effective_weight(nghttp2_stream *stream) {
return; return;
} }
/* If there is no direct descendant whose dpri is
NGHTTP2_STREAM_DPRI_TOP, indirect descendants have the chance to
send data, so recursively set weight for descendants. */
if (stream->sum_top_weight == 0) {
for (si = stream->dep_next; si; si = si->sib_next) { for (si = stream->dep_next; si; si = si->sib_next) {
if (si->dpri != NGHTTP2_STREAM_DPRI_REST) { if (si->dpri != NGHTTP2_STREAM_DPRI_REST) {
si->effective_weight = si->effective_weight =
@ -219,36 +201,6 @@ static void stream_update_dep_effective_weight(nghttp2_stream *stream) {
stream_update_dep_effective_weight(si); stream_update_dep_effective_weight(si);
} }
return;
}
/* If there is at least one direct descendant whose dpri is
NGHTTP2_STREAM_DPRI_TOP, we won't give a chance to indirect
descendants, since closed or blocked stream's weight is
distributed among its siblings */
for (si = stream->dep_next; si; si = si->sib_next) {
if (si->dpri == NGHTTP2_STREAM_DPRI_TOP) {
si->effective_weight =
stream_dep_distributed_top_effective_weight(stream, si->weight);
DEBUGF(fprintf(stderr, "stream: stream=%d top eweight=%d\n",
si->stream_id, si->effective_weight));
continue;
}
if (si->dpri == NGHTTP2_STREAM_DPRI_NO_ITEM) {
DEBUGF(fprintf(stderr, "stream: stream=%d no_item, ignored\n",
si->stream_id));
/* Since we marked NGHTTP2_STREAM_DPRI_TOP under si, we make
them NGHTTP2_STREAM_DPRI_REST again. */
stream_update_dep_set_rest(si->dep_next);
} else {
DEBUGF(
fprintf(stderr, "stream: stream=%d rest, ignored\n", si->stream_id));
}
}
} }
static void stream_update_dep_set_rest(nghttp2_stream *stream) { static void stream_update_dep_set_rest(nghttp2_stream *stream) {
@ -343,25 +295,20 @@ static int stream_update_dep_queue_top(nghttp2_stream *stream,
} }
/* /*
* Updates stream->sum_norest_weight and stream->sum_top_weight * Updates stream->sum_norest_weight recursively. We have to gather
* recursively. We have to gather effective sum of weight of * effective sum of weight of descendants. If stream->dpri ==
* descendants. If stream->dpri == NGHTTP2_STREAM_DPRI_NO_ITEM, we * NGHTTP2_STREAM_DPRI_NO_ITEM, we have to go deeper and check that
* have to go deeper and check that any of its descendants has dpri * any of its descendants has dpri value of NGHTTP2_STREAM_DPRI_TOP.
* value of NGHTTP2_STREAM_DPRI_TOP. If so, we have to add weight of * If so, we have to add weight of its direct descendants to
* its direct descendants to stream->sum_norest_weight. To make this * stream->sum_norest_weight. To make this work, this function
* work, this function returns 1 if any of its descendants has dpri * returns 1 if any of its descendants has dpri value of
* value of NGHTTP2_STREAM_DPRI_TOP, otherwise 0. * NGHTTP2_STREAM_DPRI_TOP, otherwise 0.
*
* Calculating stream->sum_top_weight is very simple compared to
* stream->sum_norest_weight. It just adds up the weight of direct
* descendants whose dpri is NGHTTP2_STREAM_DPRI_TOP.
*/ */
static int stream_update_dep_sum_norest_weight(nghttp2_stream *stream) { static int stream_update_dep_sum_norest_weight(nghttp2_stream *stream) {
nghttp2_stream *si; nghttp2_stream *si;
int rv; int rv;
stream->sum_norest_weight = 0; stream->sum_norest_weight = 0;
stream->sum_top_weight = 0;
if (stream->dpri == NGHTTP2_STREAM_DPRI_TOP) { if (stream->dpri == NGHTTP2_STREAM_DPRI_TOP) {
return 1; return 1;
@ -379,10 +326,6 @@ static int stream_update_dep_sum_norest_weight(nghttp2_stream *stream) {
rv = 1; rv = 1;
stream->sum_norest_weight += si->weight; stream->sum_norest_weight += si->weight;
} }
if (si->dpri == NGHTTP2_STREAM_DPRI_TOP) {
stream->sum_top_weight += si->weight;
}
} }
return rv; return rv;

View File

@ -217,9 +217,6 @@ struct nghttp2_stream {
descendant with dpri == NGHTTP2_STREAM_DPRI_TOP. We use this descendant with dpri == NGHTTP2_STREAM_DPRI_TOP. We use this
value to calculate effective weight. */ value to calculate effective weight. */
int32_t sum_norest_weight; int32_t sum_norest_weight;
/* sum of weight of direct descendants whose dpri value is
NGHTTP2_STREAM_DPRI_TOP */
int32_t sum_top_weight;
nghttp2_stream_state state; nghttp2_stream_state state;
/* status code from remote server */ /* status code from remote server */
int16_t status_code; int16_t status_code;

View File

@ -6152,11 +6152,12 @@ void test_nghttp2_session_stream_attach_item(void) {
CU_ASSERT(NGHTTP2_STREAM_DPRI_NO_ITEM == a->dpri); CU_ASSERT(NGHTTP2_STREAM_DPRI_NO_ITEM == a->dpri);
CU_ASSERT(NGHTTP2_STREAM_DPRI_TOP == b->dpri); CU_ASSERT(NGHTTP2_STREAM_DPRI_TOP == b->dpri);
CU_ASSERT(NGHTTP2_STREAM_DPRI_NO_ITEM == c->dpri); CU_ASSERT(NGHTTP2_STREAM_DPRI_NO_ITEM == c->dpri);
CU_ASSERT(NGHTTP2_STREAM_DPRI_REST == d->dpri); CU_ASSERT(NGHTTP2_STREAM_DPRI_TOP == d->dpri);
CU_ASSERT(16 * 16 / 16 == b->effective_weight); CU_ASSERT(16 * 16 / 32 == b->effective_weight);
CU_ASSERT(16 * 16 / 32 == d->effective_weight);
CU_ASSERT(0 == dd->queued); CU_ASSERT(1 == dd->queued);
nghttp2_stream_detach_item(b, session); nghttp2_stream_detach_item(b, session);
@ -6322,12 +6323,13 @@ void test_nghttp2_session_stream_attach_item_subtree(void) {
CU_ASSERT(NGHTTP2_STREAM_DPRI_NO_ITEM == a->dpri); CU_ASSERT(NGHTTP2_STREAM_DPRI_NO_ITEM == a->dpri);
CU_ASSERT(NGHTTP2_STREAM_DPRI_TOP == b->dpri); CU_ASSERT(NGHTTP2_STREAM_DPRI_TOP == b->dpri);
CU_ASSERT(NGHTTP2_STREAM_DPRI_NO_ITEM == c->dpri); CU_ASSERT(NGHTTP2_STREAM_DPRI_NO_ITEM == c->dpri);
CU_ASSERT(NGHTTP2_STREAM_DPRI_REST == d->dpri); CU_ASSERT(NGHTTP2_STREAM_DPRI_TOP == d->dpri);
CU_ASSERT(NGHTTP2_STREAM_DPRI_TOP == e->dpri); CU_ASSERT(NGHTTP2_STREAM_DPRI_TOP == e->dpri);
CU_ASSERT(NGHTTP2_STREAM_DPRI_NO_ITEM == f->dpri); CU_ASSERT(NGHTTP2_STREAM_DPRI_NO_ITEM == f->dpri);
CU_ASSERT(16 == b->effective_weight); CU_ASSERT(16 == b->effective_weight);
CU_ASSERT(16 * 16 / 16 == e->effective_weight); CU_ASSERT(16 * 16 / 32 == e->effective_weight);
CU_ASSERT(16 * 16 / 32 == e->effective_weight);
CU_ASSERT(32 == a->sum_norest_weight); CU_ASSERT(32 == a->sum_norest_weight);
CU_ASSERT(16 == c->sum_norest_weight); CU_ASSERT(16 == c->sum_norest_weight);