service-capacity-modeling 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. service_capacity_modeling-0.2.0/LICENSE +201 -0
  2. service_capacity_modeling-0.2.0/PKG-INFO +261 -0
  3. service_capacity_modeling-0.2.0/README.md +232 -0
  4. service_capacity_modeling-0.2.0/service_capacity_modeling/__init__.py +0 -0
  5. service_capacity_modeling-0.2.0/service_capacity_modeling/capacity_planner.py +834 -0
  6. service_capacity_modeling-0.2.0/service_capacity_modeling/hardware/__init__.py +186 -0
  7. service_capacity_modeling-0.2.0/service_capacity_modeling/hardware/profiles/__init__.py +39 -0
  8. service_capacity_modeling-0.2.0/service_capacity_modeling/hardware/profiles/pricing/aws/3yr-reserved_ec2.json +2514 -0
  9. service_capacity_modeling-0.2.0/service_capacity_modeling/hardware/profiles/pricing/aws/3yr-reserved_zz-overrides.json +68 -0
  10. service_capacity_modeling-0.2.0/service_capacity_modeling/hardware/profiles/profiles.txt +1 -0
  11. service_capacity_modeling-0.2.0/service_capacity_modeling/hardware/profiles/shapes/aws.json +1128 -0
  12. service_capacity_modeling-0.2.0/service_capacity_modeling/interface.py +888 -0
  13. service_capacity_modeling-0.2.0/service_capacity_modeling/models/__init__.py +349 -0
  14. service_capacity_modeling-0.2.0/service_capacity_modeling/models/common.py +557 -0
  15. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/__init__.py +0 -0
  16. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/__init__.py +41 -0
  17. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/aurora.py +360 -0
  18. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/cassandra.py +717 -0
  19. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/counter.py +236 -0
  20. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/crdb.py +471 -0
  21. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/ddb.py +685 -0
  22. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/elasticsearch.py +591 -0
  23. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/entity.py +210 -0
  24. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/evcache.py +544 -0
  25. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/iso_date_math.py +34 -0
  26. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/kafka.py +485 -0
  27. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/key_value.py +227 -0
  28. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/postgres.py +107 -0
  29. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/rds.py +300 -0
  30. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/stateless_java.py +283 -0
  31. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/time_series.py +198 -0
  32. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/time_series_config.py +176 -0
  33. service_capacity_modeling-0.2.0/service_capacity_modeling/models/org/netflix/zookeeper.py +202 -0
  34. service_capacity_modeling-0.2.0/service_capacity_modeling/models/utils.py +50 -0
  35. service_capacity_modeling-0.2.0/service_capacity_modeling/stats.py +174 -0
  36. service_capacity_modeling-0.2.0/service_capacity_modeling/tools/__init__.py +0 -0
  37. service_capacity_modeling-0.2.0/service_capacity_modeling/tools/auto_shape.py +157 -0
  38. service_capacity_modeling-0.2.0/service_capacity_modeling/tools/fetch_pricing.py +124 -0
  39. service_capacity_modeling-0.2.0/service_capacity_modeling.egg-info/PKG-INFO +261 -0
  40. service_capacity_modeling-0.2.0/service_capacity_modeling.egg-info/SOURCES.txt +54 -0
  41. service_capacity_modeling-0.2.0/service_capacity_modeling.egg-info/dependency_links.txt +1 -0
  42. service_capacity_modeling-0.2.0/service_capacity_modeling.egg-info/entry_points.txt +3 -0
  43. service_capacity_modeling-0.2.0/service_capacity_modeling.egg-info/requires.txt +10 -0
  44. service_capacity_modeling-0.2.0/service_capacity_modeling.egg-info/top_level.txt +1 -0
  45. service_capacity_modeling-0.2.0/setup.cfg +4 -0
  46. service_capacity_modeling-0.2.0/setup.py +40 -0
  47. service_capacity_modeling-0.2.0/tests/test_arguments.py +7 -0
  48. service_capacity_modeling-0.2.0/tests/test_auto_shape.py +75 -0
  49. service_capacity_modeling-0.2.0/tests/test_common.py +192 -0
  50. service_capacity_modeling-0.2.0/tests/test_desire_merge.py +46 -0
  51. service_capacity_modeling-0.2.0/tests/test_hardware.py +62 -0
  52. service_capacity_modeling-0.2.0/tests/test_io2.py +29 -0
  53. service_capacity_modeling-0.2.0/tests/test_model_dump.py +21 -0
  54. service_capacity_modeling-0.2.0/tests/test_reproducible.py +101 -0
  55. service_capacity_modeling-0.2.0/tests/test_simulation.py +159 -0
  56. service_capacity_modeling-0.2.0/tests/test_working_set.py +63 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2020 Netflix, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,261 @@
1
+ Metadata-Version: 2.2
2
+ Name: service-capacity-modeling
3
+ Version: 0.2.0
4
+ Summary: Contains utilities for modeling database capacity on a cloud
5
+ Author: Joseph Lynch
6
+ Author-email: josephl@netflix.com
7
+ License: Apache 2.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Operating System :: OS Independent
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: pydantic>2.0
14
+ Requires-Dist: scipy
15
+ Requires-Dist: numpy
16
+ Requires-Dist: importlib_resources; python_version < "3.7"
17
+ Requires-Dist: isodate
18
+ Provides-Extra: aws
19
+ Requires-Dist: boto3; extra == "aws"
20
+ Dynamic: author
21
+ Dynamic: author-email
22
+ Dynamic: classifier
23
+ Dynamic: description
24
+ Dynamic: description-content-type
25
+ Dynamic: license
26
+ Dynamic: provides-extra
27
+ Dynamic: requires-dist
28
+ Dynamic: summary
29
+
30
+ # Service Capacity Modeling
31
+
32
+ ![Build Status](https://github.com/Netflix-Skunkworks/service-capacity-modeling/actions/workflows/python-build.yml/badge.svg)
33
+
34
+ A generic toolkit for modeling capacity requirements in the cloud. Pricing
35
+ information included in this repository are public prices.
36
+
37
+ **NOTE**: Netflix confidential information should never enter this repo. Please
38
+ remember this repository is public when making changes to it.
39
+
40
+ ## Trying it out
41
+
42
+ Run the tests:
43
+ ```bash
44
+ # Test the capacity planner on included netflix models
45
+ $ tox -e py38
46
+
47
+ # Run a single test with a debugger attached if the test fails
48
+ $ .tox/py38/bin/pytest -n0 -k test_java_heap_heavy --pdb --pdbcls=IPython.terminal.debugger:Pdb
49
+
50
+ # Verify all type contracts
51
+ $ tox -e mypy
52
+ ```
53
+
54
+ Run IPython for interactively using the library:
55
+ ```
56
+ tox -e dev -- ipython
57
+ ```
58
+
59
+ ## Example of Provisioning a Database
60
+ Fire up ipython and let's capacity plan a Tier 1 (important to the product aka
61
+ "prod") Cassandra database.
62
+
63
+ ```python
64
+ from service_capacity_modeling.interface import CapacityDesires
65
+ from service_capacity_modeling.interface import FixedInterval, Interval
66
+ from service_capacity_modeling.interface import QueryPattern, DataShape
67
+
68
+ db_desires = CapacityDesires(
69
+ # This service is important to the business, not critical (tier 0)
70
+ service_tier=1,
71
+ query_pattern=QueryPattern(
72
+ # Not sure exactly how much QPS we will do, but we think around
73
+ # 10,000 reads and 10,000 writes per second.
74
+ estimated_read_per_second=Interval(
75
+ low=1000, mid=10000, high=100000, confidence=0.9
76
+ ),
77
+ estimated_write_per_second=Interval(
78
+ low=1000, mid=10000, high=100000, confidence=0.9
79
+ ),
80
+ ),
81
+ # Not sure how much data, but we think it'll be below 1 TiB
82
+ data_shape=DataShape(
83
+ estimated_state_size_gib=Interval(low=100, mid=100, high=1000, confidence=0.9),
84
+ ),
85
+ )
86
+ ```
87
+
88
+ Now we can load up some models and do some capacity planning
89
+
90
+ ```python
91
+ from service_capacity_modeling.capacity_planner import planner
92
+ from service_capacity_modeling.models.org import netflix
93
+ import pprint
94
+
95
+ # Load up the Netflix capacity models
96
+ planner.register_group(netflix.models)
97
+
98
+ cap_plan = planner.plan(
99
+ model_name="org.netflix.cassandra",
100
+ region="us-east-1",
101
+ desires=db_desires,
102
+ # Simulate the possible requirements 512 times
103
+ simulations=512,
104
+ # Request 3 diverse hardware families to be returned
105
+ num_results=3,
106
+ )
107
+
108
+ # The range of requirements in hardware resources (CPU, RAM, Disk, etc ...)
109
+ requirements = cap_plan.requirements
110
+
111
+ # The ordered list of least regretful choices for the requirement
112
+ least_regret = cap_plan.least_regret
113
+
114
+ # Show the range of requirements for a single zone
115
+ pprint.pprint(requirements.zonal[0].model_dump())
116
+
117
+ # Show our least regretful choices of hardware in least regret order
118
+ # So for example if we can buy the first set of computers we would prefer
119
+ # to do that but we might not have availability in that family in which
120
+ # case we'd buy the second one.
121
+ for choice in range(3):
122
+ num_clusters = len(least_regret[choice].candidate_clusters.zonal)
123
+ print(f"Our #{choice + 1} choice is {num_clusters} zones of:")
124
+ pprint.pprint(least_regret[choice].candidate_clusters.zonal[0].model_dump())
125
+
126
+ ```
127
+
128
+ Note that we _can_ customize more information given what we know about the
129
+ use case, but each model (e.g. Cassandra) supplies reasonable defaults.
130
+
131
+ For example we can specify a lot more information
132
+
133
+ ```python
134
+ from service_capacity_modeling.interface import CapacityDesires, QueryPattern, Interval, FixedInterval, DataShape
135
+
136
+ db_desires = CapacityDesires(
137
+ # This service is important to the business, not critical (tier 0)
138
+ service_tier=1,
139
+ query_pattern=QueryPattern(
140
+ # Not sure exactly how much QPS we will do, but we think around
141
+ # 50,000 reads and 45,000 writes per second with a rather narrow
142
+ # bound
143
+ estimated_read_per_second=Interval(
144
+ low=40_000, mid=50_000, high=60_000, confidence=0.9
145
+ ),
146
+ estimated_write_per_second=Interval(
147
+ low=42_000, mid=45_000, high=50_000, confidence=0.9
148
+ ),
149
+ # This use case might do some partition scan queries that are
150
+ # somewhat expensive, so we hint a rather expensive ON-CPU time
151
+ # that a read will consume on the entire cluster.
152
+ estimated_mean_read_latency_ms=Interval(
153
+ low=0.1, mid=4, high=20, confidence=0.9
154
+ ),
155
+ # Writes at LOCAL_ONE are pretty cheap
156
+ estimated_mean_write_latency_ms=Interval(
157
+ low=0.1, mid=0.4, high=0.8, confidence=0.9
158
+ ),
159
+ # We want single digit latency, note that this is not a p99 of 10ms
160
+ # but defines the interval where 98% of latency falls to be between
161
+ # 0.4 and 10 milliseconds. Think of:
162
+ # low = "the minimum reasonable latency"
163
+ # high = "the maximum reasonable latency"
164
+ # mid = "value between low and high such that I want my distribution
165
+ # to skew left or right"
166
+ read_latency_slo_ms=FixedInterval(
167
+ low=0.4, mid=4, high=10, confidence=0.98
168
+ ),
169
+ write_latency_slo_ms=FixedInterval(
170
+ low=0.4, mid=4, high=10, confidence=0.98
171
+ )
172
+ ),
173
+ # Not sure how much data, but we think it'll be below 1 TiB
174
+ data_shape=DataShape(
175
+ estimated_state_size_gib=Interval(low=100, mid=500, high=1000, confidence=0.9),
176
+ ),
177
+ )
178
+ ```
179
+
180
+ ## Example of provisioning a caching cluster
181
+
182
+ In this example we tweak the QPS up, on CPU time of operations down
183
+ and SLO down. This more closely approximates a caching workload
184
+
185
+ ```python
186
+ from service_capacity_modeling.interface import CapacityDesires, QueryPattern, Interval, FixedInterval, DataShape
187
+ from service_capacity_modeling.capacity_planner import planner
188
+
189
+ cache_desires = CapacityDesires(
190
+ service_tier=1,
191
+ query_pattern=QueryPattern(
192
+ # Not sure exactly how much QPS we will do, but we think around
193
+ # 10,000 reads and 10,000 writes per second.
194
+ estimated_read_per_second=Interval(
195
+ low=10_000, mid=100_000, high=1_000_000, confidence=0.9
196
+ ),
197
+ estimated_write_per_second=Interval(
198
+ low=1_000, mid=20_000, high=100_000, confidence=0.9
199
+ ),
200
+ # Memcache is consistently fast at queries
201
+ estimated_mean_read_latency_ms=Interval(
202
+ low=0.05, mid=0.2, high=0.4, confidence=0.9
203
+ ),
204
+ estimated_mean_write_latency_ms=Interval(
205
+ low=0.05, mid=0.2, high=0.4, confidence=0.9
206
+ ),
207
+ # Caches usually have tighter SLOs
208
+ read_latency_slo_ms=FixedInterval(
209
+ low=0.4, mid=0.5, high=5, confidence=0.98
210
+ ),
211
+ write_latency_slo_ms=FixedInterval(
212
+ low=0.4, mid=0.5, high=5, confidence=0.98
213
+ )
214
+ ),
215
+ # Not sure how much data, but we think it'll be below 1000
216
+ data_shape=DataShape(
217
+ estimated_state_size_gib=Interval(low=100, mid=200, high=500, confidence=0.9),
218
+ ),
219
+ )
220
+
221
+ cache_cap_plan = planner.plan(
222
+ model_name="org.netflix.cassandra",
223
+ region="us-east-1",
224
+ desires=cache_desires,
225
+ allow_gp2=True,
226
+ )
227
+
228
+ requirement = cache_cap_plan.requirement
229
+ least_regret = cache_cap_plan.least_regret
230
+ ```
231
+
232
+ ## Notebooks
233
+
234
+ We have a demo notebook in `notebooks` you can use to experiment. Start it with
235
+
236
+ ```
237
+ tox -e notebook -- jupyter notebook notebooks/demo.ipynb
238
+ ```
239
+
240
+ ## Development
241
+
242
+ To contribute to this project:
243
+
244
+ 1. Make your change in a branch. Consider making a new model if you are making
245
+ significant changes and registering it as a different name.
246
+ 2. Write a unit test using `pytest` in the `tests` folder.
247
+ 3. Ensure your tests pass via `tox` or debug them with:
248
+ ```
249
+ tox -e py38 -- -k test_<your_functionality> --pdb --pdbcls=IPython.terminal.debugger:Pdb
250
+ ```
251
+
252
+ ### PyCharm IDE Setup
253
+ Use one of the test environments for IDE development, e.g. `tox -e py310` and then
254
+ `Add New Interpreter -> Add Local -> Select Existing -> Navigate to (workdir)/.tox/py310`.
255
+
256
+ ### Running CLIs
257
+ Use the `dev` virtual environment via `tox -e dev`. Then execute CLIs via that env.
258
+
259
+ ## Release
260
+ Tag to release, and Github actions should publish to upstream pypi. The internal Netflix mirrors will then
261
+ pull it down.
@@ -0,0 +1,232 @@
1
+ # Service Capacity Modeling
2
+
3
+ ![Build Status](https://github.com/Netflix-Skunkworks/service-capacity-modeling/actions/workflows/python-build.yml/badge.svg)
4
+
5
+ A generic toolkit for modeling capacity requirements in the cloud. Pricing
6
+ information included in this repository are public prices.
7
+
8
+ **NOTE**: Netflix confidential information should never enter this repo. Please
9
+ remember this repository is public when making changes to it.
10
+
11
+ ## Trying it out
12
+
13
+ Run the tests:
14
+ ```bash
15
+ # Test the capacity planner on included netflix models
16
+ $ tox -e py38
17
+
18
+ # Run a single test with a debugger attached if the test fails
19
+ $ .tox/py38/bin/pytest -n0 -k test_java_heap_heavy --pdb --pdbcls=IPython.terminal.debugger:Pdb
20
+
21
+ # Verify all type contracts
22
+ $ tox -e mypy
23
+ ```
24
+
25
+ Run IPython for interactively using the library:
26
+ ```
27
+ tox -e dev -- ipython
28
+ ```
29
+
30
+ ## Example of Provisioning a Database
31
+ Fire up ipython and let's capacity plan a Tier 1 (important to the product aka
32
+ "prod") Cassandra database.
33
+
34
+ ```python
35
+ from service_capacity_modeling.interface import CapacityDesires
36
+ from service_capacity_modeling.interface import FixedInterval, Interval
37
+ from service_capacity_modeling.interface import QueryPattern, DataShape
38
+
39
+ db_desires = CapacityDesires(
40
+ # This service is important to the business, not critical (tier 0)
41
+ service_tier=1,
42
+ query_pattern=QueryPattern(
43
+ # Not sure exactly how much QPS we will do, but we think around
44
+ # 10,000 reads and 10,000 writes per second.
45
+ estimated_read_per_second=Interval(
46
+ low=1000, mid=10000, high=100000, confidence=0.9
47
+ ),
48
+ estimated_write_per_second=Interval(
49
+ low=1000, mid=10000, high=100000, confidence=0.9
50
+ ),
51
+ ),
52
+ # Not sure how much data, but we think it'll be below 1 TiB
53
+ data_shape=DataShape(
54
+ estimated_state_size_gib=Interval(low=100, mid=100, high=1000, confidence=0.9),
55
+ ),
56
+ )
57
+ ```
58
+
59
+ Now we can load up some models and do some capacity planning
60
+
61
+ ```python
62
+ from service_capacity_modeling.capacity_planner import planner
63
+ from service_capacity_modeling.models.org import netflix
64
+ import pprint
65
+
66
+ # Load up the Netflix capacity models
67
+ planner.register_group(netflix.models)
68
+
69
+ cap_plan = planner.plan(
70
+ model_name="org.netflix.cassandra",
71
+ region="us-east-1",
72
+ desires=db_desires,
73
+ # Simulate the possible requirements 512 times
74
+ simulations=512,
75
+ # Request 3 diverse hardware families to be returned
76
+ num_results=3,
77
+ )
78
+
79
+ # The range of requirements in hardware resources (CPU, RAM, Disk, etc ...)
80
+ requirements = cap_plan.requirements
81
+
82
+ # The ordered list of least regretful choices for the requirement
83
+ least_regret = cap_plan.least_regret
84
+
85
+ # Show the range of requirements for a single zone
86
+ pprint.pprint(requirements.zonal[0].model_dump())
87
+
88
+ # Show our least regretful choices of hardware in least regret order
89
+ # So for example if we can buy the first set of computers we would prefer
90
+ # to do that but we might not have availability in that family in which
91
+ # case we'd buy the second one.
92
+ for choice in range(3):
93
+ num_clusters = len(least_regret[choice].candidate_clusters.zonal)
94
+ print(f"Our #{choice + 1} choice is {num_clusters} zones of:")
95
+ pprint.pprint(least_regret[choice].candidate_clusters.zonal[0].model_dump())
96
+
97
+ ```
98
+
99
+ Note that we _can_ customize more information given what we know about the
100
+ use case, but each model (e.g. Cassandra) supplies reasonable defaults.
101
+
102
+ For example we can specify a lot more information
103
+
104
+ ```python
105
+ from service_capacity_modeling.interface import CapacityDesires, QueryPattern, Interval, FixedInterval, DataShape
106
+
107
+ db_desires = CapacityDesires(
108
+ # This service is important to the business, not critical (tier 0)
109
+ service_tier=1,
110
+ query_pattern=QueryPattern(
111
+ # Not sure exactly how much QPS we will do, but we think around
112
+ # 50,000 reads and 45,000 writes per second with a rather narrow
113
+ # bound
114
+ estimated_read_per_second=Interval(
115
+ low=40_000, mid=50_000, high=60_000, confidence=0.9
116
+ ),
117
+ estimated_write_per_second=Interval(
118
+ low=42_000, mid=45_000, high=50_000, confidence=0.9
119
+ ),
120
+ # This use case might do some partition scan queries that are
121
+ # somewhat expensive, so we hint a rather expensive ON-CPU time
122
+ # that a read will consume on the entire cluster.
123
+ estimated_mean_read_latency_ms=Interval(
124
+ low=0.1, mid=4, high=20, confidence=0.9
125
+ ),
126
+ # Writes at LOCAL_ONE are pretty cheap
127
+ estimated_mean_write_latency_ms=Interval(
128
+ low=0.1, mid=0.4, high=0.8, confidence=0.9
129
+ ),
130
+ # We want single digit latency, note that this is not a p99 of 10ms
131
+ # but defines the interval where 98% of latency falls to be between
132
+ # 0.4 and 10 milliseconds. Think of:
133
+ # low = "the minimum reasonable latency"
134
+ # high = "the maximum reasonable latency"
135
+ # mid = "value between low and high such that I want my distribution
136
+ # to skew left or right"
137
+ read_latency_slo_ms=FixedInterval(
138
+ low=0.4, mid=4, high=10, confidence=0.98
139
+ ),
140
+ write_latency_slo_ms=FixedInterval(
141
+ low=0.4, mid=4, high=10, confidence=0.98
142
+ )
143
+ ),
144
+ # Not sure how much data, but we think it'll be below 1 TiB
145
+ data_shape=DataShape(
146
+ estimated_state_size_gib=Interval(low=100, mid=500, high=1000, confidence=0.9),
147
+ ),
148
+ )
149
+ ```
150
+
151
+ ## Example of provisioning a caching cluster
152
+
153
+ In this example we tweak the QPS up, on CPU time of operations down
154
+ and SLO down. This more closely approximates a caching workload
155
+
156
+ ```python
157
+ from service_capacity_modeling.interface import CapacityDesires, QueryPattern, Interval, FixedInterval, DataShape
158
+ from service_capacity_modeling.capacity_planner import planner
159
+
160
+ cache_desires = CapacityDesires(
161
+ service_tier=1,
162
+ query_pattern=QueryPattern(
163
+ # Not sure exactly how much QPS we will do, but we think around
164
+ # 10,000 reads and 10,000 writes per second.
165
+ estimated_read_per_second=Interval(
166
+ low=10_000, mid=100_000, high=1_000_000, confidence=0.9
167
+ ),
168
+ estimated_write_per_second=Interval(
169
+ low=1_000, mid=20_000, high=100_000, confidence=0.9
170
+ ),
171
+ # Memcache is consistently fast at queries
172
+ estimated_mean_read_latency_ms=Interval(
173
+ low=0.05, mid=0.2, high=0.4, confidence=0.9
174
+ ),
175
+ estimated_mean_write_latency_ms=Interval(
176
+ low=0.05, mid=0.2, high=0.4, confidence=0.9
177
+ ),
178
+ # Caches usually have tighter SLOs
179
+ read_latency_slo_ms=FixedInterval(
180
+ low=0.4, mid=0.5, high=5, confidence=0.98
181
+ ),
182
+ write_latency_slo_ms=FixedInterval(
183
+ low=0.4, mid=0.5, high=5, confidence=0.98
184
+ )
185
+ ),
186
+ # Not sure how much data, but we think it'll be below 1000
187
+ data_shape=DataShape(
188
+ estimated_state_size_gib=Interval(low=100, mid=200, high=500, confidence=0.9),
189
+ ),
190
+ )
191
+
192
+ cache_cap_plan = planner.plan(
193
+ model_name="org.netflix.cassandra",
194
+ region="us-east-1",
195
+ desires=cache_desires,
196
+ allow_gp2=True,
197
+ )
198
+
199
+ requirement = cache_cap_plan.requirement
200
+ least_regret = cache_cap_plan.least_regret
201
+ ```
202
+
203
+ ## Notebooks
204
+
205
+ We have a demo notebook in `notebooks` you can use to experiment. Start it with
206
+
207
+ ```
208
+ tox -e notebook -- jupyter notebook notebooks/demo.ipynb
209
+ ```
210
+
211
+ ## Development
212
+
213
+ To contribute to this project:
214
+
215
+ 1. Make your change in a branch. Consider making a new model if you are making
216
+ significant changes and registering it as a different name.
217
+ 2. Write a unit test using `pytest` in the `tests` folder.
218
+ 3. Ensure your tests pass via `tox` or debug them with:
219
+ ```
220
+ tox -e py38 -- -k test_<your_functionality> --pdb --pdbcls=IPython.terminal.debugger:Pdb
221
+ ```
222
+
223
+ ### PyCharm IDE Setup
224
+ Use one of the test environments for IDE development, e.g. `tox -e py310` and then
225
+ `Add New Interpreter -> Add Local -> Select Existing -> Navigate to (workdir)/.tox/py310`.
226
+
227
+ ### Running CLIs
228
+ Use the `dev` virtual environment via `tox -e dev`. Then execute CLIs via that env.
229
+
230
+ ## Release
231
+ Tag to release, and Github actions should publish to upstream pypi. The internal Netflix mirrors will then
232
+ pull it down.