feat(PyPI): update metadata for MLRsearch 1.2.1
[csit.git] / PyPI / MLRsearch / README.rst
1 Multiple Loss Ratio Search library
2 ==================================
3
4 Origins
5 -------
6
7 This library was developed as a speedup for traditional binary search
8 in CSIT_ (Continuous System and Integration Testing) project of fd.io_
9 (Fast Data), one of LFN_ (Linux Foundation Networking) projects.
10
11 In order to make this code available in PyPI_ (Python Package Index),
12 the setuputils stuff has been added,
13 but after some discussion, the export directory_
14 is only a symlink to the original place of tightly coupled CSIT code.
15
16 Change log
17 ----------
18
19 1.2.1: Updated the readme document.
20
21 1.2.0: Changed the output structure to use Goal Result as described in draft-05.
22
23 1.1.0: Logic improvements, independent selectors, exceed ratio support,
24 better width rounding, conditional throughput as output.
25 Implementation relies more on dataclasses, code split into smaller files.
26 API changed considerably, mainly to avoid long argument lists.
27
28 0.4.0: Considarable logic improvements, more than two target ratios supported.
29 API is not backward compatible with previous versions.
30
31 0.3.0: Migrated to Python 3.6, small code quality improvements.
32
33 0.2.0: Optional parameter "doublings" has been added.
34
35 0.1.1: First officially released version.
36
37 Usage
38 -----
39
40 High level description
41 ______________________
42
43 A complete application capable of testing performance using MLRsearch
44 consists of three layers: Manager, Controller and Measurer.
45 This library provides an implementation for the Controller only,
46 including all the classes needed to define API between Controller
47 and other two components.
48
49 Users are supposed to implement the whole Manager layer,
50 and also implement the Measurer layer.
51 The Measurer instance is injected as a parameter
52 when the manager calls the controller instance.
53
54 The purpose of Measurer instance is to perform one trial measurement.
55 Upon invocation of measure() method, the controller only specifies
56 the intended duration and the intended load for the trial.
57 The call is done using keyword arguments, so the signature has to be:
58
59 ..  code-block:: python3
60
61     def measure(self, intended_duration, intended_load):
62
63 Usually, the trial measurement process also needs other values,
64 collectively caller a traffic profile. User (the manager instance)
65 is responsible for initiating the measurer instance accordingly.
66 Also, the manager is supposed to set up SUT, traffic generator,
67 and any other component that can affect the result.
68
69 For specific input and output objects see the example below.
70
71 Example
72 _______
73
74 This is a minimal example showing every configuration attribute.
75 The measurer does not interact with any real SUT,
76 it simulates a SUT that is able to forward exactly one million packets
77 per second (unidirectional traffic only),
78 not one packet more (fully deterministic).
79 In these conditions, the conditional throughput for PDR
80 happens to be accurate within one packet per second.
81
82 This is the screen capture of interactive python interpreter
83 (wrapped so long lines are readable):
84
85 ..  code-block:: python3
86
87     >>> import dataclasses
88     >>> from MLRsearch import (
89     ...     AbstractMeasurer, Config, MeasurementResult,
90     ...     MultipleLossRatioSearch, SearchGoal,
91     ... )
92     >>>
93     >>> class Hard1MppsMeasurer(AbstractMeasurer):
94     ...     def measure(self, intended_duration, intended_load):
95     ...         sent = int(intended_duration * intended_load)
96     ...         received = min(sent, int(intended_duration * 1e6))
97     ...         return MeasurementResult(
98     ...             intended_duration=intended_duration,
99     ...             intended_load=intended_load,
100     ...             offered_count=sent,
101     ...             forwarding_count=received,
102     ...         )
103     ...
104     >>> def print_dot(_):
105     ...     print(".", end="")
106     ...
107     >>> ndr_goal = SearchGoal(
108     ...     loss_ratio=0.0,
109     ...     exceed_ratio=0.005,
110     ...     relative_width=0.005,
111     ...     initial_trial_duration=1.0,
112     ...     final_trial_duration=1.0,
113     ...     duration_sum=21.0,
114     ...     preceding_targets=2,
115     ...     expansion_coefficient=2,
116     ... )
117     >>> pdr_goal = dataclasses.replace(ndr_goal, loss_ratio=0.005)
118     >>> config = Config(
119     ...     goals=[ndr_goal, pdr_goal],
120     ...     min_load=1e3,
121     ...     max_load=1e9,
122     ...     search_duration_max=1.0,
123     ...     warmup_duration=None,
124     ... )
125     >>> controller = MultipleLossRatioSearch(config=config)
126     >>> result = controller.search(measurer=Hard1MppsMeasurer(), debug=print_dot)
127     ....................................................................................
128     ....................................................................................
129     ...................>>> print(result)
130     {SearchGoal(loss_ratio=0.0, exceed_ratio=0.005, relative_width=0.005, initial_trial_
131     duration=1.0, final_trial_duration=1.0, duration_sum=21.0, preceding_targets=2, expa
132     nsion_coefficient=2, fail_fast=True): fl=997497.6029392382,s=(gl=21.0,bl=0.0,gs=0.0,
133     bs=0.0), SearchGoal(loss_ratio=0.005, exceed_ratio=0.005, relative_width=0.005, init
134     ial_trial_duration=1.0, final_trial_duration=1.0, duration_sum=21.0, preceding_targe
135     ts=2, expansion_coefficient=2, fail_fast=True): fl=1002508.6747611101,s=(gl=21.0,bl=
136     0.0,gs=0.0,bs=0.0)}
137     >>> print(f"NDR conditional throughput: {float(result[ndr_goal].conditional_throughp
138     ut)}")
139     NDR conditional throughput: 997497.6029392382
140     >>> print(f"PDR conditional throughput: {float(result[pdr_goal].conditional_throughp
141     ut)}")
142     PDR conditional throughput: 1000000.6730730429
143     >>>
144
145 IETF documents
146 --------------
147
148 The currently published `IETF draft`_ describes the logic of version 1.2.0,
149 earlier library and draft versions do not match each other that well.
150
151 .. _CSIT: https://wiki.fd.io/view/CSIT
152 .. _fd.io: https://fd.io/
153 .. _LFN: https://www.linuxfoundation.org/projects/networking/
154 .. _PyPI: https://pypi.org/project/MLRsearch/
155 .. _directory: https://gerrit.fd.io/r/gitweb?p=csit.git;a=tree;f=PyPI/MLRsearch
156 .. _IETF draft: https://tools.ietf.org/html/draft-ietf-bmwg-mlrsearch-05