diff --git a/code snippets/rateLimitTests.ipynb b/code snippets/rateLimitTests.ipynb new file mode 100644 index 0000000..4950918 --- /dev/null +++ b/code snippets/rateLimitTests.ipynb @@ -0,0 +1,498 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "e6dbc294", + "metadata": {}, + "outputs": [], + "source": [ + "import json, time\n", + "from datetime import datetime as dt" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "80fc41af", + "metadata": {}, + "outputs": [], + "source": [ + "__topic__ = \"v1/devices/me/telemetry\"\n", + "__qos__ = 1" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "86b39db7", + "metadata": {}, + "outputs": [], + "source": [ + "sessionLimits = {\n", + " \"maxPayloadSize\": 65536,\n", + " \"maxInflightMessages\": 100,\n", + " \"rateLimits\": {\n", + " \"messages\": \"200:1,6000:60,14000:3600\",\n", + " \"telemetryMessages\": \"100:1,3000:60,7000:3600\",\n", + " \"telemetryDataPoints\": \"200:1,6000:60,14000:3600\"\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "432e3517", + "metadata": {}, + "outputs": [], + "source": [ + "# Helper function to split the payload into chunks\n", + "def chunk_payload(payload, chunk_size=20):\n", + " chunked_values = list(payload[\"values\"].items())\n", + " for i in range(0, len(chunked_values), chunk_size):\n", + " yield {\n", + " \"ts\": payload[\"ts\"],\n", + " \"values\": dict(chunked_values[i:i+chunk_size])\n", + " }" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "1f03785e", + "metadata": {}, + "outputs": [], + "source": [ + "#telemetryDataPointsLimit = int(sessionLimits[\"rateLimits\"][\"telemetryDataPoints\"].split(\",\")[0].split(\":\")[0])\n", + "def getTelemetryDataPointLimit(sessionLimits):\n", + " #int(sessionLimits[\"rateLimits\"][\"telemetryDataPoints\"].split(\",\")[0].split(\":\")[0])\n", + " rateLimits = sessionLimits.get(\"rateLimits\")\n", + " if rateLimits:\n", + " telemetryDataPoints = rateLimits.get(\"telemetryDataPoints\")\n", + " if telemetryDataPoints:\n", + " perSecondLimit = telemetryDataPoints.split(\",\")[0]\n", + " dataPoints = perSecondLimit.split(\":\")[0]\n", + " return int(dataPoints)\n", + " else:\n", + " return \"Error: no Telemetry Data Points\" \n", + " else:\n", + " return \"Error: no rate limits\"\n", + " \n", + "telemetryDataPointsLimit = getTelemetryDataPointLimit(sessionLimits=sessionLimits)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "33753471", + "metadata": {}, + "outputs": [], + "source": [ + "payload = {\"ts\": (round(dt.timestamp(dt.now())/600)*600)*1000, \"values\": {\"test-1\": 1, \"test-2\": 2}}\n", + "for x in range(1,351):\n", + " payload[\"values\"][f\"test-{x}\"] = x\n" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "0a457fda", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"ts\": 1752608400000,\n", + " \"values\": {\n", + " \"test-1\": 1,\n", + " \"test-2\": 2,\n", + " \"test-3\": 3,\n", + " \"test-4\": 4,\n", + " \"test-5\": 5,\n", + " \"test-6\": 6,\n", + " \"test-7\": 7,\n", + " \"test-8\": 8,\n", + " \"test-9\": 9,\n", + " \"test-10\": 10,\n", + " \"test-11\": 11,\n", + " \"test-12\": 12,\n", + " \"test-13\": 13,\n", + " \"test-14\": 14,\n", + " \"test-15\": 15,\n", + " \"test-16\": 16,\n", + " \"test-17\": 17,\n", + " \"test-18\": 18,\n", + " \"test-19\": 19,\n", + " \"test-20\": 20,\n", + " \"test-21\": 21,\n", + " \"test-22\": 22,\n", + " \"test-23\": 23,\n", + " \"test-24\": 24,\n", + " \"test-25\": 25,\n", + " \"test-26\": 26,\n", + " \"test-27\": 27,\n", + " \"test-28\": 28,\n", + " \"test-29\": 29,\n", + " \"test-30\": 30,\n", + " \"test-31\": 31,\n", + " \"test-32\": 32,\n", + " \"test-33\": 33,\n", + " \"test-34\": 34,\n", + " \"test-35\": 35,\n", + " \"test-36\": 36,\n", + " \"test-37\": 37,\n", + " \"test-38\": 38,\n", + " \"test-39\": 39,\n", + " \"test-40\": 40,\n", + " \"test-41\": 41,\n", + " \"test-42\": 42,\n", + " \"test-43\": 43,\n", + " \"test-44\": 44,\n", + " \"test-45\": 45,\n", + " \"test-46\": 46,\n", + " \"test-47\": 47,\n", + " \"test-48\": 48,\n", + " \"test-49\": 49,\n", + " \"test-50\": 50,\n", + " \"test-51\": 51,\n", + " \"test-52\": 52,\n", + " \"test-53\": 53,\n", + " \"test-54\": 54,\n", + " \"test-55\": 55,\n", + " \"test-56\": 56,\n", + " \"test-57\": 57,\n", + " \"test-58\": 58,\n", + " \"test-59\": 59,\n", + " \"test-60\": 60,\n", + " \"test-61\": 61,\n", + " \"test-62\": 62,\n", + " \"test-63\": 63,\n", + " \"test-64\": 64,\n", + " \"test-65\": 65,\n", + " \"test-66\": 66,\n", + " \"test-67\": 67,\n", + " \"test-68\": 68,\n", + " \"test-69\": 69,\n", + " \"test-70\": 70,\n", + " \"test-71\": 71,\n", + " \"test-72\": 72,\n", + " \"test-73\": 73,\n", + " \"test-74\": 74,\n", + " \"test-75\": 75,\n", + " \"test-76\": 76,\n", + " \"test-77\": 77,\n", + " \"test-78\": 78,\n", + " \"test-79\": 79,\n", + " \"test-80\": 80,\n", + " \"test-81\": 81,\n", + " \"test-82\": 82,\n", + " \"test-83\": 83,\n", + " \"test-84\": 84,\n", + " \"test-85\": 85,\n", + " \"test-86\": 86,\n", + " \"test-87\": 87,\n", + " \"test-88\": 88,\n", + " \"test-89\": 89,\n", + " \"test-90\": 90,\n", + " \"test-91\": 91,\n", + " \"test-92\": 92,\n", + " \"test-93\": 93,\n", + " \"test-94\": 94,\n", + " \"test-95\": 95,\n", + " \"test-96\": 96,\n", + " \"test-97\": 97,\n", + " \"test-98\": 98,\n", + " \"test-99\": 99,\n", + " \"test-100\": 100,\n", + " \"test-101\": 101,\n", + " \"test-102\": 102,\n", + " \"test-103\": 103,\n", + " \"test-104\": 104,\n", + " \"test-105\": 105,\n", + " \"test-106\": 106,\n", + " \"test-107\": 107,\n", + " \"test-108\": 108,\n", + " \"test-109\": 109,\n", + " \"test-110\": 110,\n", + " \"test-111\": 111,\n", + " \"test-112\": 112,\n", + " \"test-113\": 113,\n", + " \"test-114\": 114,\n", + " \"test-115\": 115,\n", + " \"test-116\": 116,\n", + " \"test-117\": 117,\n", + " \"test-118\": 118,\n", + " \"test-119\": 119,\n", + " \"test-120\": 120,\n", + " \"test-121\": 121,\n", + " \"test-122\": 122,\n", + " \"test-123\": 123,\n", + " \"test-124\": 124,\n", + " \"test-125\": 125,\n", + " \"test-126\": 126,\n", + " \"test-127\": 127,\n", + " \"test-128\": 128,\n", + " \"test-129\": 129,\n", + " \"test-130\": 130,\n", + " \"test-131\": 131,\n", + " \"test-132\": 132,\n", + " \"test-133\": 133,\n", + " \"test-134\": 134,\n", + " \"test-135\": 135,\n", + " \"test-136\": 136,\n", + " \"test-137\": 137,\n", + " \"test-138\": 138,\n", + " \"test-139\": 139,\n", + " \"test-140\": 140,\n", + " \"test-141\": 141,\n", + " \"test-142\": 142,\n", + " \"test-143\": 143,\n", + " \"test-144\": 144,\n", + " \"test-145\": 145,\n", + " \"test-146\": 146,\n", + " \"test-147\": 147,\n", + " \"test-148\": 148,\n", + " \"test-149\": 149,\n", + " \"test-150\": 150,\n", + " \"test-151\": 151,\n", + " \"test-152\": 152,\n", + " \"test-153\": 153,\n", + " \"test-154\": 154,\n", + " \"test-155\": 155,\n", + " \"test-156\": 156,\n", + " \"test-157\": 157,\n", + " \"test-158\": 158,\n", + " \"test-159\": 159,\n", + " \"test-160\": 160,\n", + " \"test-161\": 161,\n", + " \"test-162\": 162,\n", + " \"test-163\": 163,\n", + " \"test-164\": 164,\n", + " \"test-165\": 165,\n", + " \"test-166\": 166,\n", + " \"test-167\": 167,\n", + " \"test-168\": 168,\n", + " \"test-169\": 169,\n", + " \"test-170\": 170,\n", + " \"test-171\": 171,\n", + " \"test-172\": 172,\n", + " \"test-173\": 173,\n", + " \"test-174\": 174,\n", + " \"test-175\": 175,\n", + " \"test-176\": 176,\n", + " \"test-177\": 177,\n", + " \"test-178\": 178,\n", + " \"test-179\": 179,\n", + " \"test-180\": 180,\n", + " \"test-181\": 181,\n", + " \"test-182\": 182,\n", + " \"test-183\": 183,\n", + " \"test-184\": 184,\n", + " \"test-185\": 185,\n", + " \"test-186\": 186,\n", + " \"test-187\": 187,\n", + " \"test-188\": 188,\n", + " \"test-189\": 189,\n", + " \"test-190\": 190,\n", + " \"test-191\": 191,\n", + " \"test-192\": 192,\n", + " \"test-193\": 193,\n", + " \"test-194\": 194,\n", + " \"test-195\": 195,\n", + " \"test-196\": 196,\n", + " \"test-197\": 197,\n", + " \"test-198\": 198,\n", + " \"test-199\": 199,\n", + " \"test-200\": 200\n", + " }\n", + "}\n", + "{\n", + " \"ts\": 1752608400000,\n", + " \"values\": {\n", + " \"test-201\": 201,\n", + " \"test-202\": 202,\n", + " \"test-203\": 203,\n", + " \"test-204\": 204,\n", + " \"test-205\": 205,\n", + " \"test-206\": 206,\n", + " \"test-207\": 207,\n", + " \"test-208\": 208,\n", + " \"test-209\": 209,\n", + " \"test-210\": 210,\n", + " \"test-211\": 211,\n", + " \"test-212\": 212,\n", + " \"test-213\": 213,\n", + " \"test-214\": 214,\n", + " \"test-215\": 215,\n", + " \"test-216\": 216,\n", + " \"test-217\": 217,\n", + " \"test-218\": 218,\n", + " \"test-219\": 219,\n", + " \"test-220\": 220,\n", + " \"test-221\": 221,\n", + " \"test-222\": 222,\n", + " \"test-223\": 223,\n", + " \"test-224\": 224,\n", + " \"test-225\": 225,\n", + " \"test-226\": 226,\n", + " \"test-227\": 227,\n", + " \"test-228\": 228,\n", + " \"test-229\": 229,\n", + " \"test-230\": 230,\n", + " \"test-231\": 231,\n", + " \"test-232\": 232,\n", + " \"test-233\": 233,\n", + " \"test-234\": 234,\n", + " \"test-235\": 235,\n", + " \"test-236\": 236,\n", + " \"test-237\": 237,\n", + " \"test-238\": 238,\n", + " \"test-239\": 239,\n", + " \"test-240\": 240,\n", + " \"test-241\": 241,\n", + " \"test-242\": 242,\n", + " \"test-243\": 243,\n", + " \"test-244\": 244,\n", + " \"test-245\": 245,\n", + " \"test-246\": 246,\n", + " \"test-247\": 247,\n", + " \"test-248\": 248,\n", + " \"test-249\": 249,\n", + " \"test-250\": 250,\n", + " \"test-251\": 251,\n", + " \"test-252\": 252,\n", + " \"test-253\": 253,\n", + " \"test-254\": 254,\n", + " \"test-255\": 255,\n", + " \"test-256\": 256,\n", + " \"test-257\": 257,\n", + " \"test-258\": 258,\n", + " \"test-259\": 259,\n", + " \"test-260\": 260,\n", + " \"test-261\": 261,\n", + " \"test-262\": 262,\n", + " \"test-263\": 263,\n", + " \"test-264\": 264,\n", + " \"test-265\": 265,\n", + " \"test-266\": 266,\n", + " \"test-267\": 267,\n", + " \"test-268\": 268,\n", + " \"test-269\": 269,\n", + " \"test-270\": 270,\n", + " \"test-271\": 271,\n", + " \"test-272\": 272,\n", + " \"test-273\": 273,\n", + " \"test-274\": 274,\n", + " \"test-275\": 275,\n", + " \"test-276\": 276,\n", + " \"test-277\": 277,\n", + " \"test-278\": 278,\n", + " \"test-279\": 279,\n", + " \"test-280\": 280,\n", + " \"test-281\": 281,\n", + " \"test-282\": 282,\n", + " \"test-283\": 283,\n", + " \"test-284\": 284,\n", + " \"test-285\": 285,\n", + " \"test-286\": 286,\n", + " \"test-287\": 287,\n", + " \"test-288\": 288,\n", + " \"test-289\": 289,\n", + " \"test-290\": 290,\n", + " \"test-291\": 291,\n", + " \"test-292\": 292,\n", + " \"test-293\": 293,\n", + " \"test-294\": 294,\n", + " \"test-295\": 295,\n", + " \"test-296\": 296,\n", + " \"test-297\": 297,\n", + " \"test-298\": 298,\n", + " \"test-299\": 299,\n", + " \"test-300\": 300,\n", + " \"test-301\": 301,\n", + " \"test-302\": 302,\n", + " \"test-303\": 303,\n", + " \"test-304\": 304,\n", + " \"test-305\": 305,\n", + " \"test-306\": 306,\n", + " \"test-307\": 307,\n", + " \"test-308\": 308,\n", + " \"test-309\": 309,\n", + " \"test-310\": 310,\n", + " \"test-311\": 311,\n", + " \"test-312\": 312,\n", + " \"test-313\": 313,\n", + " \"test-314\": 314,\n", + " \"test-315\": 315,\n", + " \"test-316\": 316,\n", + " \"test-317\": 317,\n", + " \"test-318\": 318,\n", + " \"test-319\": 319,\n", + " \"test-320\": 320,\n", + " \"test-321\": 321,\n", + " \"test-322\": 322,\n", + " \"test-323\": 323,\n", + " \"test-324\": 324,\n", + " \"test-325\": 325,\n", + " \"test-326\": 326,\n", + " \"test-327\": 327,\n", + " \"test-328\": 328,\n", + " \"test-329\": 329,\n", + " \"test-330\": 330,\n", + " \"test-331\": 331,\n", + " \"test-332\": 332,\n", + " \"test-333\": 333,\n", + " \"test-334\": 334,\n", + " \"test-335\": 335,\n", + " \"test-336\": 336,\n", + " \"test-337\": 337,\n", + " \"test-338\": 338,\n", + " \"test-339\": 339,\n", + " \"test-340\": 340,\n", + " \"test-341\": 341,\n", + " \"test-342\": 342,\n", + " \"test-343\": 343,\n", + " \"test-344\": 344,\n", + " \"test-345\": 345,\n", + " \"test-346\": 346,\n", + " \"test-347\": 347,\n", + " \"test-348\": 348,\n", + " \"test-349\": 349,\n", + " \"test-350\": 350\n", + " }\n", + "}\n" + ] + } + ], + "source": [ + "for chunk in chunk_payload(payload=payload, chunk_size=telemetryDataPointsLimit):\n", + " print(json.dumps(chunk, indent=4))\n", + " time.sleep(1)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "tbreport", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.1" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}