kquick / Thespian

Python Actor concurrency library
MIT License
189 stars 24 forks source link

High memory use and actor system timeout with about 2,000 actors #57

Closed davideps closed 2 years ago

davideps commented 4 years ago

I'm designing a simulation that should be able to scale across a cluster of computers. On my Windows 10 laptop with 6 cores and 32GB of memory, I am encountering both a memory issue and actor system timeout. I'm using multiprocTCPBase and get a timeout error (trace below) after 1,994 have been created. Together these actors use 20GB of memory (not including 5GB used at machine startup). Two actors store large dictionaries that include the addresses of many other actors. The remaining actors store only a few integer and string values. I was surprised by the memory usage, though my laptop did not actually run out of memory.

Since I'm interested in multi-core, multi-machine performance, I thought the actors should be separate processes, but perhaps there is too much overhead? I'd welcome advice about how to redesign the actors to use less memory as well as help identifying the reason for the time out.

        [lots of lines like this one below...]
    Cell {A:Cell @ ActorAddr-(T|:58746)} initialized: oid:41_34 x:41 y:34
Traceback (most recent call last):
  File "D:/Documents/Programming/ActiveFiction/python_code/thespian_test_01.py", line 409, in <module>
    cell = asys.createActor(Cell)
  File "C:\Users\dvyd\.conda\envs\activefiction\lib\site-packages\thespian\actors.py", line 705, in createActor
    sourceHash)
  File "C:\Users\dvyd\.conda\envs\activefiction\lib\site-packages\thespian\system\systemBase.py", line 217, in newPrimaryActor
    str(self.transport.myAddress)))
thespian.actors.ActorSystemRequestTimeout: No response received to PendingActor request to Admin at ActorAddr-(T|:1900) from ActorAddr-(T|:62606)

Process finished with exit code 1
kquick commented 4 years ago

Let me address your two concerns individually: memory utilization and timeouts.

davideps commented 4 years ago

Thanks Kevin. Does 20GB for 2,000 actors suggest each one is taking 10MB? If so, that is a lot more than the minimum of 20 to 30kb. Is there a way to find out why? This is what the log says:

2020-02-17 15:47:31.305327 p8380 ERR ValueError on select(#2049: [17176, 752, 712, 808, 816, 828, 724, 864, 872, 912, 896, 948, 916, 952, 888, 968, 984, 1008, 1012, 1020, 920, 960, 928, 976, 936, 932, 996, 820, 868, 892, 796, 956, 824, 812, 1044, 1036, 804, 1004, 1084, 1060, 844, 1072, 1068, 1048, 1128, 1104, 1116, 1136, 1152, 1124, 1180, 1156, 1188, 1204, 1220, 1224, 1172, 1216, 1232, 1192, 1264, 1280, 1288, 1304, 1292, 1324, 1320, 1356, 1348, 1344, 1364, 1372, 1388, 1392, 1396, 1328, 1412, 1428, 1308, 1420, 1452, 1472, 1460, 1476, 1504, 1512, 1480, 1516, 1524, 1520, 1568, 1556, 1608, 1532, 1600, 1536, 1584, 1604, 1488, 1612, 1620, 1628, 1624, 1636, 1672, 1712, 1640, 1700, 1716, 1416, 1468, 1256, 1576, 1696, 1744, 1676, 1688, 1424, 1208, 1648, 1096, 1768, 1760, 1772, 1284, 1704, 1804, 1228, 1856, 1820, 1236, 1756, 1832, 1844, 1852, 1112, 1736, 1800, 1764, 1892, 1868, 1884, 1848, 1408, 1212, 1900, 1920, 1824, 1948, 1940, 1944, 1916, 1992, 2008, 2044, 2040, 2036, 1988, 1980, 2012, 2000, 2028, 2060, 2004, 2092, 2084, 2116, 2076, 2112, 2128, 2156, 2108, 2144, 2140, 2160, 2152, 2148, 2164, 2016, 2204, 2216, 2212, 2240, 2220, 2180, 2236, 2192, 2200, 2272, 2292, 2268, 2348, 2296, 2056, 2352, 2380, 2356, 2288, 2388, 2408, 2372, 2376, 2416, 2396, 2412, 2444, 2360, 2400, 2456, 2452, 2328, 2496, 2472, 2448, 2500, 2508, 2516, 2536, 2504, 2524, 2544, 2484, 2532, 2512, 2576, 2384, 2600, 2564, 2584, 2324, 2608, 2612, 2620, 2624, 2632, 2572, 2676, 2700, 2656, 2712, 2724, 2696, 436, 2740, 2776, 2704, 2768, 2680, 2728, 2716, 2784, 2708, 2800, 2684, 2836, 2760, 2820, 2832, 2804, 2848, 2872, 2888, 2852, 2884, 2920, 2860, 2928, 2880, 2960, 2932, 2936, 2892, 2988, 2568, 2560, 2952, 2944, 2940, 2996, 3012, 2968, 2660, 2672, 3004, 2908, 3056, 3088, 3104, 3100, 3092, 3128, 3148, 3160, 3132, 3168, 3124, 3204, 3108, 3212, 3192, 3220, 3232, 3244, 3256, 3272, 3276, 3264, 3292, 3284, 3308, 3320, 3332, 3348, 3364, 3224, 3356, 3116, 3376, 3404, 3416, 3424, 3236, 3388, 3476, 3448, 3492, 3496, 3504, 3508, 3540, 3520, 3572, 3556, 3580, 3596, 3632, 3648, 3640, 3660, 3676, 3664, 3644, 3528, 3708, 3680, 3700, 3732, 3720, 3776, 3736, 3756, 3784, 3800, 3816, 3832, 3792, 3812, 3844, 3896, 3852, 3880, 3876, 3960, 3972, 3928, 3988, 3984, 3948, 3992, 3796, 3996, 4016, 3924, 4024, 4060, 4048, 4040, 4072, 4004, 4020, 4092, 4052, 3964, 3808, 4028, 3728, 3804, 3616, 3576, 4076, 3180, 3712, 3828, 4008, 3740, 3768, 4084, 3500, 3548, 3692, 3612, 3668, 3156, 3564, 3440, 3748, 3208, 3340, 3368, 3352, 3260, 3316, 3468, 3872, 4100, 4128, 4132, 4164, 4112, 4180, 3940, 4168, 3400, 4152, 4228, 4232, 4192, 4260, 4248, 4136, 4200, 4116, 4144, 4276, 4280, 4156, 4288, 4284, 4240, 4292, 4324, 4256, 4304, 4316, 4204, 4340, 4348, 4344, 4356, 4396, 4368, 4412, 4408, 4392, 4456, 4476, 4492, 4508, 4488, 4272, 4428, 4544, 4560, 4436, 4484, 4564, 4380, 4520, 4404, 4512, 4588, 4584, 4592, 4576, 4516, 536, 4608, 4632, 4648, 4660, 4472, 4600, 632, 4676, 4672, 4628, 4480, 4596, 4604, 4536, 4636, 4752, 4764, 4776, 4792, 4704, 4700, 4784, 4680, 4716, 4688, 4740, 4816, 4748, 4828, 4840, 4812, 4856, 4824, 4768, 4756, 4892, 4896, 4928, 4940, 4956, 4944, 4952, 4876, 4852, 4988, 5004, 5020, 5032, 4984, 5036, 4884, 4936, 4904, 5048, 5040, 4908, 5052, 4968, 5060, 5080, 5076, 5016, 5012, 4948, 4868, 5088, 5104, 5164, 5136, 5180, 5128, 5208, 5192, 5124, 5236, 5176, 5184, 5140, 5256, 5216, 5252, 5264, 5296, 5316, 5244, 5312, 5328, 5224, 5360, 5380, 5384, 5396, 5300, 5280, 5420, 5436, 5364, 5424, 5456, 5400, 5376, 5288, 5460, 5272, 5408, 5416, 5528, 5544, 5536, 5560, 5332, 5480, 5512, 5572, 5340, 5564, 5472, 5588, 5604, 5524, 5520, 5616, 5448, 5504, 5352, 5624, 5612, 5644, 5468, 5656, 5668, 5688, 5704, 5720, 5728, 5748, 5160, 5660, 5212, 5684, 5628, 5772, 5756, 5784, 5796, 5800, 5820, 5824, 5696, 5840, 5856, 5852, 5872, 5844, 5876, 5888, 5900, 5792, 5652, 5920, 5912, 5892, 5960, 5916, 5836, 5936, 5808, 5776, 5972, 5984, 5992, 6012, 6008, 5944, 6016, 6020, 5968, 6004, 5932, 6060, 6072, 6092, 6104, 6108, 6088, 6124, 6136, 6052, 6112, 6000, 6080, 6096, 6040, 6140, 6036, 6176, 6076, 6184, 6152, 6160, 6204, 6180, 6232, 6188, 6244, 6272, 6256, 6236, 6268, 6276, 6208, 6304, 6248, 6292, 6224, 6344, 6228, 6316, 6324, 6372, 6396, 6412, 6428, 6432, 6420, 6364, 6476, 6404, 6384, 6380, 6296, 6444, 6352, 6368, 6340, 6308, 6468, 6520, 6540, 6528, 6536, 6564, 6524, 6552, 6588, 6580, 6612, 6604, 6644, 6620, 6504, 6624, 6648, 6656, 6600, 6548, 6616, 6636, 6512, 6680, 6440, 6460, 6456, 6716, 6708, 6728, 6748, 6740, 6688, 6724, 6764, 6768, 6772, 6788, 6776, 6704, 6784, 6832, 6800, 6852, 6868, 6860, 6812, 6836, 6820, 6904, 6892, 6916, 6864, 6804, 6816, 6956, 6964, 6948, 6936, 6980, 6928, 7000, 6912, 6924, 7008, 6908, 7004, 6700, 7036, 7052, 7044, 7064, 7048, 7076, 7092, 7116, 7120, 7128, 7108, 7080, 7060, 7164, 7160, 7084, 7096, 7144, 7104, 7212, 7188, 7228, 7240, 7172, 7248, 7256, 7252, 7300, 7236, 7204, 7276, 7316, 7216, 7264, 7320, 7352, 7336, 7360, 7376, 7364, 7380, 7368, 7388, 7192, 7196, 7396, 7400, 7372, 7436, 7448, 7464, 7476, 7488, 7496, 7520, 7424, 7512, 7524, 7540, 7544, 7564, 7384, 7536, 7576, 7588, 7460, 7492, 7528, 7428, 7552, 7628, 7648, 7660, 7572, 7636, 7620, 7656, 7676, 7664, 7712, 7724, 7736, 7732, 7756, 7772, 7784, 7696, 7708, 7716, 7624, 7804, 7604, 7744, 7752, 7816, 7832, 7848, 7860, 7776, 7868, 7864, 7852, 7840, 7892, 7912, 7788, 7928, 7916, 7700, 7616, 7976, 7960, 7964, 7984, 7992, 7940, 7988, 7996, 8024, 8040, 8052, 8016, 8076, 8028, 7932, 8096, 8116, 8132, 8148, 8164, 8176, 8188, 8168, 8160, 7896, 8184, 8048, 8088, 8012, 8104, 8152, 8112, 8072, 8004, 8208, 8224, 8236, 8240, 8256, 8252, 8284, 8300, 8312, 8292, 8328, 8264, 8220, 8320, 8008, 8336, 8332, 8384, 8400, 8416, 8368, 8420, 8460, 8472, 8484, 8480, 8464, 8500, 8380, 8348, 8512, 8504, 8356, 8520, 8536, 8548, 8552, 8568, 8580, 8596, 8600, 8616, 8632, 8608, 8532, 8572, 8652, 8668, 8676, 8688, 8684, 8696, 8712, 8728, 8744, 8764, 8780, 8792, 8788, 8804, 8820, 8752, 8808, 8832, 8844, 8828, 8868, 8876, 8880, 8916, 8928, 8936, 8920, 8736, 8852, 8956, 8960, 8980, 8964, 8988, 8984, 8992, 8932, 8952, 8996, 8924, 9020, 9048, 9060, 8896, 8724, 9008, 9076, 9084, 9104, 9100, 9128, 9140, 9152, 9120, 9136, 9164, 9168, 9176, 9032, 8624, 9040, 9132, 9148, 8680, 9056, 9160, 9208, 8904, 9192, 8840, 8516, 9196, 8588, 8340, 8232, 8940, 8304, 8228, 8200, 9180, 8612, 9000, 9204, 9224, 8476, 9252, 9256, 9276, 9268, 8424, 9272, 9324, 9280, 9312, 9316, 9340, 9288, 9360, 9336, 9348, 9396, 9392, 9384, 9376, 9364, 9352, 9424, 9416, 9452, 9460, 9476, 9468, 9496, 9492, 9448, 9504, 9520, 9528, 9532, 9408, 9548, 9508, 9564, 9596, 9592, 9604, 9624, 9632, 9644, 9652, 9640, 9648, 9664, 9684, 9572, 9412, 9612, 9680, 9696, 9712, 9728, 9700, 9744, 9720, 9724, 9740, 9764, 9772, 9788, 9812, 9792, 9824, 9756, 9820, 9796, 9836, 9852, 9868, 9692, 9860, 9864, 9856, 9880, 9900, 9952, 9916, 9924, 9956, 9892, 9928, 9964, 9896, 9456, 9544, 9472, 9244, 9976, 10024, 10044, 9248, 9540, 10072, 10076, 10060, 10092, 10080, 9944, 10008, 10064, 10056, 10096, 10120, 10136, 9888, 9980, 9988, 10128, 9808, 10172, 10048, 10176, 10204, 10220, 10224, 10052, 9780, 10036, 10160, 10180, 10192, 10256, 10104, 10112, 10284, 10276, 10184, 10316, 10304, 10340, 10300, 10324, 10348, 10356, 10272, 10332, 10280, 10392, 10312, 10292, 10244, 10424, 10420, 10440, 10436, 10452, 10432, 10380, 10364, 10388, 10472, 10492, 10468, 10540, 10516, 10524, 10536, 10556, 10520, 10476, 10496, 10568, 10584, 10564, 10612, 10616, 10604, 10624, 10580, 10664, 10656, 10668, 10672, 10692, 10680, 10644, 10648, 10708, 10756, 10740, 10748, 10752, 10640, 10700, 10772, 10784, 10788, 10792, 10796, 10808, 10836, 10780, 10704, 10736, 10852, 10840, 10860, 10868, 10888, 10800, 10916, 10828, 10932, 10936, 10940, 10900, 10928, 10960, 10824, 10972, 10968, 10976, 10980, 10992, 10948, 11016, 10912, 11024, 11032, 11020, 11040, 11084, 11004, 11012, 11068, 11076, 11056, 11112, 11080, 11128, 11060, 11164, 11176, 11172, 11124, 11116, 11140, 11196, 11216, 11200, 11220, 11236, 11204, 11232, 11240, 11052, 10844, 10504, 10416, 11288, 11180, 11324, 11336, 11300, 11296, 11332, 11312, 11348, 11380, 11392, 11400, 11316, 11376, 11280, 11368, 11372, 11404, 11416, 11292, 11412, 11460, 11476, 11484, 11364, 11472, 11500, 11480, 11516, 11544, 11520, 11508, 11440, 11560, 11504, 11488, 11596, 11576, 11568, 11536, 11604, 11632, 11564, 11640, 11592, 11648, 11644, 11628, 11636, 11652, 11624, 11660, 11720, 11676, 11700, 11748, 11716, 11776, 11796, 11768, 11708, 11712, 11736, 11808, 11816, 11812, 11836, 11848, 11800, 11868, 11804, 11872, 11908, 11924, 11928, 11744, 11860, 11920, 11932, 11784, 11900, 11888, 11912, 11780, 11984, 11884, 11980, 12008, 12016, 12024, 12032, 11832, 12000, 11996, 12060, 12020, 12056, 11956, 12092, 11952, 12004, 12140, 12156, 12104, 12088, 12076, 12068, 12164, 12184, 12212, 12152, 12096, 12228, 12232, 12148, 12192, 12240, 12264, 12276, 11960, 12108, 12284, 12268, 12176, 12084, 12224, 12180, 12272, 12300, 12312, 12340, 12316, 12260, 12356, 12388, 12380, 12332, 12372, 12408, 12412, 12344, 12324, 12432, 12308, 12368, 12484, 12448, 12468, 12472, 12364, 12296, 12508, 12524, 12544, 12556, 12568, 12540, 12512, 12444, 12464, 12600, 12536, 12604, 12596, 12616, 12572, 12440, 12292, 12252, 12636, 12552, 12664, 12652, 12692, 12700, 12684, 12720, 12716, 12740, 12760, 12660, 12680, 12756, 12776, 12416, 12784, 12792, 12748, 12824, 12804, 12832, 12560, 12768, 12800, 12808, 12644, 12856, 12880, 12884, 12668, 12892, 12812, 12904, 12848, 12928, 12936, 12932, 12948, 12960, 12972, 12984, 12992, 13016, 13028, 13012, 12920, 12964, 12988, 13052, 13004, 12772, 13080, 13092, 13112, 13120, 13116, 13136, 13096, 13000, 13100, 13148, 13180, 13160, 13176, 13188, 13184, 13076, 13068, 13232, 13244, 13228, 13256, 13240, 13260, 13276, 13308, 13268, 13084, 12900, 13040, 13288, 13156, 12864, 13200, 13332, 13348, 13340, 13328, 13376, 13384, 13400, 13252, 13420, 13404, 13316, 13432, 13444, 13368, 13472, 13488, 13480, 13320, 13428, 13416, 13396, 13356, 13520, 13540, 13460, 13512, 13560, 13528, 13576, 13360, 13364, 13236, 13588, 13556, 13608, 13612, 13636, 13652, 13656, 13680, 13592, 13436, 13620, 13692, 13616, 13668, 13648, 13732, 13628, 13712, 13760, 13776, 13748, 13804, 13664, 13752, 13728, 13772, 13820, 13844, 13860, 13764, 13876, 13880, 13892, 13908, 13920, 13916, 13848, 13888, 13800, 13924, 13872, 13836, 13832, 13956, 13972, 13984, 13960, 13980, 13992, 13864, 14000, 14012, 14032, 14024, 14028, 14040, 14048, 14044, 13740, 13988, 14092, 14052, 13944, 13828, 13824, 14076, 14068, 14132, 14148, 13964, 14128, 14104, 14168, 14184, 14192, 14200, 14220, 14224, 14256, 14268, 14216, 14260, 14208, 13976, 14204, 14276, 14144, 14272, 14308, 14304, 14320, 14332, 14288, 14296, 14292, 14172, 14360, 14376, 14392, 14316, 14408, 14420, 14448, 14460, 14424, 14472, 14480, 14496, 14380, 14484, 14536, 14500, 14476, 14548, 14556, 14384, 14592, 14608, 14368, 14564, 14612, 14632, 14644, 14656, 14668, 14528, 14588, 14692, 14708, 14724, 14728, 14688, 14756, 14768, 14788, 14804, 14816, 14824, 14840, 14852, 14848, 14676, 14828, 14836, 14860, 14572, 14876, 14888, 14884, 14900, 14872, 14340, 14772, 14740, 14880, 14936, 14944, 14924, 14672, 14928, 14892, 14620, 14940, 14512, 14732, 14776, 14660, 14664, 14964, 14600, 14760, 15000, 15004, 14952, 14444, 15016, 15036, 15052, 15072, 15088, 15092, 15096, 15080, 15100, 14440, 15112, 15116, 15140, 15148, 14984, 15160, 15164, 15172, 15084, 14560, 15196, 15204, 15108, 15212, 15232, 15256, 15220, 15216, 15152, 15264, 15252, 15280, 15292, 15284, 15168, 15312, 15328, 15344, 15356, 15288, 15332, 15240, 15068, 15060, 14628, 15272, 15316, 15348, 15372, 15388, 15396, 15400, 15408, 15404, 15420, 15392, 15308, 15424, 15440, 15432, 15468, 15380, 15368, 15452, 15496, 15492, 15512, 15500, 15476, 15548, 15564, 15508, 15484, 15528, 15540, 15572, 15568, 15588, 15600, 15596, 15624, 15612, 15608, 15620, 15656, 15660, 15676, 15696, 15732, 15744, 15748, 15700, 15628, 15752, 15756, 15740, 15704, 15716, 15784, 15808, 15680, 15672, 15776, 15728, 15820, 15812, 15816, 15852, 15804, 15864, 15880, 15764, 15800, 15896, 15868, 15908, 15856, 15888, 15936, 15964, 15976, 15960, 15924, 15968, 15980, 15932, 15996, 15988, 15832, 15972, 15904, 16044, 15928, 16020, 16028, 16040, 16084, 15984, 16116, 16096, 16080, 16152, 16164, 16092, 16072, 16184, 16192, 16156, 16104, 16128, 16168, 16140, 16212, 16088, 16176, 16064, 16232, 16112, 16252, 16264, 16236, 16292, 16256, 16284, 764, 16324, 16272, 16240, 16308, 16316, 16200, 16336, 16348, 16372, 16376, 16228, 16344, 16220, 16404, 16408, 16420, 16360, 16432, 16448, 16440, 16452, 16444, 16480, 16508, 16504, 16488, 16500, 16460, 16536, 16312, 16524, 16548, 16556, 16520, 16584, 16592, 16632, 16628, 16640, 16572, 16468, 16552, 16648, 16604, 16568, 16424, 16676, 16684, 16636, 16680, 16588, 16616, 16728, 16476, 16740, 16768, 16784, 16752, 16736, 16760, 16832, 16840, 16848, 16856, 16800, 16852, 16864, 16892, 16904, 16716, 16672, 16916, 16824, 16924, 16704, 16948, 16796, 16956, 16952, 16936, 16808, 16988, 16880, 16820, 16772, 16996, 16744, 16932, 17000, 17008, 17020, 16724, 16608, 16984, 17052, 17040, 16776, 17068, 17060, 17072, 17056, 17100, 17136, 17148, 17120, 17116, 17092, 17172, 17164, 17188, 17084, 17024, 17208, 17088, 740], #0: [], #2049: {8200, 8208, 16404, 16408, 8220, 8224, 8228, 16420, 8232, 16424, 8236, 8240, 16432, 16440, 8252, 16444, 8256, 16448, 16452, 8264, 16460, 16468, 8284, 16476, 16480, 8292, 16488, 8300, 8304, 16500, 8312, 16504, 16508, 8320, 8328, 16520, 8332, 16524, 8336, 8340, 16536, 8348, 8356, 16548, 16552, 16556, 8368, 16568, 8380, 16572, 8384, 16584, 16588, 8400, 16592, 16604, 8416, 16608, 8420, 8424, 16616, 16628, 16632, 16636, 16640, 16648, 8460, 8464, 8472, 8476, 8480, 16672, 8484, 16676, 16680, 16684, 8500, 8504, 8512, 16704, 8516, 8520, 16716, 8532, 16724, 8536, 16728, 16736, 8548, 16740, 8552, 16744, 16752, 8568, 16760, 8572, 16768, 8580, 16772, 16776, 8588, 16784, 8596, 8600, 16796, 8608, 16800, 8612, 8616, 16808, 8624, 436, 16820, 8632, 16824, 16832, 16840, 8652, 16848, 16852, 16376, 16856, 8668, 16864, 8676, 8680, 8684, 8688, 16880, 8696, 16892, 8712, 16904, 8724, 16916, 536, 8728, 16924, 8736, 16932, 8744, 16936, 8752, 16948, 16952, 8764, 16956, 8780, 8788, 8792, 16984, 16988, 8804, 16996, 8808, 17000, 17008, 8820, 632, 8828, 17020, 8832, 17024, 8840, 8844, 17040, 8852, 17052, 17056, 8868, 17060, 8876, 17068, 8880, 17072, 17084, 8896, 17088, 17092, 712, 8904, 17100, 724, 8916, 8920, 8924, 17116, 8928, 17120, 8932, 740, 8936, 8940, 752, 17136, 8952, 8956, 764, 17148, 8960, 8964, 17164, 8980, 17172, 17176, 8984, 796, 8988, 8992, 804, 8996, 17188, 808, 9000, 812, 816, 9008, 820, 824, 17208, 828, 9020, 9032, 844, 9040, 9048, 864, 9056, 868, 9060, 872, 9076, 888, 892, 9084, 896, 9100, 912, 9104, 916, 920, 928, 9120, 932, 936, 9128, 9132, 9136, 948, 9140, 952, 956, 9148, 960, 9152, 968, 9160, 9164, 976, 9168, 984, 9176, 9180, 996, 9192, 1004, 9196, 1008, 1012, 9204, 9208, 1020, 9224, 1036, 1044, 1048, 9244, 9248, 1060, 9252, 9256, 1068, 1072, 9268, 9272, 1084, 9276, 9280, 1096, 9288, 1104, 1112, 1116, 9312, 1124, 9316, 1128, 9324, 1136, 9336, 9340, 1152, 1156, 9348, 9352, 9360, 1172, 9364, 1180, 9376, 1188, 1192, 9384, 9392, 1204, 9396, 1208, 1212, 1216, 9408, 9412, 1220, 1224, 9416, 1228, 1232, 9424, 1236, 1256, 9448, 9452, 1264, 9456, 9460, 9468, 1280, 9472, 1284, 9476, 1288, 1292, 9492, 1304, 9496, 1308, 9504, 9508, 1320, 1324, 1328, 9520, 9528, 9532, 1344, 1348, 9540, 9544, 1356, 9548, 1364, 1372, 9564, 9572, 1388, 1392, 1396, 9592, 9596, 1408, 1412, 9604, 1416, 1420, 9612, 1424, 1428, 9624, 9632, 9640, 1452, 9644, 9648, 1460, 9652, 1468, 1472, 9664, 1476, 1480, 1488, 9680, 9684, 9692, 1504, 9696, 9700, 1512, 1516, 1520, 9712, 1524, 9720, 1532, 9724, 1536, 9728, 9740, 9744, 1556, 9756, 1568, 9764, 1576, 9772, 1584, 9780, 9788, 1600, 9792, 1604, 9796, 1608, 1612, 9808, 1620, 9812, 1624, 1628, 9820, 9824, 1636, 1640, 9836, 1648, 9852, 9856, 9860, 1672, 9864, 1676, 9868, 1688, 9880, 1696, 9888, 1700, 9892, 1704, 9896, 9900, 1712, 1716, 9916, 9924, 1736, 9928, 1744, 9944, 1756, 1760, 9952, 1764, 9956, 1768, 1772, 9964, 9976, 9980, 9988, 1800, 1804, 10008, 1820, 1824, 1832, 10024, 1844, 10036, 1848, 1852, 10044, 1856, 10048, 10052, 10056, 1868, 10060, 10064, 10072, 1884, 10076, 10080, 1892, 1900, 10092, 10096, 10104, 1916, 1920, 10112, 10120, 10128, 1940, 1944, 10136, 1948, 10160, 1980, 10172, 10176, 1988, 10180, 1992, 10184, 2000, 10192, 2004, 2008, 2012, 10204, 2016, 2028, 10220, 10224, 2036, 2040, 2044, 10244, 2056, 2060, 10256, 2076, 10272, 2084, 10276, 10280, 2092, 10284, 10292, 2108, 10300, 2112, 10304, 2116, 10312, 10316, 2128, 10324, 2140, 10332, 2144, 2148, 10340, 2152, 2156, 10348, 2160, 2164, 10356, 10364, 2180, 10380, 2192, 10388, 2200, 10392, 2204, 2212, 2216, 2220, 10416, 10420, 10424, 2236, 2240, 10432, 10436, 10440, 10452, 2268, 2272, 10468, 10472, 10476, 2288, 2292, 2296, 10492, 10496, 10504, 2324, 10516, 2328, 10520, 10524, 10536, 2348, 10540, 2352, 2356, 2360, 10556, 2372, 10564, 2376, 10568, 2380, 2384, 2388, 10580, 10584, 2396, 2400, 2408, 2412, 10604, 2416, 10612, 10616, 10624, 2444, 2448, 10640, 2452, 10644, 2456, 10648, 10656, 2472, 10664, 10668, 10672, 2484, 10680, 2496, 2500, 10692, 2504, 2508, 10700, 2512, 10704, 2516, 10708, 2524, 2532, 2536, 2544, 10736, 10740, 10748, 2560, 10752, 2564, 10756, 2568, 2572, 2576, 10772, 2584, 10780, 10784, 10788, 2600, 10792, 10796, 2608, 10800, 2612, 10808, 2620, 2624, 2632, 10824, 10828, 10836, 10840, 10844, 2656, 2660, 10852, 10860, 2672, 2676, 10868, 2680, 2684, 2696, 10888, 2700, 2704, 2708, 10900, 2712, 2716, 10912, 2724, 10916, 2728, 10928, 2740, 10932, 10936, 10940, 10948, 2760, 2768, 10960, 2776, 10968, 10972, 2784, 10976, 10980, 2800, 10992, 2804, 11004, 2820, 11012, 11016, 11020, 2832, 11024, 2836, 11032, 2848, 11040, 2852, 2860, 11052, 11056, 11060, 2872, 11068, 2880, 2884, 11076, 2888, 11080, 2892, 11084, 2908, 2920, 11112, 11116, 2928, 2932, 11124, 2936, 11128, 2940, 2944, 11140, 2952, 2960, 2968, 11164, 11172, 11176, 2988, 11180, 2996, 3004, 11196, 11200, 3012, 11204, 11216, 11220, 11232, 11236, 11240, 3056, 3088, 11280, 3092, 11288, 3100, 11292, 3104, 11296, 3108, 11300, 3116, 11312, 3124, 11316, 3128, 3132, 11324, 11332, 11336, 3148, 3156, 11348, 3160, 3168, 11364, 11368, 3180, 11372, 11376, 11380, 3192, 11392, 3204, 3208, 11400, 3212, 11404, 3220, 11412, 3224, 11416, 3232, 3236, 3244, 11440, 3256, 3260, 3264, 11460, 3272, 3276, 11472, 3284, 11476, 11480, 3292, 11484, 11488, 3308, 11500, 11504, 3316, 11508, 3320, 11516, 11520, 3332, 3340, 11536, 3348, 3352, 11544, 3356, 3364, 3368, 11560, 11564, 3376, 11568, 11576, 3388, 3400, 11592, 3404, 11596, 11604, 3416, 3424, 11624, 11628, 3440, 11632, 11636, 3448, 11640, 11644, 11648, 11652, 3468, 11660, 3476, 11676, 3492, 3496, 3500, 3504, 3508, 11700, 11708, 3520, 11712, 11716, 3528, 11720, 3540, 11736, 3548, 11744, 3556, 11748, 3564, 3572, 3576, 11768, 3580, 11776, 11780, 11784, 3596, 11796, 11800, 3612, 11804, 3616, 11808, 11812, 11816, 3632, 3640, 11832, 3644, 11836, 3648, 11848, 3660, 3664, 3668, 11860, 3676, 11868, 3680, 11872, 3692, 11884, 11888, 3700, 3708, 11900, 3712, 11908, 3720, 11912, 3728, 11920, 3732, 11924, 3736, 11928, 3740, 11932, 3748, 3756, 11952, 11956, 3768, 11960, 3776, 3784, 11980, 3792, 11984, 3796, 3800, 3804, 11996, 3808, 12000, 3812, 12004, 3816, 12008, 12016, 3828, 12020, 3832, 12024, 12032, 3844, 3852, 12056, 12060, 3872, 3876, 12068, 3880, 12076, 12084, 3896, 12088, 12092, 12096, 12104, 12108, 3924, 3928, 3940, 3948, 12140, 12148, 3960, 12152, 3964, 12156, 3972, 12164, 3984, 12176, 3988, 12180, 3992, 12184, 3996, 12192, 4004, 4008, 4016, 4020, 12212, 4024, 4028, 12224, 12228, 4040, 12232, 4048, 12240, 4052, 4060, 12252, 12260, 4072, 12264, 4076, 12268, 12272, 4084, 12276, 4092, 12284, 4100, 12292, 12296, 12300, 4112, 4116, 12308, 12312, 12316, 4128, 4132, 12324, 4136, 12332, 4144, 12340, 4152, 12344, 4156, 4164, 12356, 4168, 12364, 12368, 4180, 12372, 12380, 4192, 12388, 4200, 4204, 12408, 12412, 12416, 4228, 4232, 4240, 12432, 4248, 12440, 12444, 4256, 12448, 4260, 4272, 12464, 4276, 12468, 4280, 12472, 4284, 4288, 4292, 12484, 4304, 4316, 12508, 12512, 4324, 12524, 4340, 4344, 12536, 4348, 12540, 12544, 4356, 12552, 12556, 4368, 12560, 12568, 4380, 12572, 4392, 4396, 4404, 12596, 4408, 12600, 4412, 12604, 12616, 4428, 4436, 12636, 12644, 4456, 12652, 12660, 4472, 12664, 4476, 12668, 4480, 4484, 4488, 12680, 4492, 12684, 12692, 4508, 12700, 4512, 4516, 4520, 12716, 12720, 4536, 4544, 12740, 12748, 4560, 4564, 12756, 12760, 4576, 12768, 12772, 4584, 12776, 4588, 4592, 12784, 4596, 4600, 12792, 4604, 4608, 12800, 12804, 12808, 12812, 4628, 4632, 12824, 4636, 12832, 4648, 12848, 4660, 12856, 4672, 12864, 4676, 4680, 4688, 12880, 12884, 4700, 12892, 4704, 12900, 12904, 4716, 12920, 12928, 4740, 12932, 12936, 4748, 4752, 4756, 12948, 4764, 4768, 12960, 12964, 4776, 12972, 4784, 4792, 12984, 12988, 12992, 13000, 4812, 13004, 4816, 13012, 4824, 13016, 4828, 13028, 4840, 13040, 4852, 4856, 13052, 4868, 4876, 13068, 4884, 13076, 13080, 4892, 13084, 4896, 13092, 4904, 13096, 4908, 13100, 13112, 13116, 4928, 13120, 4936, 4940, 4944, 13136, 4948, 4952, 4956, 13148, 13156, 4968, 13160, 4984, 13176, 4988, 13180, 13184, 13188, 5004, 13200, 5012, 5016, 5020, 5032, 5036, 13228, 5040, 13232, 13236, 5048, 13240, 5052, 13244, 5060, 13252, 13256, 13260, 5076, 13268, 5080, 13276, 5088, 13288, 5104, 13308, 5124, 13316, 5128, 13320, 5136, 13328, 5140, 13332, 13340, 13348, 5160, 5164, 13356, 13360, 13364, 5176, 13368, 5180, 5184, 13376, 5192, 13384, 13396, 5208, 13400, 5212, 13404, 5216, 5224, 13416, 13420, 5236, 13428, 13432, 5244, 13436, 5252, 13444, 5256, 5264, 13460, 5272, 5280, 13472, 5288, 13480, 5296, 13488, 5300, 5312, 5316, 13512, 5328, 13520, 5332, 13528, 5340, 13540, 5352, 5360, 5364, 13556, 13560, 5376, 5380, 5384, 13576, 5396, 13588, 5400, 13592, 5408, 5416, 13608, 5420, 13612, 5424, 13616, 13620, 5436, 13628, 13636, 5448, 5456, 13648, 5460, 13652, 13656, 5468, 5472, 13664, 13668, 5480, 13680, 13692, 5504, 5512, 5520, 13712, 5524, 5528, 5536, 13728, 13732, 5544, 13740, 13748, 5560, 13752, 5564, 13760, 5572, 13764, 13772, 13776, 5588, 5604, 13800, 5612, 13804, 5616, 5624, 5628, 13820, 13824, 13828, 13832, 5644, 13836, 5652, 13844, 5656, 13848, 5660, 5668, 13860, 13864, 13872, 5684, 13876, 5688, 13880, 5696, 13888, 13892, 5704, 13908, 5720, 13916, 5728, 13920, 13924, 5748, 13944, 5756, 13956, 13960, 5772, 13964, 5776, 13972, 5784, 13976, 13980, 5792, 13984, 5796, 13988, 5800, 13992, 5808, 14000, 5820, 14012, 5824, 14024, 5836, 14028, 5840, 14032, 5844, 14040, 5852, 14044, 5856, 14048, 14052, 5872, 5876, 14068, 14076, 5888, 5892, 5900, 14092, 5912, 14104, 5916, 5920, 5932, 5936, 14128, 14132, 5944, 14144, 14148, 5960, 5968, 5972, 14168, 14172, 5984, 5992, 14184, 6000, 14192, 6004, 6008, 14200, 6012, 14204, 6016, 14208, 6020, 14216, 14220, 14224, 6036, 6040, 6052, 6060, 14256, 14260, 6072, 6076, 14268, 6080, 14272, 14276, 6088, 6092, 6096, 14288, 14292, 6104, 14296, 6108, 6112, 14304, 14308, 6124, 14316, 14320, 6136, 6140, 14332, 14340, 6152, 6160, 14360, 6176, 14368, 6180, 6184, 14376, 6188, 14380, 14384, 14392, 6204, 6208, 14408, 6224, 6228, 14420, 6232, 14424, 6236, 6244, 6248, 14440, 14444, 6256, 14448, 6268, 14460, 6272, 6276, 14472, 14476, 14480, 6292, 14484, 6296, 6304, 14496, 6308, 14500, 6316, 14512, 6324, 14528, 6340, 6344, 14536, 6352, 14548, 6364, 14556, 6368, 14560, 6372, 14564, 6380, 14572, 6384, 6396, 14588, 14592, 6404, 14600, 6412, 14608, 6420, 14612, 6428, 14620, 6432, 14628, 6440, 14632, 6444, 14644, 6456, 6460, 14656, 6468, 14660, 14664, 6476, 14668, 14672, 14676, 14688, 14692, 6504, 6512, 14708, 6520, 6524, 6528, 14724, 6536, 14728, 6540, 14732, 6548, 14740, 6552, 6564, 14756, 14760, 14768, 6580, 14772, 14776, 6588, 14788, 6600, 6604, 6612, 14804, 6616, 6620, 6624, 14816, 14824, 6636, 14828, 6644, 14836, 6648, 14840, 6656, 14848, 14852, 14860, 6680, 14872, 14876, 6688, 14880, 14884, 14888, 6700, 14892, 6704, 6708, 14900, 6716, 6724, 6728, 14924, 14928, 6740, 14936, 6748, 14940, 14944, 14952, 6764, 6768, 6772, 14964, 6776, 6784, 6788, 14984, 6800, 6804, 15000, 6812, 15004, 6816, 6820, 15016, 6832, 6836, 15036, 6852, 6860, 15052, 6864, 6868, 15060, 15068, 15072, 15080, 6892, 15084, 15088, 15092, 6904, 15096, 6908, 15100, 6912, 6916, 15108, 15112, 6924, 15116, 6928, 6936, 6948, 15140, 6956, 15148, 15152, 6964, 15160, 15164, 15168, 6980, 15172, 7000, 7004, 15196, 7008, 15204, 15212, 15216, 15220, 7036, 15232, 7044, 7048, 15240, 7052, 7060, 15252, 7064, 15256, 15264, 7076, 7080, 15272, 7084, 15280, 7092, 15284, 7096, 15288, 15292, 7104, 7108, 7116, 15308, 7120, 15312, 15316, 7128, 15328, 15332, 7144, 15344, 15348, 7160, 7164, 15356, 7172, 15368, 15372, 7188, 15380, 7192, 7196, 15388, 15392, 7204, 15396, 15400, 7212, 15404, 7216, 15408, 7228, 15420, 15424, 7236, 7240, 15432, 7248, 15440, 7252, 7256, 15452, 7264, 7276, 15468, 15476, 15484, 7300, 15492, 15496, 15500, 7316, 15508, 7320, 15512, 7336, 15528, 15540, 7352, 15548, 7360, 7364, 7368, 7372, 15564, 7376, 15568, 7380, 15572, 7384, 7388, 7396, 15588, 7400, 15596, 15600, 15608, 15612, 7424, 7428, 15620, 15624, 7436, 15628, 7448, 7460, 7464, 15656, 15660, 7476, 15672, 15676, 7488, 15680, 7492, 7496, 15696, 15700, 7512, 15704, 7520, 7524, 15716, 7528, 7536, 15728, 7540, 15732, 7544, 15740, 7552, 15744, 15748, 15752, 7564, 15756, 7572, 15764, 7576, 15776, 7588, 15784, 7604, 15800, 15804, 7616, 15808, 7620, 15812, 7624, 15816, 7628, 15820, 7636, 15832, 7648, 7656, 7660, 15852, 7664, 15856, 15864, 7676, 15868, 15880, 7696, 15888, 7700, 15896, 7708, 7712, 15904, 7716, 15908, 7724, 7732, 15924, 7736, 15928, 15932, 7744, 15936, 7752, 7756, 15960, 7772, 15964, 7776, 15968, 15972, 7784, 15976, 7788, 15980, 15984, 15988, 7804, 15996, 7816, 16020, 7832, 16028, 7840, 7848, 16040, 7852, 16044, 7860, 7864, 7868, 16064, 16072, 16080, 7892, 16084, 7896, 16088, 16092, 16096, 7912, 16104, 7916, 16112, 16116, 7928, 7932, 16128, 7940, 16140, 7960, 16152, 7964, 16156, 16164, 7976, 16168, 7984, 16176, 7988, 7992, 16184, 7996, 16192, 8004, 8008, 16200, 8012, 8016, 16212, 8024, 8028, 16220, 16228, 8040, 16232, 16236, 8048, 16240, 8052, 16252, 16256, 8072, 16264, 8076, 16272, 8088, 16284, 8096, 16292, 8104, 8112, 8116, 16308, 16312, 16316, 8132, 16324, 16336, 8148, 8152, 16344, 16348, 8160, 8164, 8168, 16360, 8176, 16372, 8184, 8188}, 79.520764) 2020-02-17 15:47:31.336759 p8380 ERR ActorAdmin uncaught exception: Traceback (most recent call last): File "C:\Users\dvyd.conda\envs\activefiction\lib\site-packages\thespian\system\admin\convention.py", line 644, in run delay.remaining()) File "C:\Users\dvyd.conda\envs\activefiction\lib\site-packages\thespian\system\transport\wakeupTransportBase.py", line 71, in run rval = self._run_subtransport(incomingHandler, max_runtime) File "C:\Users\dvyd.conda\envs\activefiction\lib\site-packages\thespian\system\transport\wakeupTransportBase.py", line 80, in _run_subtransport rval = self._runWithExpiry(incomingHandler) File "C:\Users\dvyd.conda\envs\activefiction\lib\site-packages\thespian\system\transport\TCPTransport.py", line 1141, in _runWithExpiry set(wsend+wrecv), delay) ValueError: too many file descriptors in select()

On Mon, Feb 17, 2020 at 9:26 PM Kevin Quick notifications@github.com wrote:

Let me address your two concerns individually: memory utilization and timeouts.

-

For memory utilization, I'm afraid this may be unavoidable. The minimum overhead for a Python application seems to be about 20-30KB (at least under Linux), which seems to be related to the core interpreter, shared libraries, and the various python objects that are being maintained by the GC in the cloned processes. I did some work a couple of years ago to try to minimize this footprint but I was unable to reduce it beyond this size threshold.

One of the constraints here is that Thespian is implementing each Actor as a separate system process. This ensures separation between Actors, but it's also a heavy-weight isolation mechanism. I had considered an alternative base implementation allowing each Actor to be a separate thread instead of a separate process as a smaller footprint, but I ran into some significant concerns relative to the GIL, where any Actor would then have the ability to stop all of the Actors. I think that a thread-based implementation would be possible, with some caveats and restrictions, but it's difficult to achieve Erlang-style scalability for Actors without support for this at the VM level.

The various approaches I could suggest at this point are:

1 - use multiple systems with a convention to spread Actors across different system 2 - change the level of granularity for Actors: combine functionality to have fewer Actors capable of doing more things. I know this is counter to the general advice with Actors, but it's one way to mitigate your scalability issue. 3 - you could try multi-threading your actors. Thespian should support Actors which have multiple threads: the receiveMessage() will only be activate on the "primary" thread although other threads are allowed to call self.send(). Any other synchronization is up to you. Again, I hesitate to suggest this because it adds considerable complication and the normal advice is to stick to a single concurrency architecture, but again, it's a practical approach to dealing with your underlying constraints.

With regards to the timeouts, this may be somewhat related to the scaling issue, but it's also a bit unexpected. I've used Thespian in systems with > 1000 actors successfully. It would be good to know if the timeouts only start occurring when you reach a certain threshold number of Actors or corresponding activity to know if this is a threshold issue or a consistent gradual issue.

There is some internal logging Thespian generates that may be of some help to diagnose what is happening here. By default, it will write to $TMPDIR/thespian.log, although you can control this with the THESPLOG_FILE environment variable (ensure this is set in the process that starts the Admin to be properly applied). You can also use the THESPLOG_FILE_MAXSIZE environment variable to specify how large this file is allowed to grow (the value is the number of bytes and the default is 51200), and the THESPLOG_THRESHOLD to set the logging threshold (the default is "WARNING" and valid values are "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"). I'm happy to take a look at output from this log (either here or in a gist) to see if anything looks out of place.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kquick/Thespian/issues/57?email_source=notifications&email_token=AANTN7PZX53T5OYY54DERILRDLQHRA5CNFSM4KWSYJR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL7OG2Y#issuecomment-587129707, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANTN7L32K3LZ25BMENLYXTRDLQHRANCNFSM4KWSYJRQ .

davideps commented 4 years ago

Sorry--the list didn't wrap on my screen. I could have truncated it for easier reading.

On Mon, Feb 17, 2020 at 9:40 PM David Epstein davideps@umich.edu wrote:

Thanks Kevin. Does 20GB for 2,000 actors suggest each one is taking 10MB? If so, that is a lot more than the minimum of 20 to 30kb. Is there a way to find out why? This is what the log says:

2020-02-17 15:47:31.305327 p8380 ERR ValueError on select(#2049: [17176, 752, 712, 808, 816, 828, 724, 864, 872, 912, 896, 948, 916, 952, 888, 968, 984, 1008, 1012, 1020, 920, 960, 928, 976, 936, 932, 996, 820, 868, 892, 796, 956, 824, 812, 1044, 1036, 804, 1004, 1084, 1060, 844, 1072, 1068, 1048, 1128, 1104, 1116, 1136, 1152, 1124, 1180, 1156, 1188, 1204, 1220, 1224, 1172, 1216, 1232, 1192, 1264, 1280, 1288, 1304, 1292, 1324, 1320, 1356, 1348, 1344, 1364, 1372, 1388, 1392, 1396, 1328, 1412, 1428, 1308, 1420, 1452, 1472, 1460, 1476, 1504, 1512, 1480, 1516, 1524, 1520, 1568, 1556, 1608, 1532, 1600, 1536, 1584, 1604, 1488, 1612, 1620, 1628, 1624, 1636, 1672, 1712, 1640, 1700, 1716, 1416, 1468, 1256, 1576, 1696, 1744, 1676, 1688, 1424, 1208, 1648, 1096, 1768, 1760, 1772, 1284, 1704, 1804, 1228, 1856, 1820, 1236, 1756, 1832, 1844, 1852, 1112, 1736, 1800, 1764, 1892, 1868, 1884, 1848, 1408, 1212, 1900, 1920, 1824, 1948, 1940, 1944, 1916, 1992, 2008, 2044, 2040, 2036, 1988, 1980, 2012, 2000, 2028, 2060, 2004, 2092, 2084, 2116, 2076, 2112, 2128, 2156, 2108, 2144, 2140, 2160, 2152, 2148, 2164, 2016, 2204, 2216, 2212, 2240, 2220, 2180, 2236, 2192, 2200, 2272, 2292, 2268, 2348, 2296, 2056, 2352, 2380, 2356, 2288, 2388, 2408, 2372, 2376, 2416, 2396, 2412, 2444, 2360, 2400, 2456, 2452, 2328, 2496, 2472, 2448, 2500, 2508, 2516, 2536, 2504, 2524, 2544, 2484, 2532, 2512, 2576, 2384, 2600, 2564, 2584, 2324, 2608, 2612, 2620, 2624, 2632, 2572, 2676, 2700, 2656, 2712, 2724, 2696, 436, 2740, 2776, 2704, 2768, 2680, 2728, 2716, 2784, 2708, 2800, 2684, 2836, 2760, 2820, 2832, 2804, 2848, 2872, 2888, 2852, 2884, 2920, 2860, 2928, 2880, 2960, 2932, 2936, 2892, 2988, 2568, 2560, 2952, 2944, 2940, 2996, 3012, 2968, 2660, 2672, 3004, 2908, 3056, 3088, 3104, 3100, 3092, 3128, 3148, 3160, 3132, 3168, 3124, 3204, 3108, 3212, 3192, 3220, 3232, 3244, 3256, 3272, 3276, 3264, 3292, 3284, 3308, 3320, 3332, 3348, 3364, 3224, 3356, 3116, 3376, 3404, 3416, 3424, 3236, 3388, 3476, 3448, 3492, 3496, 3504, 3508, 3540, 3520, 3572, 3556, 3580, 3596, 3632, 3648, 3640, 3660, 3676, 3664, 3644, 3528, 3708, 3680, 3700, 3732, 3720, 3776, 3736, 3756, 3784, 3800, 3816, 3832, 3792, 3812, 3844, 3896, 3852, 3880, 3876, 3960, 3972, 3928, 3988, 3984, 3948, 3992, 3796, 3996, 4016, 3924, 4024, 4060, 4048, 4040, 4072, 4004, 4020, 4092, 4052, 3964, 3808, 4028, 3728, 3804, 3616, 3576, 4076, 3180, 3712, 3828, 4008, 3740, 3768, 4084, 3500, 3548, 3692, 3612, 3668, 3156, 3564, 3440, 3748, 3208, 3340, 3368, 3352, 3260, 3316, 3468, 3872, 4100, 4128, 4132, 4164, 4112, 4180, 3940, 4168, 3400, 4152, 4228, 4232, 4192, 4260, 4248, 4136, 4200, 4116, 4144, 4276, 4280, 4156, 4288, 4284, 4240, 4292, 4324, 4256, 4304, 4316, 4204, 4340, 4348, 4344, 4356, 4396, 4368, 4412, 4408, 4392, 4456, 4476, 4492, 4508, 4488, 4272, 4428, 4544, 4560, 4436, 4484, 4564, 4380, 4520, 4404, 4512, 4588, 4584, 4592, 4576, 4516, 536, 4608, 4632, 4648, 4660, 4472, 4600, 632, 4676, 4672, 4628, 4480, 4596, 4604, 4536, 4636, 4752, 4764, 4776, 4792, 4704, 4700, 4784, 4680, 4716, 4688, 4740, 4816, 4748, 4828, 4840, 4812, 4856, 4824, 4768, 4756, 4892, 4896, 4928, 4940, 4956, 4944, 4952, 4876, 4852, 4988, 5004, 5020, 5032, 4984, 5036, 4884, 4936, 4904, 5048, 5040, 4908, 5052, 4968, 5060, 5080, 5076, 5016, 5012, 4948, 4868, 5088, 5104, 5164, 5136, 5180, 5128, 5208, 5192, 5124, 5236, 5176, 5184, 5140, 5256, 5216, 5252, 5264, 5296, 5316, 5244, 5312, 5328, 5224, 5360, 5380, 5384, 5396, 5300, 5280, 5420, 5436, 5364, 5424, 5456, 5400, 5376, 5288, 5460, 5272, 5408, 5416, 5528, 5544, 5536, 5560, 5332, 5480, 5512, 5572, 5340, 5564, 5472, 5588, 5604, 5524, 5520, 5616, 5448, 5504, 5352, 5624, 5612, 5644, 5468, 5656, 5668, 5688, 5704, 5720, 5728, 5748, 5160, 5660, 5212, 5684, 5628, 5772, 5756, 5784, 5796, 5800, 5820, 5824, 5696, 5840, 5856, 5852, 5872, 5844, 5876, 5888, 5900, 5792, 5652, 5920, 5912, 5892, 5960, 5916, 5836, 5936, 5808, 5776, 5972, 5984, 5992, 6012, 6008, 5944, 6016, 6020, 5968, 6004, 5932, 6060, 6072, 6092, 6104, 6108, 6088, 6124, 6136, 6052, 6112, 6000, 6080, 6096, 6040, 6140, 6036, 6176, 6076, 6184, 6152, 6160, 6204, 6180, 6232, 6188, 6244, 6272, 6256, 6236, 6268, 6276, 6208, 6304, 6248, 6292, 6224, 6344, 6228, 6316, 6324, 6372, 6396, 6412, 6428, 6432, 6420, 6364, 6476, 6404, 6384, 6380, 6296, 6444, 6352, 6368, 6340, 6308, 6468, 6520, 6540, 6528, 6536, 6564, 6524, 6552, 6588, 6580, 6612, 6604, 6644, 6620, 6504, 6624, 6648, 6656, 6600, 6548, 6616, 6636, 6512, 6680, 6440, 6460, 6456, 6716, 6708, 6728, 6748, 6740, 6688, 6724, 6764, 6768, 6772, 6788, 6776, 6704, 6784, 6832, 6800, 6852, 6868, 6860, 6812, 6836, 6820, 6904, 6892, 6916, 6864, 6804, 6816, 6956, 6964, 6948, 6936, 6980, 6928, 7000, 6912, 6924, 7008, 6908, 7004, 6700, 7036, 7052, 7044, 7064, 7048, 7076, 7092, 7116, 7120, 7128, 7108, 7080, 7060, 7164, 7160, 7084, 7096, 7144, 7104, 7212, 7188, 7228, 7240, 7172, 7248, 7256, 7252, 7300, 7236, 7204, 7276, 7316, 7216, 7264, 7320, 7352, 7336, 7360, 7376, 7364, 7380, 7368, 7388, 7192, 7196, 7396, 7400, 7372, 7436, 7448, 7464, 7476, 7488, 7496, 7520, 7424, 7512, 7524, 7540, 7544, 7564, 7384, 7536, 7576, 7588, 7460, 7492, 7528, 7428, 7552, 7628, 7648, 7660, 7572, 7636, 7620, 7656, 7676, 7664, 7712, 7724, 7736, 7732, 7756, 7772, 7784, 7696, 7708, 7716, 7624, 7804, 7604, 7744, 7752, 7816, 7832, 7848, 7860, 7776, 7868, 7864, 7852, 7840, 7892, 7912, 7788, 7928, 7916, 7700, 7616, 7976, 7960, 7964, 7984, 7992, 7940, 7988, 7996, 8024, 8040, 8052, 8016, 8076, 8028, 7932, 8096, 8116, 8132, 8148, 8164, 8176, 8188, 8168, 8160, 7896, 8184, 8048, 8088, 8012, 8104, 8152, 8112, 8072, 8004, 8208, 8224, 8236, 8240, 8256, 8252, 8284, 8300, 8312, 8292, 8328, 8264, 8220, 8320, 8008, 8336, 8332, 8384, 8400, 8416, 8368, 8420, 8460, 8472, 8484, 8480, 8464, 8500, 8380, 8348, 8512, 8504, 8356, 8520, 8536, 8548, 8552, 8568, 8580, 8596, 8600, 8616, 8632, 8608, 8532, 8572, 8652, 8668, 8676, 8688, 8684, 8696, 8712, 8728, 8744, 8764, 8780, 8792, 8788, 8804, 8820, 8752, 8808, 8832, 8844, 8828, 8868, 8876, 8880, 8916, 8928, 8936, 8920, 8736, 8852, 8956, 8960, 8980, 8964, 8988, 8984, 8992, 8932, 8952, 8996, 8924, 9020, 9048, 9060, 8896, 8724, 9008, 9076, 9084, 9104, 9100, 9128, 9140, 9152, 9120, 9136, 9164, 9168, 9176, 9032, 8624, 9040, 9132, 9148, 8680, 9056, 9160, 9208, 8904, 9192, 8840, 8516, 9196, 8588, 8340, 8232, 8940, 8304, 8228, 8200, 9180, 8612, 9000, 9204, 9224, 8476, 9252, 9256, 9276, 9268, 8424, 9272, 9324, 9280, 9312, 9316, 9340, 9288, 9360, 9336, 9348, 9396, 9392, 9384, 9376, 9364, 9352, 9424, 9416, 9452, 9460, 9476, 9468, 9496, 9492, 9448, 9504, 9520, 9528, 9532, 9408, 9548, 9508, 9564, 9596, 9592, 9604, 9624, 9632, 9644, 9652, 9640, 9648, 9664, 9684, 9572, 9412, 9612, 9680, 9696, 9712, 9728, 9700, 9744, 9720, 9724, 9740, 9764, 9772, 9788, 9812, 9792, 9824, 9756, 9820, 9796, 9836, 9852, 9868, 9692, 9860, 9864, 9856, 9880, 9900, 9952, 9916, 9924, 9956, 9892, 9928, 9964, 9896, 9456, 9544, 9472, 9244, 9976, 10024, 10044, 9248, 9540, 10072, 10076, 10060, 10092, 10080, 9944, 10008, 10064, 10056, 10096, 10120, 10136, 9888, 9980, 9988, 10128, 9808, 10172, 10048, 10176, 10204, 10220, 10224, 10052, 9780, 10036, 10160, 10180, 10192, 10256, 10104, 10112, 10284, 10276, 10184, 10316, 10304, 10340, 10300, 10324, 10348, 10356, 10272, 10332, 10280, 10392, 10312, 10292, 10244, 10424, 10420, 10440, 10436, 10452, 10432, 10380, 10364, 10388, 10472, 10492, 10468, 10540, 10516, 10524, 10536, 10556, 10520, 10476, 10496, 10568, 10584, 10564, 10612, 10616, 10604, 10624, 10580, 10664, 10656, 10668, 10672, 10692, 10680, 10644, 10648, 10708, 10756, 10740, 10748, 10752, 10640, 10700, 10772, 10784, 10788, 10792, 10796, 10808, 10836, 10780, 10704, 10736, 10852, 10840, 10860, 10868, 10888, 10800, 10916, 10828, 10932, 10936, 10940, 10900, 10928, 10960, 10824, 10972, 10968, 10976, 10980, 10992, 10948, 11016, 10912, 11024, 11032, 11020, 11040, 11084, 11004, 11012, 11068, 11076, 11056, 11112, 11080, 11128, 11060, 11164, 11176, 11172, 11124, 11116, 11140, 11196, 11216, 11200, 11220, 11236, 11204, 11232, 11240, 11052, 10844, 10504, 10416, 11288, 11180, 11324, 11336, 11300, 11296, 11332, 11312, 11348, 11380, 11392, 11400, 11316, 11376, 11280, 11368, 11372, 11404, 11416, 11292, 11412, 11460, 11476, 11484, 11364, 11472, 11500, 11480, 11516, 11544, 11520, 11508, 11440, 11560, 11504, 11488, 11596, 11576, 11568, 11536, 11604, 11632, 11564, 11640, 11592, 11648, 11644, 11628, 11636, 11652, 11624, 11660, 11720, 11676, 11700, 11748, 11716, 11776, 11796, 11768, 11708, 11712, 11736, 11808, 11816, 11812, 11836, 11848, 11800, 11868, 11804, 11872, 11908, 11924, 11928, 11744, 11860, 11920, 11932, 11784, 11900, 11888, 11912, 11780, 11984, 11884, 11980, 12008, 12016, 12024, 12032, 11832, 12000, 11996, 12060, 12020, 12056, 11956, 12092, 11952, 12004, 12140, 12156, 12104, 12088, 12076, 12068, 12164, 12184, 12212, 12152, 12096, 12228, 12232, 12148, 12192, 12240, 12264, 12276, 11960, 12108, 12284, 12268, 12176, 12084, 12224, 12180, 12272, 12300, 12312, 12340, 12316, 12260, 12356, 12388, 12380, 12332, 12372, 12408, 12412, 12344, 12324, 12432, 12308, 12368, 12484, 12448, 12468, 12472, 12364, 12296, 12508, 12524, 12544, 12556, 12568, 12540, 12512, 12444, 12464, 12600, 12536, 12604, 12596, 12616, 12572, 12440, 12292, 12252, 12636, 12552, 12664, 12652, 12692, 12700, 12684, 12720, 12716, 12740, 12760, 12660, 12680, 12756, 12776, 12416, 12784, 12792, 12748, 12824, 12804, 12832, 12560, 12768, 12800, 12808, 12644, 12856, 12880, 12884, 12668, 12892, 12812, 12904, 12848, 12928, 12936, 12932, 12948, 12960, 12972, 12984, 12992, 13016, 13028, 13012, 12920, 12964, 12988, 13052, 13004, 12772, 13080, 13092, 13112, 13120, 13116, 13136, 13096, 13000, 13100, 13148, 13180, 13160, 13176, 13188, 13184, 13076, 13068, 13232, 13244, 13228, 13256, 13240, 13260, 13276, 13308, 13268, 13084, 12900, 13040, 13288, 13156, 12864, 13200, 13332, 13348, 13340, 13328, 13376, 13384, 13400, 13252, 13420, 13404, 13316, 13432, 13444, 13368, 13472, 13488, 13480, 13320, 13428, 13416, 13396, 13356, 13520, 13540, 13460, 13512, 13560, 13528, 13576, 13360, 13364, 13236, 13588, 13556, 13608, 13612, 13636, 13652, 13656, 13680, 13592, 13436, 13620, 13692, 13616, 13668, 13648, 13732, 13628, 13712, 13760, 13776, 13748, 13804, 13664, 13752, 13728, 13772, 13820, 13844, 13860, 13764, 13876, 13880, 13892, 13908, 13920, 13916, 13848, 13888, 13800, 13924, 13872, 13836, 13832, 13956, 13972, 13984, 13960, 13980, 13992, 13864, 14000, 14012, 14032, 14024, 14028, 14040, 14048, 14044, 13740, 13988, 14092, 14052, 13944, 13828, 13824, 14076, 14068, 14132, 14148, 13964, 14128, 14104, 14168, 14184, 14192, 14200, 14220, 14224, 14256, 14268, 14216, 14260, 14208, 13976, 14204, 14276, 14144, 14272, 14308, 14304, 14320, 14332, 14288, 14296, 14292, 14172, 14360, 14376, 14392, 14316, 14408, 14420, 14448, 14460, 14424, 14472, 14480, 14496, 14380, 14484, 14536, 14500, 14476, 14548, 14556, 14384, 14592, 14608, 14368, 14564, 14612, 14632, 14644, 14656, 14668, 14528, 14588, 14692, 14708, 14724, 14728, 14688, 14756, 14768, 14788, 14804, 14816, 14824, 14840, 14852, 14848, 14676, 14828, 14836, 14860, 14572, 14876, 14888, 14884, 14900, 14872, 14340, 14772, 14740, 14880, 14936, 14944, 14924, 14672, 14928, 14892, 14620, 14940, 14512, 14732, 14776, 14660, 14664, 14964, 14600, 14760, 15000, 15004, 14952, 14444, 15016, 15036, 15052, 15072, 15088, 15092, 15096, 15080, 15100, 14440, 15112, 15116, 15140, 15148, 14984, 15160, 15164, 15172, 15084, 14560, 15196, 15204, 15108, 15212, 15232, 15256, 15220, 15216, 15152, 15264, 15252, 15280, 15292, 15284, 15168, 15312, 15328, 15344, 15356, 15288, 15332, 15240, 15068, 15060, 14628, 15272, 15316, 15348, 15372, 15388, 15396, 15400, 15408, 15404, 15420, 15392, 15308, 15424, 15440, 15432, 15468, 15380, 15368, 15452, 15496, 15492, 15512, 15500, 15476, 15548, 15564, 15508, 15484, 15528, 15540, 15572, 15568, 15588, 15600, 15596, 15624, 15612, 15608, 15620, 15656, 15660, 15676, 15696, 15732, 15744, 15748, 15700, 15628, 15752, 15756, 15740, 15704, 15716, 15784, 15808, 15680, 15672, 15776, 15728, 15820, 15812, 15816, 15852, 15804, 15864, 15880, 15764, 15800, 15896, 15868, 15908, 15856, 15888, 15936, 15964, 15976, 15960, 15924, 15968, 15980, 15932, 15996, 15988, 15832, 15972, 15904, 16044, 15928, 16020, 16028, 16040, 16084, 15984, 16116, 16096, 16080, 16152, 16164, 16092, 16072, 16184, 16192, 16156, 16104, 16128, 16168, 16140, 16212, 16088, 16176, 16064, 16232, 16112, 16252, 16264, 16236, 16292, 16256, 16284, 764, 16324, 16272, 16240, 16308, 16316, 16200, 16336, 16348, 16372, 16376, 16228, 16344, 16220, 16404, 16408, 16420, 16360, 16432, 16448, 16440, 16452, 16444, 16480, 16508, 16504, 16488, 16500, 16460, 16536, 16312, 16524, 16548, 16556, 16520, 16584, 16592, 16632, 16628, 16640, 16572, 16468, 16552, 16648, 16604, 16568, 16424, 16676, 16684, 16636, 16680, 16588, 16616, 16728, 16476, 16740, 16768, 16784, 16752, 16736, 16760, 16832, 16840, 16848, 16856, 16800, 16852, 16864, 16892, 16904, 16716, 16672, 16916, 16824, 16924, 16704, 16948, 16796, 16956, 16952, 16936, 16808, 16988, 16880, 16820, 16772, 16996, 16744, 16932, 17000, 17008, 17020, 16724, 16608, 16984, 17052, 17040, 16776, 17068, 17060, 17072, 17056, 17100, 17136, 17148, 17120, 17116, 17092, 17172, 17164, 17188, 17084, 17024, 17208, 17088, 740], #0: [], #2049: {8200, 8208, 16404, 16408, 8220, 8224, 8228, 16420, 8232, 16424, 8236, 8240, 16432, 16440, 8252, 16444, 8256, 16448, 16452, 8264, 16460, 16468, 8284, 16476, 16480, 8292, 16488, 8300, 8304, 16500, 8312, 16504, 16508, 8320, 8328, 16520, 8332, 16524, 8336, 8340, 16536, 8348, 8356, 16548, 16552, 16556, 8368, 16568, 8380, 16572, 8384, 16584, 16588, 8400, 16592, 16604, 8416, 16608, 8420, 8424, 16616, 16628, 16632, 16636, 16640, 16648, 8460, 8464, 8472, 8476, 8480, 16672, 8484, 16676, 16680, 16684, 8500, 8504, 8512, 16704, 8516, 8520, 16716, 8532, 16724, 8536, 16728, 16736, 8548, 16740, 8552, 16744, 16752, 8568, 16760, 8572, 16768, 8580, 16772, 16776, 8588, 16784, 8596, 8600, 16796, 8608, 16800, 8612, 8616, 16808, 8624, 436, 16820, 8632, 16824, 16832, 16840, 8652, 16848, 16852, 16376, 16856, 8668, 16864, 8676, 8680, 8684, 8688, 16880, 8696, 16892, 8712, 16904, 8724, 16916, 536, 8728, 16924, 8736, 16932, 8744, 16936, 8752, 16948, 16952, 8764, 16956, 8780, 8788, 8792, 16984, 16988, 8804, 16996, 8808, 17000, 17008, 8820, 632, 8828, 17020, 8832, 17024, 8840, 8844, 17040, 8852, 17052, 17056, 8868, 17060, 8876, 17068, 8880, 17072, 17084, 8896, 17088, 17092, 712, 8904, 17100, 724, 8916, 8920, 8924, 17116, 8928, 17120, 8932, 740, 8936, 8940, 752, 17136, 8952, 8956, 764, 17148, 8960, 8964, 17164, 8980, 17172, 17176, 8984, 796, 8988, 8992, 804, 8996, 17188, 808, 9000, 812, 816, 9008, 820, 824, 17208, 828, 9020, 9032, 844, 9040, 9048, 864, 9056, 868, 9060, 872, 9076, 888, 892, 9084, 896, 9100, 912, 9104, 916, 920, 928, 9120, 932, 936, 9128, 9132, 9136, 948, 9140, 952, 956, 9148, 960, 9152, 968, 9160, 9164, 976, 9168, 984, 9176, 9180, 996, 9192, 1004, 9196, 1008, 1012, 9204, 9208, 1020, 9224, 1036, 1044, 1048, 9244, 9248, 1060, 9252, 9256, 1068, 1072, 9268, 9272, 1084, 9276, 9280, 1096, 9288, 1104, 1112, 1116, 9312, 1124, 9316, 1128, 9324, 1136, 9336, 9340, 1152, 1156, 9348, 9352, 9360, 1172, 9364, 1180, 9376, 1188, 1192, 9384, 9392, 1204, 9396, 1208, 1212, 1216, 9408, 9412, 1220, 1224, 9416, 1228, 1232, 9424, 1236, 1256, 9448, 9452, 1264, 9456, 9460, 9468, 1280, 9472, 1284, 9476, 1288, 1292, 9492, 1304, 9496, 1308, 9504, 9508, 1320, 1324, 1328, 9520, 9528, 9532, 1344, 1348, 9540, 9544, 1356, 9548, 1364, 1372, 9564, 9572, 1388, 1392, 1396, 9592, 9596, 1408, 1412, 9604, 1416, 1420, 9612, 1424, 1428, 9624, 9632, 9640, 1452, 9644, 9648, 1460, 9652, 1468, 1472, 9664, 1476, 1480, 1488, 9680, 9684, 9692, 1504, 9696, 9700, 1512, 1516, 1520, 9712, 1524, 9720, 1532, 9724, 1536, 9728, 9740, 9744, 1556, 9756, 1568, 9764, 1576, 9772, 1584, 9780, 9788, 1600, 9792, 1604, 9796, 1608, 1612, 9808, 1620, 9812, 1624, 1628, 9820, 9824, 1636, 1640, 9836, 1648, 9852, 9856, 9860, 1672, 9864, 1676, 9868, 1688, 9880, 1696, 9888, 1700, 9892, 1704, 9896, 9900, 1712, 1716, 9916, 9924, 1736, 9928, 1744, 9944, 1756, 1760, 9952, 1764, 9956, 1768, 1772, 9964, 9976, 9980, 9988, 1800, 1804, 10008, 1820, 1824, 1832, 10024, 1844, 10036, 1848, 1852, 10044, 1856, 10048, 10052, 10056, 1868, 10060, 10064, 10072, 1884, 10076, 10080, 1892, 1900, 10092, 10096, 10104, 1916, 1920, 10112, 10120, 10128, 1940, 1944, 10136, 1948, 10160, 1980, 10172, 10176, 1988, 10180, 1992, 10184, 2000, 10192, 2004, 2008, 2012, 10204, 2016, 2028, 10220, 10224, 2036, 2040, 2044, 10244, 2056, 2060, 10256, 2076, 10272, 2084, 10276, 10280, 2092, 10284, 10292, 2108, 10300, 2112, 10304, 2116, 10312, 10316, 2128, 10324, 2140, 10332, 2144, 2148, 10340, 2152, 2156, 10348, 2160, 2164, 10356, 10364, 2180, 10380, 2192, 10388, 2200, 10392, 2204, 2212, 2216, 2220, 10416, 10420, 10424, 2236, 2240, 10432, 10436, 10440, 10452, 2268, 2272, 10468, 10472, 10476, 2288, 2292, 2296, 10492, 10496, 10504, 2324, 10516, 2328, 10520, 10524, 10536, 2348, 10540, 2352, 2356, 2360, 10556, 2372, 10564, 2376, 10568, 2380, 2384, 2388, 10580, 10584, 2396, 2400, 2408, 2412, 10604, 2416, 10612, 10616, 10624, 2444, 2448, 10640, 2452, 10644, 2456, 10648, 10656, 2472, 10664, 10668, 10672, 2484, 10680, 2496, 2500, 10692, 2504, 2508, 10700, 2512, 10704, 2516, 10708, 2524, 2532, 2536, 2544, 10736, 10740, 10748, 2560, 10752, 2564, 10756, 2568, 2572, 2576, 10772, 2584, 10780, 10784, 10788, 2600, 10792, 10796, 2608, 10800, 2612, 10808, 2620, 2624, 2632, 10824, 10828, 10836, 10840, 10844, 2656, 2660, 10852, 10860, 2672, 2676, 10868, 2680, 2684, 2696, 10888, 2700, 2704, 2708, 10900, 2712, 2716, 10912, 2724, 10916, 2728, 10928, 2740, 10932, 10936, 10940, 10948, 2760, 2768, 10960, 2776, 10968, 10972, 2784, 10976, 10980, 2800, 10992, 2804, 11004, 2820, 11012, 11016, 11020, 2832, 11024, 2836, 11032, 2848, 11040, 2852, 2860, 11052, 11056, 11060, 2872, 11068, 2880, 2884, 11076, 2888, 11080, 2892, 11084, 2908, 2920, 11112, 11116, 2928, 2932, 11124, 2936, 11128, 2940, 2944, 11140, 2952, 2960, 2968, 11164, 11172, 11176, 2988, 11180, 2996, 3004, 11196, 11200, 3012, 11204, 11216, 11220, 11232, 11236, 11240, 3056, 3088, 11280, 3092, 11288, 3100, 11292, 3104, 11296, 3108, 11300, 3116, 11312, 3124, 11316, 3128, 3132, 11324, 11332, 11336, 3148, 3156, 11348, 3160, 3168, 11364, 11368, 3180, 11372, 11376, 11380, 3192, 11392, 3204, 3208, 11400, 3212, 11404, 3220, 11412, 3224, 11416, 3232, 3236, 3244, 11440, 3256, 3260, 3264, 11460, 3272, 3276, 11472, 3284, 11476, 11480, 3292, 11484, 11488, 3308, 11500, 11504, 3316, 11508, 3320, 11516, 11520, 3332, 3340, 11536, 3348, 3352, 11544, 3356, 3364, 3368, 11560, 11564, 3376, 11568, 11576, 3388, 3400, 11592, 3404, 11596, 11604, 3416, 3424, 11624, 11628, 3440, 11632, 11636, 3448, 11640, 11644, 11648, 11652, 3468, 11660, 3476, 11676, 3492, 3496, 3500, 3504, 3508, 11700, 11708, 3520, 11712, 11716, 3528, 11720, 3540, 11736, 3548, 11744, 3556, 11748, 3564, 3572, 3576, 11768, 3580, 11776, 11780, 11784, 3596, 11796, 11800, 3612, 11804, 3616, 11808, 11812, 11816, 3632, 3640, 11832, 3644, 11836, 3648, 11848, 3660, 3664, 3668, 11860, 3676, 11868, 3680, 11872, 3692, 11884, 11888, 3700, 3708, 11900, 3712, 11908, 3720, 11912, 3728, 11920, 3732, 11924, 3736, 11928, 3740, 11932, 3748, 3756, 11952, 11956, 3768, 11960, 3776, 3784, 11980, 3792, 11984, 3796, 3800, 3804, 11996, 3808, 12000, 3812, 12004, 3816, 12008, 12016, 3828, 12020, 3832, 12024, 12032, 3844, 3852, 12056, 12060, 3872, 3876, 12068, 3880, 12076, 12084, 3896, 12088, 12092, 12096, 12104, 12108, 3924, 3928, 3940, 3948, 12140, 12148, 3960, 12152, 3964, 12156, 3972, 12164, 3984, 12176, 3988, 12180, 3992, 12184, 3996, 12192, 4004, 4008, 4016, 4020, 12212, 4024, 4028, 12224, 12228, 4040, 12232, 4048, 12240, 4052, 4060, 12252, 12260, 4072, 12264, 4076, 12268, 12272, 4084, 12276, 4092, 12284, 4100, 12292, 12296, 12300, 4112, 4116, 12308, 12312, 12316, 4128, 4132, 12324, 4136, 12332, 4144, 12340, 4152, 12344, 4156, 4164, 12356, 4168, 12364, 12368, 4180, 12372, 12380, 4192, 12388, 4200, 4204, 12408, 12412, 12416, 4228, 4232, 4240, 12432, 4248, 12440, 12444, 4256, 12448, 4260, 4272, 12464, 4276, 12468, 4280, 12472, 4284, 4288, 4292, 12484, 4304, 4316, 12508, 12512, 4324, 12524, 4340, 4344, 12536, 4348, 12540, 12544, 4356, 12552, 12556, 4368, 12560, 12568, 4380, 12572, 4392, 4396, 4404, 12596, 4408, 12600, 4412, 12604, 12616, 4428, 4436, 12636, 12644, 4456, 12652, 12660, 4472, 12664, 4476, 12668, 4480, 4484, 4488, 12680, 4492, 12684, 12692, 4508, 12700, 4512, 4516, 4520, 12716, 12720, 4536, 4544, 12740, 12748, 4560, 4564, 12756, 12760, 4576, 12768, 12772, 4584, 12776, 4588, 4592, 12784, 4596, 4600, 12792, 4604, 4608, 12800, 12804, 12808, 12812, 4628, 4632, 12824, 4636, 12832, 4648, 12848, 4660, 12856, 4672, 12864, 4676, 4680, 4688, 12880, 12884, 4700, 12892, 4704, 12900, 12904, 4716, 12920, 12928, 4740, 12932, 12936, 4748, 4752, 4756, 12948, 4764, 4768, 12960, 12964, 4776, 12972, 4784, 4792, 12984, 12988, 12992, 13000, 4812, 13004, 4816, 13012, 4824, 13016, 4828, 13028, 4840, 13040, 4852, 4856, 13052, 4868, 4876, 13068, 4884, 13076, 13080, 4892, 13084, 4896, 13092, 4904, 13096, 4908, 13100, 13112, 13116, 4928, 13120, 4936, 4940, 4944, 13136, 4948, 4952, 4956, 13148, 13156, 4968, 13160, 4984, 13176, 4988, 13180, 13184, 13188, 5004, 13200, 5012, 5016, 5020, 5032, 5036, 13228, 5040, 13232, 13236, 5048, 13240, 5052, 13244, 5060, 13252, 13256, 13260, 5076, 13268, 5080, 13276, 5088, 13288, 5104, 13308, 5124, 13316, 5128, 13320, 5136, 13328, 5140, 13332, 13340, 13348, 5160, 5164, 13356, 13360, 13364, 5176, 13368, 5180, 5184, 13376, 5192, 13384, 13396, 5208, 13400, 5212, 13404, 5216, 5224, 13416, 13420, 5236, 13428, 13432, 5244, 13436, 5252, 13444, 5256, 5264, 13460, 5272, 5280, 13472, 5288, 13480, 5296, 13488, 5300, 5312, 5316, 13512, 5328, 13520, 5332, 13528, 5340, 13540, 5352, 5360, 5364, 13556, 13560, 5376, 5380, 5384, 13576, 5396, 13588, 5400, 13592, 5408, 5416, 13608, 5420, 13612, 5424, 13616, 13620, 5436, 13628, 13636, 5448, 5456, 13648, 5460, 13652, 13656, 5468, 5472, 13664, 13668, 5480, 13680, 13692, 5504, 5512, 5520, 13712, 5524, 5528, 5536, 13728, 13732, 5544, 13740, 13748, 5560, 13752, 5564, 13760, 5572, 13764, 13772, 13776, 5588, 5604, 13800, 5612, 13804, 5616, 5624, 5628, 13820, 13824, 13828, 13832, 5644, 13836, 5652, 13844, 5656, 13848, 5660, 5668, 13860, 13864, 13872, 5684, 13876, 5688, 13880, 5696, 13888, 13892, 5704, 13908, 5720, 13916, 5728, 13920, 13924, 5748, 13944, 5756, 13956, 13960, 5772, 13964, 5776, 13972, 5784, 13976, 13980, 5792, 13984, 5796, 13988, 5800, 13992, 5808, 14000, 5820, 14012, 5824, 14024, 5836, 14028, 5840, 14032, 5844, 14040, 5852, 14044, 5856, 14048, 14052, 5872, 5876, 14068, 14076, 5888, 5892, 5900, 14092, 5912, 14104, 5916, 5920, 5932, 5936, 14128, 14132, 5944, 14144, 14148, 5960, 5968, 5972, 14168, 14172, 5984, 5992, 14184, 6000, 14192, 6004, 6008, 14200, 6012, 14204, 6016, 14208, 6020, 14216, 14220, 14224, 6036, 6040, 6052, 6060, 14256, 14260, 6072, 6076, 14268, 6080, 14272, 14276, 6088, 6092, 6096, 14288, 14292, 6104, 14296, 6108, 6112, 14304, 14308, 6124, 14316, 14320, 6136, 6140, 14332, 14340, 6152, 6160, 14360, 6176, 14368, 6180, 6184, 14376, 6188, 14380, 14384, 14392, 6204, 6208, 14408, 6224, 6228, 14420, 6232, 14424, 6236, 6244, 6248, 14440, 14444, 6256, 14448, 6268, 14460, 6272, 6276, 14472, 14476, 14480, 6292, 14484, 6296, 6304, 14496, 6308, 14500, 6316, 14512, 6324, 14528, 6340, 6344, 14536, 6352, 14548, 6364, 14556, 6368, 14560, 6372, 14564, 6380, 14572, 6384, 6396, 14588, 14592, 6404, 14600, 6412, 14608, 6420, 14612, 6428, 14620, 6432, 14628, 6440, 14632, 6444, 14644, 6456, 6460, 14656, 6468, 14660, 14664, 6476, 14668, 14672, 14676, 14688, 14692, 6504, 6512, 14708, 6520, 6524, 6528, 14724, 6536, 14728, 6540, 14732, 6548, 14740, 6552, 6564, 14756, 14760, 14768, 6580, 14772, 14776, 6588, 14788, 6600, 6604, 6612, 14804, 6616, 6620, 6624, 14816, 14824, 6636, 14828, 6644, 14836, 6648, 14840, 6656, 14848, 14852, 14860, 6680, 14872, 14876, 6688, 14880, 14884, 14888, 6700, 14892, 6704, 6708, 14900, 6716, 6724, 6728, 14924, 14928, 6740, 14936, 6748, 14940, 14944, 14952, 6764, 6768, 6772, 14964, 6776, 6784, 6788, 14984, 6800, 6804, 15000, 6812, 15004, 6816, 6820, 15016, 6832, 6836, 15036, 6852, 6860, 15052, 6864, 6868, 15060, 15068, 15072, 15080, 6892, 15084, 15088, 15092, 6904, 15096, 6908, 15100, 6912, 6916, 15108, 15112, 6924, 15116, 6928, 6936, 6948, 15140, 6956, 15148, 15152, 6964, 15160, 15164, 15168, 6980, 15172, 7000, 7004, 15196, 7008, 15204, 15212, 15216, 15220, 7036, 15232, 7044, 7048, 15240, 7052, 7060, 15252, 7064, 15256, 15264, 7076, 7080, 15272, 7084, 15280, 7092, 15284, 7096, 15288, 15292, 7104, 7108, 7116, 15308, 7120, 15312, 15316, 7128, 15328, 15332, 7144, 15344, 15348, 7160, 7164, 15356, 7172, 15368, 15372, 7188, 15380, 7192, 7196, 15388, 15392, 7204, 15396, 15400, 7212, 15404, 7216, 15408, 7228, 15420, 15424, 7236, 7240, 15432, 7248, 15440, 7252, 7256, 15452, 7264, 7276, 15468, 15476, 15484, 7300, 15492, 15496, 15500, 7316, 15508, 7320, 15512, 7336, 15528, 15540, 7352, 15548, 7360, 7364, 7368, 7372, 15564, 7376, 15568, 7380, 15572, 7384, 7388, 7396, 15588, 7400, 15596, 15600, 15608, 15612, 7424, 7428, 15620, 15624, 7436, 15628, 7448, 7460, 7464, 15656, 15660, 7476, 15672, 15676, 7488, 15680, 7492, 7496, 15696, 15700, 7512, 15704, 7520, 7524, 15716, 7528, 7536, 15728, 7540, 15732, 7544, 15740, 7552, 15744, 15748, 15752, 7564, 15756, 7572, 15764, 7576, 15776, 7588, 15784, 7604, 15800, 15804, 7616, 15808, 7620, 15812, 7624, 15816, 7628, 15820, 7636, 15832, 7648, 7656, 7660, 15852, 7664, 15856, 15864, 7676, 15868, 15880, 7696, 15888, 7700, 15896, 7708, 7712, 15904, 7716, 15908, 7724, 7732, 15924, 7736, 15928, 15932, 7744, 15936, 7752, 7756, 15960, 7772, 15964, 7776, 15968, 15972, 7784, 15976, 7788, 15980, 15984, 15988, 7804, 15996, 7816, 16020, 7832, 16028, 7840, 7848, 16040, 7852, 16044, 7860, 7864, 7868, 16064, 16072, 16080, 7892, 16084, 7896, 16088, 16092, 16096, 7912, 16104, 7916, 16112, 16116, 7928, 7932, 16128, 7940, 16140, 7960, 16152, 7964, 16156, 16164, 7976, 16168, 7984, 16176, 7988, 7992, 16184, 7996, 16192, 8004, 8008, 16200, 8012, 8016, 16212, 8024, 8028, 16220, 16228, 8040, 16232, 16236, 8048, 16240, 8052, 16252, 16256, 8072, 16264, 8076, 16272, 8088, 16284, 8096, 16292, 8104, 8112, 8116, 16308, 16312, 16316, 8132, 16324, 16336, 8148, 8152, 16344, 16348, 8160, 8164, 8168, 16360, 8176, 16372, 8184, 8188}, 79.520764) 2020-02-17 15:47:31.336759 p8380 ERR ActorAdmin uncaught exception: Traceback (most recent call last): File "C:\Users\dvyd.conda\envs\activefiction\lib\site-packages\thespian\system\admin\convention.py", line 644, in run delay.remaining()) File "C:\Users\dvyd.conda\envs\activefiction\lib\site-packages\thespian\system\transport\wakeupTransportBase.py", line 71, in run rval = self._run_subtransport(incomingHandler, max_runtime) File "C:\Users\dvyd.conda\envs\activefiction\lib\site-packages\thespian\system\transport\wakeupTransportBase.py", line 80, in _run_subtransport rval = self._runWithExpiry(incomingHandler) File "C:\Users\dvyd.conda\envs\activefiction\lib\site-packages\thespian\system\transport\TCPTransport.py", line 1141, in _runWithExpiry set(wsend+wrecv), delay) ValueError: too many file descriptors in select()

On Mon, Feb 17, 2020 at 9:26 PM Kevin Quick notifications@github.com wrote:

Let me address your two concerns individually: memory utilization and timeouts.

-

For memory utilization, I'm afraid this may be unavoidable. The minimum overhead for a Python application seems to be about 20-30KB (at least under Linux), which seems to be related to the core interpreter, shared libraries, and the various python objects that are being maintained by the GC in the cloned processes. I did some work a couple of years ago to try to minimize this footprint but I was unable to reduce it beyond this size threshold.

One of the constraints here is that Thespian is implementing each Actor as a separate system process. This ensures separation between Actors, but it's also a heavy-weight isolation mechanism. I had considered an alternative base implementation allowing each Actor to be a separate thread instead of a separate process as a smaller footprint, but I ran into some significant concerns relative to the GIL, where any Actor would then have the ability to stop all of the Actors. I think that a thread-based implementation would be possible, with some caveats and restrictions, but it's difficult to achieve Erlang-style scalability for Actors without support for this at the VM level.

The various approaches I could suggest at this point are:

1 - use multiple systems with a convention to spread Actors across different system 2 - change the level of granularity for Actors: combine functionality to have fewer Actors capable of doing more things. I know this is counter to the general advice with Actors, but it's one way to mitigate your scalability issue. 3 - you could try multi-threading your actors. Thespian should support Actors which have multiple threads: the receiveMessage() will only be activate on the "primary" thread although other threads are allowed to call self.send(). Any other synchronization is up to you. Again, I hesitate to suggest this because it adds considerable complication and the normal advice is to stick to a single concurrency architecture, but again, it's a practical approach to dealing with your underlying constraints.

With regards to the timeouts, this may be somewhat related to the scaling issue, but it's also a bit unexpected. I've used Thespian in systems with > 1000 actors successfully. It would be good to know if the timeouts only start occurring when you reach a certain threshold number of Actors or corresponding activity to know if this is a threshold issue or a consistent gradual issue.

There is some internal logging Thespian generates that may be of some help to diagnose what is happening here. By default, it will write to $TMPDIR/thespian.log, although you can control this with the THESPLOG_FILE environment variable (ensure this is set in the process that starts the Admin to be properly applied). You can also use the THESPLOG_FILE_MAXSIZE environment variable to specify how large this file is allowed to grow (the value is the number of bytes and the default is 51200), and the THESPLOG_THRESHOLD to set the logging threshold (the default is "WARNING" and valid values are "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"). I'm happy to take a look at output from this log (either here or in a gist) to see if anything looks out of place.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kquick/Thespian/issues/57?email_source=notifications&email_token=AANTN7PZX53T5OYY54DERILRDLQHRA5CNFSM4KWSYJR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL7OG2Y#issuecomment-587129707, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANTN7L32K3LZ25BMENLYXTRDLQHRANCNFSM4KWSYJRQ .

kquick commented 4 years ago

That's OK, the last line is the important one: ValueError: too many file descriptors in select(). This is probably an OS limit that is being hit. I don't know if Windows provides a way to adjust this limit or not, but if you are close to the maximum number of Actors you need, this could be a viable solution. However, if you are wanting to scale significantly beyond 2000 actors, then this might start to encounter secondary effects.

Another option is to tell Thespian not to keep the sockets open; keeping the socket open is an efficiency measure to avoid TCP connection times, but Thespian will reconnect as needed. Unfortunately, there's no environmental control for this at the moment, so you'll need to edit your local version of Thespian and change REUSE_SOCKETS to False here: https://github.com/kquick/Thespian/blob/master/thespian/system/transport/TCPTransport.py#L127. If this helps and solves this problem for you, I could add an environment variable or other way to control this setting. Alternatively, I could look into establishing an upper threshold on the number of open sockets that would automatically close sockets as needed to avoid crossing that threshold; I'd like to get more data on your experiences though before undertaking any adjustments.

With respect to memory utilization, you are correct: there's a magnitude difference between the minimum I'm aware of and what you are seeing. One thought is that my observed minimum is under Linux and I'm less familiar with the situation on Windows. It might be interesting to see what the difference is between starting 2000 actors with no traffic v.s. that number after they start exchanging traffic in your application. If it's the latter, then in may be that since there's memory available in the system, there's less pressure on each Actor process's memory to cause python GC. I don't want to leap to any conclusions though, so if you have a chance to observe the footprint of 2000 idle actors to compare to your current situation it would be interesting to compare those.

davideps commented 4 years ago

Thanks Kevin, I'll look into both memory and connection issues later this week. Is there any benefit to experimenting with the different Thespian actor systems that don't use TCP?

On Mon, Feb 17, 2020 at 10:54 PM Kevin Quick notifications@github.com wrote:

That's OK, the last line is the important one: ValueError: too many file descriptors in select(). This is probably an OS limit that is being hit. I don't know if Windows provides a way to adjust this limit or not, but if you are close to the maximum number of Actors you need, this could be a viable solution. However, if you are wanting to scale significantly beyond 2000 actors, then this might start to encounter secondary effects.

Another option is to tell Thespian not to keep the sockets open; keeping the socket open is an efficiency measure to avoid TCP connection times, but Thespian will reconnect as needed. Unfortunately, there's no environmental control for this at the moment, so you'll need to edit your local version of Thespian and change REUSE_SOCKETS to False here: https://github.com/kquick/Thespian/blob/master/thespian/system/transport/TCPTransport.py#L127. If this helps and solves this problem for you, I could add an environment variable or other way to control this setting. Alternatively, I could look into establishing an upper threshold on the number of open sockets that would automatically close sockets as needed to avoid crossing that threshold; I'd like to get more data on your experiences though before undertaking any adjustments.

With respect to memory utilization, you are correct: there's a magnitude difference between the minimum I'm aware of and what you are seeing. One thought is that my observed minimum is under Linux and I'm less familiar with the situation on Windows. It might be interesting to see what the difference is between starting 2000 actors with no traffic v.s. that number after they start exchanging traffic in your application. If it's the latter, then in may be that since there's memory available in the system, there's less pressure on each Actor process's memory to cause python GC. I don't want to leap to any conclusions though, so if you have a chance to observe the footprint of 2000 idle actors to compare to your current situation it would be interesting to compare those.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kquick/Thespian/issues/57?email_source=notifications&email_token=AANTN7KMHQWL6K5W3FFG3IDRDL2RTA5CNFSM4KWSYJR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL7UH7I#issuecomment-587154429, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANTN7PV7WONVLQK62GCADLRDL2RTANCNFSM4KWSYJRQ .

kquick commented 4 years ago

It depends on your usage.

I would recommend against using the UDP base because UDP messages do not guarantee delivery; this base is interesting, especially for experimentation with lossy delivery, but should probably not be used for reliable/production use.

The multiprocQueueBase uses Python's Queue facility for communications between Actors. A Queue cannot be arbitrarily attached to processes, but is instead a point-to-point between a parent and child, so Thespian's message delivery in a Queue transport involves passing the message up the parent chain of actors (internally... the Actor code itself is not involved) to a common ancestor of both the sender and the receiver, and then back down the chain of children on the receiver's side to the destination. The benefit to you of this base is that none of them will exceed the file descriptor limit for the select() call unless you have an exceptionally flat Actor tree where all 2000 Actors are children of a single parent. The disadvantage is the performance impact of passing each message across multiple Actors to the intended destination. That said, all of this complexity is hidden, so all you would need to do is change the name of the base you are using to experiment and see if the multiprocQueueBase works better for your needs. [One additional note: in my testing I've seen occasional failures that seem to originate in the internals of the Queue implementation, but I haven't had the time to fully track them down.]

The simpleSystemBase has no processes or sockets, but the performance will be even less than the multiprocQueueBase because all the Actors live in the current process and participate in a cooperative scheduling technique to run serially. Additionally, since all the Actors share the same process, it's easier to accidentally violate the Actor protections by having Actors share structures in memory, so your development requires more discipline to avoid this. Again however, you can simply try this base to see if it helps or hurts your situation by changing the name of the base started, with no other changes to your code.

davideps commented 4 years ago

Kevin, is the file descriptor limit the same thing as the open file limit discussed/solved here: https://coderwall.com/p/ptq7rw/increase-open-files-limit-and-drop-privileges-in-python ?

If I change REUSE_SOCKETS to False , then the actorsystem will need to create a connection, send a message, and then close the connection for every communication? If the time spent on this extra overhead is much less than the time saved by accessing multiple processors, it is a net gain. Do you have any idea how much time it takes to open and close the connections?

Can the multiprocQueueBase be used in a cluster scenario or only the TCP base ? Since creating thousands of actors is slow on a single processor, I was planning to create a number of "generator" actors equal to the number of cores in my laptop. Their sole purpose is to create worker actors and send the new addresses to the schedule actor. I suppose this would make the generator actors the workers' parents and reduce the flatness of my simulation. Perhaps making multiprocQueueBase more viable.

Thanks for all your guidance on this.

On Tue, Feb 18, 2020 at 12:32 AM Kevin Quick notifications@github.com wrote:

It depends on your usage.

I would recommend against using the UDP base because UDP messages do not guarantee delivery; this base is interesting, especially for experimentation with lossy delivery, but should probably not be used for reliable/production use.

The multiprocQueueBase uses Python's Queue facility for communications between Actors. A Queue cannot be arbitrarily attached to processes, but is instead a point-to-point between a parent and child, so Thespian's message delivery in a Queue transport involves passing the message up the parent chain of actors (internally... the Actor code itself is not involved) to a common ancestor of both the sender and the receiver, and then back down the chain of children on the receiver's side to the destination. The benefit to you of this base is that none of them will exceed the file descriptor limit for the select() call unless you have an exceptionally flat Actor tree where all 2000 Actors are children of a single parent. The disadvantage is the performance impact of passing each message across multiple Actors to the intended destination. That said, all of this complexity is hidden, so all you would need to do is change the name of the base you are using to experiment and see if the multiprocQueueBase works better for your needs. [One additional note: in my testing I've seen occasional failures that seem to originate in the internals of the Queue implementation, but I haven't had the time to fully track them down.]

The simpleSystemBase has no processes or sockets, but the performance will be even less than the multiprocQueueBase because all the Actors live in the current process and participate in a cooperative scheduling technique to run serially. Additionally, since all the Actors share the same process, it's easier to accidentally violate the Actor protections by having Actors share structures in memory, so your development requires more discipline to avoid this. Again however, you can simply try this base to see if it helps or hurts your situation by changing the name of the base started, with no other changes to your code.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kquick/Thespian/issues/57?email_source=notifications&email_token=AANTN7PFAUVU2P7KKZGFMPTRDMF7HA5CNFSM4KWSYJR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL72ISY#issuecomment-587179083, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANTN7JMTT2KOGGWMEULASTRDMF7HANCNFSM4KWSYJRQ .

davideps commented 4 years ago

When I set REUSE_SOCKETS = False, I get the following trace:

C:\Users\dvyd.conda\envs\activefiction\python.exe D:/Documents/Programming/ActiveFiction/python_code/thespian_test_01.py Starting actor system Exception ignored in: <function TCPIncoming.del at 0x000001B93F6D25E8> Traceback (most recent call last): File "C:\Users\dvyd.conda\envs\activefiction\lib\site-packages\thespian\system\transport\TCPTransport.py", line 197, in del _safeSocketShutdown(s.socket) NameError: name 's' is not defined Exception ignored in: <function TCPIncoming.del at 0x0000024955672D38> Traceback (most recent call last): File "C:\Users\dvyd.conda\envs\activefiction\lib\site-packages\thespian\system\transport\TCPTransport.py", line 197, in del _safeSocketShutdown(s.socket) NameError: name 's' is not defined Exception ignored in: <function TCPIncoming.del at 0x000001B93F6D25E8> Traceback (most recent call last): File "C:\Users\dvyd.conda\envs\activefiction\lib\site-packages\thespian\system\transport\TCPTransport.py", line 197, in del _safeSocketShutdown(s.socket) NameError: name 's' is not defined Exception ignored in: <function TCPIncoming.del at 0x0000024955672D38> Traceback (most recent call last): File "C:\Users\dvyd.conda\envs\activefiction\lib\site-packages\thespian\system\transport\TCPTransport.py", line 197, in del _safeSocketShutdown(s.socket) NameError: name 's' is not defined Exception ignored in: <function TCPIncoming.del at 0x000001B93F6D25E8> Traceback (most recent call last): File "C:\Users\dvyd.conda\envs\activefiction\lib\site-packages\thespian\system\transport\TCPTransport.py", line 197, in del _safeSocketShutdown(s.socket) NameError: name 's' is not defined Traceback (most recent call last): File "D:/Documents/Programming/ActiveFiction/python_code/thespian_test_01.py", line 399, in agent_scheduler = asys.createActor(AgentScheduler) File "C:\Users\dvyd.conda\envs\activefiction\lib\site-packages\thespian\actors.py", line 705, in createActor sourceHash) File "C:\Users\dvyd.conda\envs\activefiction\lib\site-packages\thespian\system\systemBase.py", line 196, in newPrimaryActor response.failure_message) thespian.actors.InvalidActorSpecification: Invalid Actor Specification: <class 'main.AgentScheduler'> ('TCPTransport' object has no attribute '_openSockets') Creating agent_scheduler

Process finished with exit code 1

kquick commented 4 years ago

is the file descriptor limit the same thing as the open file limit discussed/solved here: https://coderwall.com/p/ptq7rw/increase-open-files-limit-and-drop-privileges-in-python ?

Yes, although that link is related although it's POSIX specific. The python calls used there have command-line equivalents in a POSIX system as well (e.g. Linux). For Windows, it's probably something along the lines of what's indicated here: https://serverfault.com/questions/249477/windows-server-2008-r2-max-open-files-limit

Do you have any idea how much time it takes to open and close the connections?

That will vary a lot based on the OS and other factors like how many messages you expect to exchange. If your program execution will be dominated by delivery of messages between actors, then this may be visible to you, but if your program execution is dominated by computation within the actors then it may not be a big deal. TCP socket re-use is a common technique for improving high-load performance of network-based operations and the technique has been highlighted in scenarios where people are running benchmarks or working to maximize the number of transactions to a server; it starts to be a significant factor at those higher ends of the scale but it's not necessarily going to be a noticeable impact when you aren't running configurations at those levels.

Can the multiprocQueueBase be used in a cluster scenario or only the TCP base ?

No, it cannot. The Python Queue object is only useable between processes on the same system. To support your multi-system functionality, you will need either the multiprocTCPBase or the multiprocUDPBase (see previous note though: this one is not recommended). FYI, more information on the different ActorSystem bases is here: https://thespianpy.com/doc/using.html#outline-container-org8296d29

When I set REUSE_SOCKETS = False, I get the following trace:

Whoops, sorry about that! It looks like I haven't run in this mode for quite a while and some bitrot occurred. I've committed (https://github.com/kquick/Thespian/commit/e21f484db5d0207d98274276a2336dcab108c864) an updated TCPTransport.py that fixes this. You should be able to get a new version of this file (https://raw.githubusercontent.com/kquick/Thespian/e21f484db5d0207d98274276a2336dcab108c864/thespian/system/transport/TCPTransport.py) and replace your existing file, or you can checkout the latest master version of the repository. (The committed version still has REUSE_SOCKETS = True, so you'll still need to make that change.)

davideps commented 4 years ago

Kevin, the new version of TCPTransport.py solved the problem! I was able to create thousands of actors without running into the select() error. It is a turn-based simulation. Will I run into a problem when the scheduler tells all the workers to make a move and then they all try to open TCP connections to confirm to the scheduler that they are done? Will the ActorSystem handle the demand for new connections and make sure the open total never exceeds 1,900 or so?

The downside of being able to start all these actors is that I can easily run out of memory (32GB) if I try to generate too many. My machine started to use cache! How can I determine why the actors are using so much memory? The init of the workers is pretty simple:

class Agent(Actor):
    def __init__(self, *args, **kw):
        self.oid = None
        self.firstname = None
        self.lastname = None
        self.fullname = None
        self.cell = None
        super().__init__(*args, **kw)

and

class Cell(Actor):
    def __init__(self, *args, **kw):
        self.oid = None
        self.x = None
        self.y = None
        self.neighbors = {}
        super().__init__(*args, **kw)

The two schedulers (not shown) are a bit heavier. Each holds a dictionary of several thousand worker addresses. Still, that is not close to even a single GB of data.

kquick commented 4 years ago

Great news about the new TCPTransport.py!

There is currently no explicit limiter that would prevent it from trying to open too many sockets at once, although there are limits on the number of active listens which may help to regulate this. There is also a lot of error handling and retry logic in the TCPTransport: it's possible that you've been hitting this limit in other calls and it's been handling those, but the select() is expected to be able to work. It's also a little tricky because just regulating at the getrlimit() value isn't enough because the code doesn't have any way to account for other open file descriptors. Let's keep an eye on your results as you do more testing and when I have some more time (possibly this weekend) I can setup some more extensive tests for investigating this.

Regarding the memory size, I did some rough experimentation and (under Linux) it looks like a started Python process with nothing loaded starts at about 122MB (only ~9.6MB resident). Clearly some of this is shareable, since 1000 processes at that base rate would be 122GB. Windows results may be significantly different, depending on the amount of sharing Windows can achieve with Python DLL's.

One thing you can try is to change the "Process Startup Method" capability (see https://thespianpy.com/doc/using.html#outline-container-org8296d29), which allows you to specify which Python multiprocessing mode is used (modulo system capabilities). Here again, I think Windows is more restricted in this area (try $ python -c "import multiprocessing; print(multiprocessing.get_all_start_methods())" to see what's actually available on your system). Different process startup methods may have different levels of sharing and impact on the resulting process size.

You may want to try using mprof or guppy to do some analysis (https://pypi.org/project/memory-profiler/ and https://www.pluralsight.com/blog/tutorials/how-to-profile-memory-usage-in-python may be helpful). I will look into this situation more as well, although it will take me a couple of days to have time to do this properly. However, unless we can find some egregious usage of memory in the Thespian code itself (which would surprise me, but I'd certainly want to fix it if there was), I'm not sure if there's a lot that can be done to improve things here. Memory is one of the cheaper resources available these days and so there's not a lot of general focus on minimizing footprints and not a lot that Thespian can do to control this.

davideps commented 4 years ago

Thank you Kevin. I'll followup on your suggestions and tell you how it goes. The 9.6MB you mentioned is about what I'm seeing on average across all my actors.

On Wed, Feb 19, 2020 at 8:40 AM Kevin Quick notifications@github.com wrote:

Great news about the new TCPTransport.py!

There is currently no explicit limiter that would prevent it from trying to open too many sockets at once, although there are limits on the number of active listens which may help to regulate this. There is also a lot of error handling and retry logic in the TCPTransport: it's possible that you've been hitting this limit in other calls and it's been handling those, but the select() is expected to be able to work. It's also a little tricky because just regulating at the getrlimit() value isn't enough because the code doesn't have any way to account for other open file descriptors. Let's keep an eye on your results as you do more testing and when I have some more time (possibly this weekend) I can setup some more extensive tests for investigating this.

Regarding the memory size, I did some rough experimentation and (under Linux) it looks like a started Python process with nothing loaded starts at about 122MB (only ~9.6MB resident). Clearly some of this is shareable, since 1000 processes at that base rate would be 122GB. Windows results may be significantly different, depending on the amount of sharing Windows can achieve with Python DLL's.

One thing you can try is to change the "Process Startup Method" capability (see https://thespianpy.com/doc/using.html#outline-container-org8296d29), which allows you to specify which Python multiprocessing mode is used (modulo system capabilities). Here again, I think Windows is more restricted in this area (try $ python -c "import multiprocessing; print(multiprocessing.get_all_start_methods())" to see what's actually available on your system). Different process startup methods may have different levels of sharing and impact on the resulting process size.

You may want to try using mprof or guppy to do some analysis ( https://pypi.org/project/memory-profiler/ and https://www.pluralsight.com/blog/tutorials/how-to-profile-memory-usage-in-python may be helpful). I will look into this situation more as well, although it will take me a couple of days to have time to do this properly. However, unless we can find some egregious usage of memory in the Thespian code itself (which would surprise me, but I'd certainly want to fix it if there was), I'm not sure if there's a lot that can be done to improve things here. Memory is one of the cheaper resources available these days and so there's not a lot of general focus on minimizing footprints and not a lot that Thespian can do to control this.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kquick/Thespian/issues/57?email_source=notifications&email_token=AANTN7NMW72CMRCSQMSQOQ3RDTH6VA5CNFSM4KWSYJR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMGRSWI#issuecomment-588061017, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANTN7JBXRULOP6KHAOGGRDRDTH6VANCNFSM4KWSYJRQ .

davideps commented 4 years ago

Kevin, is it possible for all actors to send messages but for some actors to actually be processes and others to be some lighter thing like a thread? For example, each cell in my grid is an actor. But, could each cell be a thread within a single grid process? The goal here is to reduce memory usage. The grid itself might never send or receive messages--it.just contains the grid actors.

On Wed, Feb 19, 2020, 10:33 AM David Epstein davideps@umich.edu wrote:

Thank you Kevin. I'll followup on your suggestions and tell you how it goes. The 9.6MB you mentioned is about what I'm seeing on average across all my actors.

On Wed, Feb 19, 2020 at 8:40 AM Kevin Quick notifications@github.com wrote:

Great news about the new TCPTransport.py!

There is currently no explicit limiter that would prevent it from trying to open too many sockets at once, although there are limits on the number of active listens which may help to regulate this. There is also a lot of error handling and retry logic in the TCPTransport: it's possible that you've been hitting this limit in other calls and it's been handling those, but the select() is expected to be able to work. It's also a little tricky because just regulating at the getrlimit() value isn't enough because the code doesn't have any way to account for other open file descriptors. Let's keep an eye on your results as you do more testing and when I have some more time (possibly this weekend) I can setup some more extensive tests for investigating this.

Regarding the memory size, I did some rough experimentation and (under Linux) it looks like a started Python process with nothing loaded starts at about 122MB (only ~9.6MB resident). Clearly some of this is shareable, since 1000 processes at that base rate would be 122GB. Windows results may be significantly different, depending on the amount of sharing Windows can achieve with Python DLL's.

One thing you can try is to change the "Process Startup Method" capability (see https://thespianpy.com/doc/using.html#outline-container-org8296d29), which allows you to specify which Python multiprocessing mode is used (modulo system capabilities). Here again, I think Windows is more restricted in this area (try $ python -c "import multiprocessing; print(multiprocessing.get_all_start_methods())" to see what's actually available on your system). Different process startup methods may have different levels of sharing and impact on the resulting process size.

You may want to try using mprof or guppy to do some analysis ( https://pypi.org/project/memory-profiler/ and https://www.pluralsight.com/blog/tutorials/how-to-profile-memory-usage-in-python may be helpful). I will look into this situation more as well, although it will take me a couple of days to have time to do this properly. However, unless we can find some egregious usage of memory in the Thespian code itself (which would surprise me, but I'd certainly want to fix it if there was), I'm not sure if there's a lot that can be done to improve things here. Memory is one of the cheaper resources available these days and so there's not a lot of general focus on minimizing footprints and not a lot that Thespian can do to control this.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kquick/Thespian/issues/57?email_source=notifications&email_token=AANTN7NMW72CMRCSQMSQOQ3RDTH6VA5CNFSM4KWSYJR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMGRSWI#issuecomment-588061017, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANTN7JBXRULOP6KHAOGGRDRDTH6VANCNFSM4KWSYJRQ .

davideps commented 4 years ago

sorry, I think the default on windows is spawn (not fork)

On Wed, Feb 19, 2020 at 5:39 PM David Epstein davideps@umich.edu wrote:

I'd like to compare performance under the fork (default) and forkserver startup methods. Using the default settings, 500 actors required 5.1GB (10.2MB per actor) and took 1min 3sec to generate on a single thread. I can't figure out where to specify "forkserver" for comparison. It doesn't seem to be a parameter of ActorSystem. Is it a capability? I've tried:

asys = ActorSystem('multiprocTCPBase, set_start_method="forkserver")

and

asys = ActorSystem('multiprocTCPBase') asys.set_start_method("forkserver")

and

from multiprocessing import set_start_method set_start_method("forkserver")

On Wed, Feb 19, 2020 at 3:35 PM David Epstein davideps@umich.edu wrote:

Kevin, is it possible for all actors to send messages but for some actors to actually be processes and others to be some lighter thing like a thread? For example, each cell in my grid is an actor. But, could each cell be a thread within a single grid process? The goal here is to reduce memory usage. The grid itself might never send or receive messages--it.just contains the grid actors.

On Wed, Feb 19, 2020, 10:33 AM David Epstein davideps@umich.edu wrote:

Thank you Kevin. I'll followup on your suggestions and tell you how it goes. The 9.6MB you mentioned is about what I'm seeing on average across all my actors.

On Wed, Feb 19, 2020 at 8:40 AM Kevin Quick notifications@github.com wrote:

Great news about the new TCPTransport.py!

There is currently no explicit limiter that would prevent it from trying to open too many sockets at once, although there are limits on the number of active listens which may help to regulate this. There is also a lot of error handling and retry logic in the TCPTransport: it's possible that you've been hitting this limit in other calls and it's been handling those, but the select() is expected to be able to work. It's also a little tricky because just regulating at the getrlimit() value isn't enough because the code doesn't have any way to account for other open file descriptors. Let's keep an eye on your results as you do more testing and when I have some more time (possibly this weekend) I can setup some more extensive tests for investigating this.

Regarding the memory size, I did some rough experimentation and (under Linux) it looks like a started Python process with nothing loaded starts at about 122MB (only ~9.6MB resident). Clearly some of this is shareable, since 1000 processes at that base rate would be 122GB. Windows results may be significantly different, depending on the amount of sharing Windows can achieve with Python DLL's.

One thing you can try is to change the "Process Startup Method" capability (see https://thespianpy.com/doc/using.html#outline-container-org8296d29), which allows you to specify which Python multiprocessing mode is used (modulo system capabilities). Here again, I think Windows is more restricted in this area (try $ python -c "import multiprocessing; print(multiprocessing.get_all_start_methods())" to see what's actually available on your system). Different process startup methods may have different levels of sharing and impact on the resulting process size.

You may want to try using mprof or guppy to do some analysis ( https://pypi.org/project/memory-profiler/ and https://www.pluralsight.com/blog/tutorials/how-to-profile-memory-usage-in-python may be helpful). I will look into this situation more as well, although it will take me a couple of days to have time to do this properly. However, unless we can find some egregious usage of memory in the Thespian code itself (which would surprise me, but I'd certainly want to fix it if there was), I'm not sure if there's a lot that can be done to improve things here. Memory is one of the cheaper resources available these days and so there's not a lot of general focus on minimizing footprints and not a lot that Thespian can do to control this.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kquick/Thespian/issues/57?email_source=notifications&email_token=AANTN7NMW72CMRCSQMSQOQ3RDTH6VA5CNFSM4KWSYJR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMGRSWI#issuecomment-588061017, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANTN7JBXRULOP6KHAOGGRDRDTH6VANCNFSM4KWSYJRQ .

kquick commented 4 years ago

It isn't possible for the Actor itself to be a thread (that was the development route I was talking about above that I considered but couldn't make work in a general fashion), but you can write an Actor that has multiple threads. Despite my aversion to recommending mixed concurrency mechanisms, this might be a good practical approach for your scalability needs.

Essentially you would have a grid Actor that contained some number of cells, where each cell could be a separate thread. The Actor receiveMessage() would always be invoked by Thespian in the context of the main grid thread, so it would need some mechanism to pass the message to the correct "cell" thread (using one of the mechanisms discussed in Python's multithreading library). The "cell" thread's can call self.send() directly to send their responses as that call should be thread-safe in Thespian.

Regarding Windows using spawn, I recall that now. Under Linux, a spawn is potentially slower, although it might have the advantage of carrying across less instantiated memory. Windows will have very different characteristics however in how it handles multiprocessing and system resources, but it sounds like this is not a parameter that you can experiment with to try to get some savings.

kquick commented 3 years ago

Hi @davideps, are there still concerns to be addressed regarding this issue?