==========================================
Priority: A HTTP/2 Priority Implementation
==========================================
.. image:: https://github.com/python-hyper/priority/workflows/CI/badge.svg
:target: https://github.com/python-hyper/priority/actions
:alt: Build Status
.. image:: https://codecov.io/gh/python-hyper/priority/branch/master/graph/badge.svg
:target: https://codecov.io/gh/python-hyper/priority
:alt: Code Coverage
.. image:: https://readthedocs.org/projects/priority/badge/?version=latest
:target: https://priority.readthedocs.io/en/latest/
:alt: Documentation Status
.. image:: https://img.shields.io/badge/chat-join_now-brightgreen.svg
:target: https://gitter.im/python-hyper/community
:alt: Chat community
.. image:: https://raw.github.com/python-hyper/documentation/master/source/logo/hyper-black-bg-white.png
Priority is a pure-Python implementation of the priority logic for HTTP/2, set
out in `RFC 7540 Section 5.3 (Stream Priority)`_. This logic allows for clients
to express a preference for how the server allocates its (limited) resources to
the many outstanding HTTP requests that may be running over a single HTTP/2
connection.
Specifically, this Python implementation uses a variant of the implementation
used in the excellent `H2O`_ project. This original implementation is also the
inspiration for `nghttp2's`_ priority implementation, and generally produces a
very clean and even priority stream. The only notable changes from H2O's
implementation are small modifications to allow the priority implementation to
work cleanly as a separate implementation, rather than being embedded in a
HTTP/2 stack directly.
While priority information in HTTP/2 is only a suggestion, rather than an
enforceable constraint, where possible servers should respect the priority
requests of their clients.
Using Priority
--------------
Priority has a simple API. Streams are inserted into the tree: when they are
inserted, they may optionally have a weight, depend on another stream, or
become an exclusive dependent of another stream.
.. code-block:: python
>>> p = priority.PriorityTree()
>>> p.insert_stream(stream_id=1)
>>> p.insert_stream(stream_id=3)
>>> p.insert_stream(stream_id=5, depends_on=1)
>>> p.insert_stream(stream_id=7, weight=32)
>>> p.insert_stream(stream_id=9, depends_on=7, weight=8)
>>> p.insert_stream(stream_id=11, depends_on=7, exclusive=True)
Once streams are inserted, the stream priorities can be requested. This allows
the server to make decisions about how to allocate resources.
Iterating The Tree
~~~~~~~~~~~~~~~~~~
The tree in this algorithm acts as a gate. Its goal is to allow one stream
"through" at a time, in such a manner that all the active streams are served as
evenly as possible in proportion to their weights.
This is handled in Priority by iterating over the tree. The tree itself is an
iterator, and each time it is advanced it will yield a stream ID. This is the
ID of the stream that should next send data.
This looks like this:
.. code-block:: python
>>> for stream_id in p:
... send_data(stream_id)
If each stream only sends when it is 'ungated' by this mechanism, the server
will automatically be emitting stream data in conformance to RFC 7540.
Updating The Tree
~~~~~~~~~~~~~~~~~
If for any reason a stream is unable to proceed (for example, it is blocked on
HTTP/2 flow control, or it is waiting for more data from another service), that
stream is *blocked*. The ``PriorityTree`` should be informed that the stream is
blocked so that other dependent streams get a chance to proceed. This can be
done by calling the ``block`` method of the tree with the stream ID that is
currently unable to proceed. This will automatically update the tree, and it
will adjust on the fly to correctly allow any streams that were dependent on
the blocked one to progress.
For example:
.. code-block:: python
>>> for stream_id in p:
... send_data(stream_id)
... if blocked(stream_id):
... p.block(stream_id)
When a stream goes from being blocked to being unblocked, call the ``unblock``
method to place it back into the sequence. Both the ``block`` and ``unblock``
methods are idempotent and safe to call repeatedly.
Additionally, the priority of a stream may change. When it does, the
``reprioritize`` method can be used to update the tree in the wake of that
change. ``reprioritize`` has the same signature as ``insert_stream``, but
applies only to streams already in the tree.
Removing Streams
~~~~~~~~~~~~~~~~
A stream can be entirely removed from the tree by calling ``remove_stream``.
Note that this is not idempotent. Further, calling ``remove_stream`` and then
re-adding it *may* cause a substantial change in the shape of the priority
tree, and *will* cause the iteration order to change.
License
-------
Priority is made available under the MIT License. For more details, see the
LICENSE file in the repository.
Authors
-------
Priority is maintained by Cory Benfield, with contributions from others. For
more details about the contributors, please see CONTRIBUTORS.rst in the
repository.
.. _RFC 7540 Section 5.3 (Stream Priority): https://tools.ietf.org/html/rfc7540#section-5.3
.. _nghttp2's: https://nghttp2.org/blog/2015/11/11/stream-scheduling-utilizing-http2-priority/
.. _H2O: https://h2o.examp1e.net/
Raw data
{
"_id": null,
"home_page": "https://github.com/python-hyper/priority/",
"name": "priority",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6.1",
"maintainer_email": "",
"keywords": "",
"author": "Cory Benfield",
"author_email": "cory@lukasa.co.uk",
"download_url": "https://files.pythonhosted.org/packages/f5/3c/eb7c35f4dcede96fca1842dac5f4f5d15511aa4b52f3a961219e68ae9204/priority-2.0.0.tar.gz",
"platform": "",
"description": "==========================================\nPriority: A HTTP/2 Priority Implementation\n==========================================\n\n.. image:: https://github.com/python-hyper/priority/workflows/CI/badge.svg\n :target: https://github.com/python-hyper/priority/actions\n :alt: Build Status\n.. image:: https://codecov.io/gh/python-hyper/priority/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/python-hyper/priority\n :alt: Code Coverage\n.. image:: https://readthedocs.org/projects/priority/badge/?version=latest\n :target: https://priority.readthedocs.io/en/latest/\n :alt: Documentation Status\n.. image:: https://img.shields.io/badge/chat-join_now-brightgreen.svg\n :target: https://gitter.im/python-hyper/community\n :alt: Chat community\n\n.. image:: https://raw.github.com/python-hyper/documentation/master/source/logo/hyper-black-bg-white.png\n\n\nPriority is a pure-Python implementation of the priority logic for HTTP/2, set\nout in `RFC 7540 Section 5.3 (Stream Priority)`_. This logic allows for clients\nto express a preference for how the server allocates its (limited) resources to\nthe many outstanding HTTP requests that may be running over a single HTTP/2\nconnection.\n\nSpecifically, this Python implementation uses a variant of the implementation\nused in the excellent `H2O`_ project. This original implementation is also the\ninspiration for `nghttp2's`_ priority implementation, and generally produces a\nvery clean and even priority stream. The only notable changes from H2O's\nimplementation are small modifications to allow the priority implementation to\nwork cleanly as a separate implementation, rather than being embedded in a\nHTTP/2 stack directly.\n\nWhile priority information in HTTP/2 is only a suggestion, rather than an\nenforceable constraint, where possible servers should respect the priority\nrequests of their clients.\n\nUsing Priority\n--------------\n\nPriority has a simple API. Streams are inserted into the tree: when they are\ninserted, they may optionally have a weight, depend on another stream, or\nbecome an exclusive dependent of another stream.\n\n.. code-block:: python\n\n >>> p = priority.PriorityTree()\n >>> p.insert_stream(stream_id=1)\n >>> p.insert_stream(stream_id=3)\n >>> p.insert_stream(stream_id=5, depends_on=1)\n >>> p.insert_stream(stream_id=7, weight=32)\n >>> p.insert_stream(stream_id=9, depends_on=7, weight=8)\n >>> p.insert_stream(stream_id=11, depends_on=7, exclusive=True)\n\nOnce streams are inserted, the stream priorities can be requested. This allows\nthe server to make decisions about how to allocate resources.\n\nIterating The Tree\n~~~~~~~~~~~~~~~~~~\n\nThe tree in this algorithm acts as a gate. Its goal is to allow one stream\n\"through\" at a time, in such a manner that all the active streams are served as\nevenly as possible in proportion to their weights.\n\nThis is handled in Priority by iterating over the tree. The tree itself is an\niterator, and each time it is advanced it will yield a stream ID. This is the\nID of the stream that should next send data.\n\nThis looks like this:\n\n.. code-block:: python\n\n >>> for stream_id in p:\n ... send_data(stream_id)\n\nIf each stream only sends when it is 'ungated' by this mechanism, the server\nwill automatically be emitting stream data in conformance to RFC 7540.\n\nUpdating The Tree\n~~~~~~~~~~~~~~~~~\n\nIf for any reason a stream is unable to proceed (for example, it is blocked on\nHTTP/2 flow control, or it is waiting for more data from another service), that\nstream is *blocked*. The ``PriorityTree`` should be informed that the stream is\nblocked so that other dependent streams get a chance to proceed. This can be\ndone by calling the ``block`` method of the tree with the stream ID that is\ncurrently unable to proceed. This will automatically update the tree, and it\nwill adjust on the fly to correctly allow any streams that were dependent on\nthe blocked one to progress.\n\nFor example:\n\n.. code-block:: python\n\n >>> for stream_id in p:\n ... send_data(stream_id)\n ... if blocked(stream_id):\n ... p.block(stream_id)\n\nWhen a stream goes from being blocked to being unblocked, call the ``unblock``\nmethod to place it back into the sequence. Both the ``block`` and ``unblock``\nmethods are idempotent and safe to call repeatedly.\n\nAdditionally, the priority of a stream may change. When it does, the\n``reprioritize`` method can be used to update the tree in the wake of that\nchange. ``reprioritize`` has the same signature as ``insert_stream``, but\napplies only to streams already in the tree.\n\nRemoving Streams\n~~~~~~~~~~~~~~~~\n\nA stream can be entirely removed from the tree by calling ``remove_stream``.\nNote that this is not idempotent. Further, calling ``remove_stream`` and then\nre-adding it *may* cause a substantial change in the shape of the priority\ntree, and *will* cause the iteration order to change.\n\nLicense\n-------\n\nPriority is made available under the MIT License. For more details, see the\nLICENSE file in the repository.\n\nAuthors\n-------\n\nPriority is maintained by Cory Benfield, with contributions from others. For\nmore details about the contributors, please see CONTRIBUTORS.rst in the\nrepository.\n\n\n.. _RFC 7540 Section 5.3 (Stream Priority): https://tools.ietf.org/html/rfc7540#section-5.3\n.. _nghttp2's: https://nghttp2.org/blog/2015/11/11/stream-scheduling-utilizing-http2-priority/\n.. _H2O: https://h2o.examp1e.net/\n\n\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "A pure-Python implementation of the HTTP/2 priority tree",
"version": "2.0.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "4b37219b8468723cfe978a541b941a7b",
"sha256": "6f8eefce5f3ad59baf2c080a664037bb4725cd0a790d53d59ab4059288faf6aa"
},
"downloads": -1,
"filename": "priority-2.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4b37219b8468723cfe978a541b941a7b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6.1",
"size": 8946,
"upload_time": "2021-06-27T10:15:03",
"upload_time_iso_8601": "2021-06-27T10:15:03.856590Z",
"url": "https://files.pythonhosted.org/packages/5e/5f/82c8074f7e84978129347c2c6ec8b6c59f3584ff1a20bc3c940a3e061790/priority-2.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "149531bf0e754782cf218bfc8cc994ae",
"sha256": "c965d54f1b8d0d0b19479db3924c7c36cf672dbf2aec92d43fbdaf4492ba18c0"
},
"downloads": -1,
"filename": "priority-2.0.0.tar.gz",
"has_sig": false,
"md5_digest": "149531bf0e754782cf218bfc8cc994ae",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6.1",
"size": 24792,
"upload_time": "2021-06-27T10:15:05",
"upload_time_iso_8601": "2021-06-27T10:15:05.487867Z",
"url": "https://files.pythonhosted.org/packages/f5/3c/eb7c35f4dcede96fca1842dac5f4f5d15511aa4b52f3a961219e68ae9204/priority-2.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-06-27 10:15:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "python-hyper",
"github_project": "priority",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "priority"
}