Commit d1e49a19 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

Remove restriction in regard to number of stream in dependency tree

Previously, the number of stream in one dependency tree (not including
root) is limited to 120.  This is due to the fact that we use
recursive calls to traverse trees.  Now we replaced recursive calls
with loop, we can remove this limitation.  Also now all streams are
descendant of root stream, rather than linked list of individual
subtree root.
parent 8c8d1f6e
......@@ -350,7 +350,9 @@ static int session_new(nghttp2_session **session_ptr,
goto fail_map;
}
nghttp2_stream_roots_init(&(*session_ptr)->roots);
nghttp2_stream_init(&(*session_ptr)->root, 0, NGHTTP2_STREAM_FLAG_NONE,
NGHTTP2_STREAM_INITIAL, NGHTTP2_DEFAULT_WEIGHT, 0, 0,
NULL);
(*session_ptr)->remote_window_size = NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE;
(*session_ptr)->recv_window_size = 0;
......@@ -608,7 +610,7 @@ void nghttp2_session_del(nghttp2_session *session) {
settings = next;
}
nghttp2_stream_roots_free(&session->roots);
nghttp2_stream_free(&session->root);
/* Have to free streams first, so that we can check
stream->item->queued */
......@@ -633,7 +635,6 @@ nghttp2_session_reprioritize_stream(nghttp2_session *session,
const nghttp2_priority_spec *pri_spec_in) {
int rv;
nghttp2_stream *dep_stream = NULL;
nghttp2_stream *root_stream;
nghttp2_priority_spec pri_spec_default;
const nghttp2_priority_spec *pri_spec = pri_spec_in;
......@@ -665,32 +666,18 @@ nghttp2_session_reprioritize_stream(nghttp2_session *session,
}
if (pri_spec->stream_id == 0) {
nghttp2_stream_dep_remove_subtree(stream);
/* We have to update weight after removing stream from tree */
stream->weight = pri_spec->weight;
if (pri_spec->exclusive &&
session->roots.num_streams <= NGHTTP2_MAX_DEP_TREE_LENGTH) {
rv = nghttp2_stream_dep_all_your_stream_are_belong_to_us(stream, session);
} else {
rv = nghttp2_stream_dep_make_root(stream, session);
}
return rv;
}
assert(dep_stream);
if (nghttp2_stream_dep_subtree_find(stream, dep_stream)) {
dep_stream = &session->root;
} else if (nghttp2_stream_dep_subtree_find(stream, dep_stream)) {
DEBUGF(fprintf(stderr, "stream: cycle detected, dep_stream(%p)=%d "
"stream(%p)=%d\n",
dep_stream, dep_stream->stream_id, stream,
stream->stream_id));
nghttp2_stream_dep_remove_subtree(dep_stream);
nghttp2_stream_dep_make_root(dep_stream, session);
rv = nghttp2_stream_dep_add_subtree(&session->root, dep_stream, session);
if (rv != 0) {
return rv;
}
}
nghttp2_stream_dep_remove_subtree(stream);
......@@ -698,19 +685,10 @@ nghttp2_session_reprioritize_stream(nghttp2_session *session,
/* We have to update weight after removing stream from tree */
stream->weight = pri_spec->weight;
root_stream = nghttp2_stream_get_dep_root(dep_stream);
if (root_stream->num_substreams + stream->num_substreams >
NGHTTP2_MAX_DEP_TREE_LENGTH) {
stream->weight = NGHTTP2_DEFAULT_WEIGHT;
rv = nghttp2_stream_dep_make_root(stream, session);
if (pri_spec->exclusive) {
rv = nghttp2_stream_dep_insert_subtree(dep_stream, stream, session);
} else {
if (pri_spec->exclusive) {
rv = nghttp2_stream_dep_insert_subtree(dep_stream, stream, session);
} else {
rv = nghttp2_stream_dep_add_subtree(dep_stream, stream, session);
}
rv = nghttp2_stream_dep_add_subtree(dep_stream, stream, session);
}
if (rv != 0) {
......@@ -875,7 +853,6 @@ nghttp2_stream *nghttp2_session_open_stream(nghttp2_session *session,
int rv;
nghttp2_stream *stream;
nghttp2_stream *dep_stream = NULL;
nghttp2_stream *root_stream;
int stream_alloc = 0;
nghttp2_priority_spec pri_spec_default;
nghttp2_priority_spec *pri_spec = pri_spec_in;
......@@ -936,10 +913,10 @@ nghttp2_stream *nghttp2_session_open_stream(nghttp2_session *session,
flags |= NGHTTP2_STREAM_FLAG_PUSH;
}
nghttp2_stream_init(
stream, stream_id, flags, initial_state, pri_spec->weight,
&session->roots, session->remote_settings.initial_window_size,
session->local_settings.initial_window_size, stream_user_data);
nghttp2_stream_init(stream, stream_id, flags, initial_state, pri_spec->weight,
session->remote_settings.initial_window_size,
session->local_settings.initial_window_size,
stream_user_data);
if (stream_alloc) {
rv = nghttp2_map_insert(&session->streams, &stream->map_entry);
......@@ -980,42 +957,20 @@ nghttp2_stream *nghttp2_session_open_stream(nghttp2_session *session,
return stream;
}
if (pri_spec->stream_id == 0) {
++session->roots.num_streams;
if (pri_spec->exclusive &&
session->roots.num_streams <= NGHTTP2_MAX_DEP_TREE_LENGTH) {
rv = nghttp2_stream_dep_all_your_stream_are_belong_to_us(stream, session);
/* Since no dpri is changed in dependency tree, the above
function call never fail. */
assert(rv == 0);
} else {
nghttp2_stream_roots_add(&session->roots, stream);
}
return stream;
}
/* TODO Client does not have to track dependencies of streams except
for those which have upload data. Currently, we just track
everything. */
assert(dep_stream);
if (pri_spec->stream_id == 0) {
dep_stream = &session->root;
}
root_stream = nghttp2_stream_get_dep_root(dep_stream);
assert(dep_stream);
if (root_stream->num_substreams < NGHTTP2_MAX_DEP_TREE_LENGTH) {
if (pri_spec->exclusive) {
nghttp2_stream_dep_insert(dep_stream, stream);
} else {
nghttp2_stream_dep_add(dep_stream, stream);
}
if (pri_spec->exclusive) {
nghttp2_stream_dep_insert(dep_stream, stream);
} else {
stream->weight = NGHTTP2_DEFAULT_WEIGHT;
nghttp2_stream_roots_add(&session->roots, stream);
nghttp2_stream_dep_add(dep_stream, stream);
}
return stream;
......@@ -1107,7 +1062,9 @@ void nghttp2_session_destroy_stream(nghttp2_session *session,
mem = &session->mem;
nghttp2_stream_dep_remove(stream);
if (nghttp2_stream_in_dep_tree(stream)) {
nghttp2_stream_dep_remove(stream);
}
nghttp2_map_remove(&session->streams, stream->stream_id);
nghttp2_stream_free(stream);
......
......@@ -153,7 +153,8 @@ typedef struct nghttp2_inflight_settings nghttp2_inflight_settings;
struct nghttp2_session {
nghttp2_map /* <nghttp2_stream*> */ streams;
nghttp2_stream_roots roots;
/* root of dependency tree*/
nghttp2_stream root;
/* Queue for outbound urgent frames (PING and SETTINGS) */
nghttp2_outbound_queue ob_urgent;
/* Queue for non-DATA frames */
......
This diff is collapsed.
......@@ -35,11 +35,6 @@
#include "nghttp2_pq.h"
#include "nghttp2_int.h"
/*
* Maximum number of streams in one dependency tree.
*/
#define NGHTTP2_MAX_DEP_TREE_LENGTH 120
/*
* If local peer is stream initiator:
* NGHTTP2_STREAM_OPENING : upon sending request HEADERS
......@@ -167,17 +162,11 @@ struct nghttp2_stream {
dep_prev and sib_prev are NULL. */
nghttp2_stream *dep_prev, *dep_next;
nghttp2_stream *sib_prev, *sib_next;
/* pointers to track dependency tree root streams. This is
doubly-linked list and first element is pointed by
roots->head. */
nghttp2_stream *root_prev, *root_next;
/* When stream is kept after closure, it may be kept in doubly
linked list pointed by nghttp2_session closed_stream_head.
closed_next points to the next stream object if it is the element
of the list. */
nghttp2_stream *closed_prev, *closed_next;
/* pointer to roots, which tracks dependency tree roots */
nghttp2_stream_roots *roots;
/* The arbitrary data provided by user for this stream. */
void *stream_user_data;
/* Item to send */
......@@ -187,8 +176,6 @@ struct nghttp2_stream {
/* categorized priority of this stream. Only stream bearing
NGHTTP2_STREAM_DPRI_TOP can send item. */
nghttp2_stream_dpri dpri;
/* the number of streams in subtree */
size_t num_substreams;
/* Current remote window size. This value is computed against the
current initial window size of remote endpoint. */
int32_t remote_window_size;
......@@ -231,8 +218,7 @@ struct nghttp2_stream {
void nghttp2_stream_init(nghttp2_stream *stream, int32_t stream_id,
uint8_t flags, nghttp2_stream_state initial_state,
int32_t weight, nghttp2_stream_roots *roots,
int32_t remote_initial_window_size,
int32_t weight, int32_t remote_initial_window_size,
int32_t local_initial_window_size,
void *stream_user_data);
......@@ -425,54 +411,9 @@ int nghttp2_stream_dep_add_subtree(nghttp2_stream *dep_stream,
*/
void nghttp2_stream_dep_remove_subtree(nghttp2_stream *stream);
/*
* Makes the |stream| as root. Updates dpri members in this
* dependency tree.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* NGHTTP2_ERR_NOMEM
* Out of memory
*/
int nghttp2_stream_dep_make_root(nghttp2_stream *stream,
nghttp2_session *session);
/*
* Makes the |stream| as root and all existing root streams become
* direct children of |stream|.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* NGHTTP2_ERR_NOMEM
* Out of memory
*/
int
nghttp2_stream_dep_all_your_stream_are_belong_to_us(nghttp2_stream *stream,
nghttp2_session *session);
/*
* Returns nonzero if |stream| is in any dependency tree.
*/
int nghttp2_stream_in_dep_tree(nghttp2_stream *stream);
struct nghttp2_stream_roots {
nghttp2_stream *head;
int32_t num_streams;
};
void nghttp2_stream_roots_init(nghttp2_stream_roots *roots);
void nghttp2_stream_roots_free(nghttp2_stream_roots *roots);
void nghttp2_stream_roots_add(nghttp2_stream_roots *roots,
nghttp2_stream *stream);
void nghttp2_stream_roots_remove(nghttp2_stream_roots *roots,
nghttp2_stream *stream);
void nghttp2_stream_roots_remove_all(nghttp2_stream_roots *roots);
#endif /* NGHTTP2_STREAM */
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment