Skip to content

Commit

Permalink
Latest changes
Browse files Browse the repository at this point in the history
- [API Change] Sendfile-like functionality is gone.  The stream no
  longer opens files and deals with file descriptors.  (Among other
  things, this makes the code more portable.)  Three writing functions
  are provided:

    lsquic_stream_write
    lsquic_stream_writev
    lsquic_stream_writef    (NEW)

  lsquic_stream_writef() is given an abstract reader that has function
  pointers for size() and read() functions which the user can implement.
  This is the most flexible way.  lsquic_stream_write() and
  lsquic_stream_writev() are now both implemented as wrappers around
  lsquic_stream_writef().

- [OPTIMIZATION] When writing to stream, be it within or without the
  on_write() callback, place data directly into packet buffer,
  bypassing auxiliary data structures.  This reduces amount of memory
  required, for the amount of data that can be written is limited
  by the congestion window.

  To support writes outside the on_write() callback, we keep N
  outgoing packet buffers per connection which can be written to
  by any stream.  One half of these are reserved for the highest
  priority stream(s), the other half for all other streams.  This way,
  low-priority streams cannot write instead of high-priority streams
  and, on the other hand, low-priority streams get a chance to send
  their packets out.

  The algorithm is as follows:

  - When user writes to stream outside of the callback:
    - If this is the highest priority stream, place it onto the
      reserved N/2 queue or fail.
        (The actual size of this queue is dynamic -- MAX(N/2, CWND) --
         rather than N/2, allowing high-priority streams to write as
         much as can be sent.)
    - If the stream is not the highest priority, try to place the
      data onto the reserved N/2 queue or fail.
  - When tick occurs *and* more packets can be scheduled:
    - Transfer packets from the high N/2 queue to the scheduled
      queue.
    - If more scheduling is allowed:
      - Call on_write callbacks for highest-priority streams,
        placing resulting packets directly onto the scheduled queue.
    - If more scheduling is allowed:
      - Transfer packets from the low N/2 queue to the scheduled
        queue.
    - If more scheduling is allowed:
      - Call on_write callbacks for non-highest-priority streams,
        placing resulting packets directly onto the scheduled queue

  The number N is currently 20, but it could be varied based on
  resource usage.

- If stream is created due to incoming headers, make headers readable
  from on_new.

- Outgoing packets are no longer marked non-writeable to prevent placing
  more than one STREAM frame from the same stream into a single packet.
  This property is maintained via code flow and an explicit check.
  Packets for stream data are allocated using a special function.

- STREAM frame elision is cheaper, as we only perform it if a reset
  stream has outgoing packets referencing it.

- lsquic_packet_out_t is smaller, as stream_rec elements are now
  inside a union.
  • Loading branch information
Dmitri Tikhonov committed Oct 31, 2017
1 parent 0ae3fcc commit c51ce33
Show file tree
Hide file tree
Showing 94 changed files with 4,746 additions and 3,298 deletions.
71 changes: 71 additions & 0 deletions CHANGELOG
@@ -1,3 +1,74 @@
2017-10-31

- [API Change] Sendfile-like functionality is gone. The stream no
longer opens files and deals with file descriptors. (Among other
things, this makes the code more portable.) Three writing functions
are provided:

lsquic_stream_write
lsquic_stream_writev
lsquic_stream_writef (NEW)

lsquic_stream_writef() is given an abstract reader that has function
pointers for size() and read() functions which the user can implement.
This is the most flexible way. lsquic_stream_write() and
lsquic_stream_writev() are now both implemented as wrappers around
lsquic_stream_writef().

- [OPTIMIZATION] When writing to stream, be it within or without the
on_write() callback, place data directly into packet buffer,
bypassing auxiliary data structures. This reduces amount of memory
required, for the amount of data that can be written is limited
by the congestion window.

To support writes outside the on_write() callback, we keep N
outgoing packet buffers per connection which can be written to
by any stream. One half of these are reserved for the highest
priority stream(s), the other half for all other streams. This way,
low-priority streams cannot write instead of high-priority streams
and, on the other hand, low-priority streams get a chance to send
their packets out.

The algorithm is as follows:

- When user writes to stream outside of the callback:
- If this is the highest priority stream, place it onto the
reserved N/2 queue or fail.
(The actual size of this queue is dynamic -- MAX(N/2, CWND) --
rather than N/2, allowing high-priority streams to write as
much as can be sent.)
- If the stream is not the highest priority, try to place the
data onto the reserved N/2 queue or fail.
- When tick occurs *and* more packets can be scheduled:
- Transfer packets from the high N/2 queue to the scheduled
queue.
- If more scheduling is allowed:
- Call on_write callbacks for highest-priority streams,
placing resulting packets directly onto the scheduled queue.
- If more scheduling is allowed:
- Transfer packets from the low N/2 queue to the scheduled
queue.
- If more scheduling is allowed:
- Call on_write callbacks for non-highest-priority streams,
placing resulting packets directly onto the scheduled queue

The number N is currently 20, but it could be varied based on
resource usage.

- If stream is created due to incoming headers, make headers readable
from on_new.

- Outgoing packets are no longer marked non-writeable to prevent placing
more than one STREAM frame from the same stream into a single packet.
This property is maintained via code flow and an explicit check.
Packets for stream data are allocated using a special function.

- STREAM frame elision is cheaper, as we only perform it if a reset
stream has outgoing packets referencing it.

- lsquic_packet_out_t is smaller, as stream_rec elements are now
inside a union.

2017-10-12

- Do not send RST_STREAM when stream is closed for reading
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Expand Up @@ -81,7 +81,11 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
link_directories( /usr/local/lib )
ENDIF()

add_executable(http_client test/http_client.c test/prog.c test/test_common.c test/test_cert.c)
add_executable(http_client
test/http_client.c
test/prog.c
test/test_common.c
)

target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} z m)

Expand Down
3 changes: 2 additions & 1 deletion docs/html/annotated.html
Expand Up @@ -94,7 +94,8 @@
<tr id="row_4_" class="even"><td class="entry"><span style="width:16px;display:inline-block;">&#160;</span><span class="icona"><span class="icon">C</span></span><a class="el" href="structlsquic__logger__if.html" target="_self">lsquic_logger_if</a></td><td class="desc"></td></tr>
<tr id="row_5_"><td class="entry"><span style="width:16px;display:inline-block;">&#160;</span><span class="icona"><span class="icon">C</span></span><a class="el" href="structlsquic__out__spec.html" target="_self">lsquic_out_spec</a></td><td class="desc"></td></tr>
<tr id="row_6_" class="even"><td class="entry"><span style="width:16px;display:inline-block;">&#160;</span><span class="icona"><span class="icon">C</span></span><a class="el" href="structlsquic__packout__mem__if.html" target="_self">lsquic_packout_mem_if</a></td><td class="desc"></td></tr>
<tr id="row_7_"><td class="entry"><span style="width:16px;display:inline-block;">&#160;</span><span class="icona"><span class="icon">C</span></span><a class="el" href="structlsquic__stream__if.html" target="_self">lsquic_stream_if</a></td><td class="desc">The definition of callback functions call by lsquic_stream to process events </td></tr>
<tr id="row_7_"><td class="entry"><span style="width:16px;display:inline-block;">&#160;</span><span class="icona"><span class="icon">C</span></span><a class="el" href="structlsquic__reader.html" target="_self">lsquic_reader</a></td><td class="desc"></td></tr>
<tr id="row_8_" class="even"><td class="entry"><span style="width:16px;display:inline-block;">&#160;</span><span class="icona"><span class="icon">C</span></span><a class="el" href="structlsquic__stream__if.html" target="_self">lsquic_stream_if</a></td><td class="desc">The definition of callback functions call by lsquic_stream to process events </td></tr>
</table>
</div><!-- directory -->
</div><!-- contents -->
Expand Down
8 changes: 4 additions & 4 deletions docs/html/classes.html
Expand Up @@ -88,10 +88,10 @@
<div class="qindex"><a class="qindex" href="#letter_L">L</a></div>
<table class="classindex">
<tr><td rowspan="2" valign="bottom"><a name="letter_l"></a><table border="0" cellspacing="0" cellpadding="0"><tr><td><div class="ah">&#160;&#160;l&#160;&#160;</div></td></tr></table>
</td><td valign="top"><a class="el" href="structlsquic__engine__settings.html">lsquic_engine_settings</a>&#160;&#160;&#160;</td><td valign="top"><a class="el" href="structlsquic__http__headers.html">lsquic_http_headers</a>&#160;&#160;&#160;</td><td valign="top"><a class="el" href="structlsquic__out__spec.html">lsquic_out_spec</a>&#160;&#160;&#160;</td><td valign="top"><a class="el" href="structlsquic__stream__if.html">lsquic_stream_if</a>&#160;&#160;&#160;</td></tr>
<tr><td valign="top"><a class="el" href="structlsquic__http__header.html">lsquic_http_header</a>&#160;&#160;&#160;</td><td valign="top"><a class="el" href="structlsquic__logger__if.html">lsquic_logger_if</a>&#160;&#160;&#160;</td><td valign="top"><a class="el" href="structlsquic__packout__mem__if.html">lsquic_packout_mem_if</a>&#160;&#160;&#160;</td><td></td></tr>
<tr><td valign="top"><a class="el" href="structlsquic__engine__api.html">lsquic_engine_api</a>&#160;&#160;&#160;</td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td></tr>
</td><td valign="top"><a class="el" href="structlsquic__engine__settings.html">lsquic_engine_settings</a>&#160;&#160;&#160;</td><td valign="top"><a class="el" href="structlsquic__logger__if.html">lsquic_logger_if</a>&#160;&#160;&#160;</td><td valign="top"><a class="el" href="structlsquic__reader.html">lsquic_reader</a>&#160;&#160;&#160;</td></tr>
<tr><td valign="top"><a class="el" href="structlsquic__http__header.html">lsquic_http_header</a>&#160;&#160;&#160;</td><td valign="top"><a class="el" href="structlsquic__out__spec.html">lsquic_out_spec</a>&#160;&#160;&#160;</td><td valign="top"><a class="el" href="structlsquic__stream__if.html">lsquic_stream_if</a>&#160;&#160;&#160;</td></tr>
<tr><td valign="top"><a class="el" href="structlsquic__engine__api.html">lsquic_engine_api</a>&#160;&#160;&#160;</td><td valign="top"><a class="el" href="structlsquic__http__headers.html">lsquic_http_headers</a>&#160;&#160;&#160;</td><td valign="top"><a class="el" href="structlsquic__packout__mem__if.html">lsquic_packout_mem_if</a>&#160;&#160;&#160;</td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
</table>
<div class="qindex"><a class="qindex" href="#letter_L">L</a></div>
</div><!-- contents -->
Expand Down
6 changes: 6 additions & 0 deletions docs/html/functions.html
Expand Up @@ -151,6 +151,12 @@
<li>es_versions
: <a class="el" href="structlsquic__engine__settings.html#a9dca1ee29ab43ca9454b6b0a8d5e2799">lsquic_engine_settings</a>
</li>
<li>lsqr_read
: <a class="el" href="structlsquic__reader.html#ae6a68ebf2a1fb77160b0bac599d42790">lsquic_reader</a>
</li>
<li>lsqr_size
: <a class="el" href="structlsquic__reader.html#aaf6c91ecaf35ca6faa39dde9ea401f17">lsquic_reader</a>
</li>
<li>on_goaway_received
: <a class="el" href="structlsquic__stream__if.html#afdab3bce65931517452d2ddd979596d7">lsquic_stream_if</a>
</li>
Expand Down
6 changes: 6 additions & 0 deletions docs/html/functions_vars.html
Expand Up @@ -151,6 +151,12 @@
<li>es_versions
: <a class="el" href="structlsquic__engine__settings.html#a9dca1ee29ab43ca9454b6b0a8d5e2799">lsquic_engine_settings</a>
</li>
<li>lsqr_read
: <a class="el" href="structlsquic__reader.html#ae6a68ebf2a1fb77160b0bac599d42790">lsquic_reader</a>
</li>
<li>lsqr_size
: <a class="el" href="structlsquic__reader.html#aaf6c91ecaf35ca6faa39dde9ea401f17">lsquic_reader</a>
</li>
<li>on_goaway_received
: <a class="el" href="structlsquic__stream__if.html#afdab3bce65931517452d2ddd979596d7">lsquic_stream_if</a>
</li>
Expand Down
13 changes: 5 additions & 8 deletions docs/html/globals.html
Expand Up @@ -278,6 +278,9 @@ <h3><a class="anchor" id="index_l"></a>- l -</h3><ul>
<li>lsquic_stream_ctx_t
: <a class="el" href="lsquic__types_8h.html#a4012fdeb11382d691dfe5f025206b8f3">lsquic_types.h</a>
</li>
<li>lsquic_stream_flush()
: <a class="el" href="lsquic_8h.html#abcf25d8301c4a2796ea13e6e306a33a9">lsquic.h</a>
</li>
<li>lsquic_stream_get_ctx()
: <a class="el" href="lsquic_8h.html#a26335cffe38e49a6e87d94967371150d">lsquic.h</a>
</li>
Expand All @@ -296,9 +299,6 @@ <h3><a class="anchor" id="index_l"></a>- l -</h3><ul>
<li>lsquic_stream_refuse_push()
: <a class="el" href="lsquic_8h.html#ada61e01ced7a7db11e5c503409c565be">lsquic.h</a>
</li>
<li>lsquic_stream_sendfile()
: <a class="el" href="lsquic_8h.html#a1700c950ace4e560d225b474a5e44d58">lsquic.h</a>
</li>
<li>lsquic_stream_set_priority()
: <a class="el" href="lsquic_8h.html#aa5e0ddfd53a44561248a286caacbd114">lsquic.h</a>
</li>
Expand All @@ -311,11 +311,8 @@ <h3><a class="anchor" id="index_l"></a>- l -</h3><ul>
<li>lsquic_stream_write()
: <a class="el" href="lsquic_8h.html#a1071b7be4f2f28c5fedf957aa6309f9a">lsquic.h</a>
</li>
<li>lsquic_stream_write_avail()
: <a class="el" href="lsquic_8h.html#a97229544d7aaf6c5dcd5e071613f9c8f">lsquic.h</a>
</li>
<li>lsquic_stream_write_file()
: <a class="el" href="lsquic_8h.html#af5b85bb360eb8316fd663d7c5bc149c9">lsquic.h</a>
<li>lsquic_stream_writef()
: <a class="el" href="lsquic_8h.html#a49f11caabdf3638d3a3217ebdd21c3af">lsquic.h</a>
</li>
<li>LSQUIC_SUPPORTED_VERSIONS
: <a class="el" href="lsquic_8h.html#a0420e68d347462080cf2e583b77d61a0">lsquic.h</a>
Expand Down
13 changes: 5 additions & 8 deletions docs/html/globals_func.html
Expand Up @@ -188,6 +188,9 @@ <h3><a class="anchor" id="index_l"></a>- l -</h3><ul>
<li>lsquic_stream_conn()
: <a class="el" href="lsquic_8h.html#a177184b3d7178dda5a3e95e539230b2b">lsquic.h</a>
</li>
<li>lsquic_stream_flush()
: <a class="el" href="lsquic_8h.html#abcf25d8301c4a2796ea13e6e306a33a9">lsquic.h</a>
</li>
<li>lsquic_stream_get_ctx()
: <a class="el" href="lsquic_8h.html#a26335cffe38e49a6e87d94967371150d">lsquic.h</a>
</li>
Expand All @@ -206,9 +209,6 @@ <h3><a class="anchor" id="index_l"></a>- l -</h3><ul>
<li>lsquic_stream_refuse_push()
: <a class="el" href="lsquic_8h.html#ada61e01ced7a7db11e5c503409c565be">lsquic.h</a>
</li>
<li>lsquic_stream_sendfile()
: <a class="el" href="lsquic_8h.html#a1700c950ace4e560d225b474a5e44d58">lsquic.h</a>
</li>
<li>lsquic_stream_set_priority()
: <a class="el" href="lsquic_8h.html#aa5e0ddfd53a44561248a286caacbd114">lsquic.h</a>
</li>
Expand All @@ -218,11 +218,8 @@ <h3><a class="anchor" id="index_l"></a>- l -</h3><ul>
<li>lsquic_stream_write()
: <a class="el" href="lsquic_8h.html#a1071b7be4f2f28c5fedf957aa6309f9a">lsquic.h</a>
</li>
<li>lsquic_stream_write_avail()
: <a class="el" href="lsquic_8h.html#a97229544d7aaf6c5dcd5e071613f9c8f">lsquic.h</a>
</li>
<li>lsquic_stream_write_file()
: <a class="el" href="lsquic_8h.html#af5b85bb360eb8316fd663d7c5bc149c9">lsquic.h</a>
<li>lsquic_stream_writef()
: <a class="el" href="lsquic_8h.html#a49f11caabdf3638d3a3217ebdd21c3af">lsquic.h</a>
</li>
</ul>
</div><!-- contents -->
Expand Down

0 comments on commit c51ce33

Please sign in to comment.