high-yak-85899
02/03/2022, 2:20 AMhigh-yak-85899
02/03/2022, 2:22 AM--cov --no-cov-on-fail
in our pytest.ini addopts
section in this repo and that we make heavy use of unittest.mock
with their create_autospec method (this is critical to help us mock away hardware dependencies that this repo is normally used for).high-yak-85899
02/03/2022, 2:23 AM(ops-venv) ~/devel/operations (pants)$ ./pants test --force ops/utils/wheel_utils_test.py
19:22:38.71 [INFO] Completed: Run Pytest - ops/utils/wheel_utils_test.py:tests succeeded.
✓ ops/utils/wheel_utils_test.py:tests succeeded in 4.55s.
Wrote test XML to `dist/test_results`
(ops-venv) ~/devel/operations (pants)$ pytest ops/utils/wheel_utils_test.py
================================================================================================================================================ test session starts ================================================================================================================================================
platform linux -- Python 3.8.10, pytest-5.4.3, py-1.10.0, pluggy-0.13.1
rootdir: /home/nathanael/devel/operations, inifile: pytest.ini
plugins: typeguard-2.12.1, xdist-1.34.0, timeout-2.1.0, forked-1.3.0, cov-3.0.0
timeout: 1.0s
timeout method: signal
timeout func_only: False
collected 3 items
ops/utils/wheel_utils_test.py ... [100%]
================================================================================================================================================= 3 passed in 0.32s =================================================================================================================================================
high-yak-85899
02/03/2022, 2:23 AMhappy-kitchen-89482
02/03/2022, 2:31 AM--force
?hundreds-father-404
02/03/2022, 2:53 AMhigh-yak-85899
02/03/2022, 2:57 AMhigh-yak-85899
02/03/2022, 3:00 AMhundreds-father-404
02/03/2022, 3:02 AMtest --debug
, which runs in the foreground as an interactive process?hundreds-father-404
02/03/2022, 3:02 AMContention seems surprising when I'm running one thing in isolationYeah, wouldn't explain the 5 seconds vs. 0.5 seconds. But might explain the 5 seconds vs 15-20
high-yak-85899
02/03/2022, 3:06 AMconftest.py
to make the times pytest reports lower than they actually are).
(ops-venv) ~/devel/operations (pants)$ ./pants test --force --output=all ops/utils/wheel_utils_test.py --pytest-args="--durations=3"
20:05:05.79 [INFO] Initializing scheduler...
20:05:05.90 [INFO] Scheduler initialized.
20:05:12.61 [INFO] Completed: Run Pytest - ops/utils/wheel_utils_test.py:tests succeeded.
============================= test session starts ==============================
platform linux -- Python 3.8.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /tmp/process-executioneNcGLY, configfile: pytest.ini
plugins: typeguard-2.12.1, timeout-2.1.0, cov-3.0.0
timeout: 4.0s
timeout method: signal
timeout func_only: False
collected 3 items
ops/utils/wheel_utils_test.py ... [100%]
=============================== warnings summary ===============================
../../home/nathanael/.cache/pants/named_caches/pex_root/venvs/s/08108cc5/venv/lib/python3.8/site-packages/marshmallow/__init__.py:17
/home/nathanael/.cache/pants/named_caches/pex_root/venvs/s/08108cc5/venv/lib/python3.8/site-packages/marshmallow/__init__.py:17: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
__version_info__ = tuple(LooseVersion(__version__).version)
-- Docs: <https://docs.pytest.org/en/stable/warnings.html>
- generated xml file: /tmp/process-executioneNcGLY/ops.utils.wheel_utils_test.py.tests.xml -
============================= slowest 3 durations ==============================
1.61s call ops/utils/wheel_utils_test.py::CommandSpeedsFromList::test_commanding_speeds_from_list
0.08s call ops/utils/wheel_utils_test.py::SetSpeedAndStabilizeTests::test_setting_speed_and_stabilize
0.08s call ops/utils/wheel_utils_test.py::WaitForWheelSpeedStabilized::test_waiting_to_stabilize
========================= 3 passed, 1 warning in 3.74s =========================
✓ ops/utils/wheel_utils_test.py:tests succeeded in 4.51s.
Wrote test XML to `dist/test_results`
(ops-venv) ~/devel/operations (pants)$ pytest ops/utils/wheel_utils_test.py --durations=3
================================================================================================================================================ test session starts ================================================================================================================================================
platform linux -- Python 3.8.10, pytest-5.4.3, py-1.10.0, pluggy-0.13.1
rootdir: /home/nathanael/devel/operations, inifile: pytest.ini
plugins: typeguard-2.12.1, xdist-1.34.0, timeout-2.1.0, forked-1.3.0, cov-3.0.0
timeout: 4.0s
timeout method: signal
timeout func_only: False
collected 3 items
ops/utils/wheel_utils_test.py ... [100%]
============================================================================================================================================= slowest 3 test durations ==============================================================================================================================================
1.49s call ops/utils/wheel_utils_test.py::CommandSpeedsFromList::test_commanding_speeds_from_list
0.09s call ops/utils/wheel_utils_test.py::WaitForWheelSpeedStabilized::test_waiting_to_stabilize
0.07s call ops/utils/wheel_utils_test.py::SetSpeedAndStabilizeTests::test_setting_speed_and_stabilize
================================================================================================================================================= 3 passed in 1.71s =================================================================================================================================================
high-yak-85899
02/03/2022, 3:06 AMhigh-yak-85899
02/03/2022, 3:08 AMdependencies --transitive
, I see my other repo that's pulled in as a dependency as just //:astranis-python
. So maybe it's just taking a really long time to bundle/package up the test?high-yak-85899
02/03/2022, 3:08 AMhundreds-father-404
02/03/2022, 3:12 AMimmutable_paths
APIhappy-kitchen-89482
02/03/2022, 3:20 AMhappy-kitchen-89482
02/03/2022, 3:21 AM--force
and seeing significant overhead every time, that's something we'd want to look into.happy-kitchen-89482
02/03/2022, 3:22 AM//:astranis-python
looks like it's on a wheel you've published from that other repo?happy-kitchen-89482
02/03/2022, 3:25 AM20:05:05.79 [INFO] Initializing scheduler...
20:05:05.90 [INFO] Scheduler initialized.
on every run?happy-kitchen-89482
02/03/2022, 3:26 AMhigh-yak-85899
02/03/2022, 3:40 AMrequirements.txt
.high-yak-85899
02/03/2022, 3:40 AMRun Pytest
high-yak-85899
02/03/2022, 3:43 AM20:41:43.97 [DEBUG] Completed: Hit: Local cache lookup: Building requirements.pex with 1 requirement: astranis-python@ <git+ssh://git@git.corp.astranis.com/source/monorepo.git@6980a7de52f8>
with -ldebug
high-yak-85899
02/03/2022, 3:49 AMastranis-python
dependency are taking a long time to import. When pants is running the test, the import sections take ~1.8 seconds. When I run it normally with pytest
, it takes 0.002 seconds.high-yak-85899
02/03/2022, 3:50 AMhigh-yak-85899
02/03/2022, 3:53 AMhappy-kitchen-89482
02/03/2022, 3:54 AM-ldebug
output across multiple runs, would be really appreciated!happy-kitchen-89482
02/03/2022, 3:54 AMhappy-kitchen-89482
02/03/2022, 3:55 AMhappy-kitchen-89482
02/03/2022, 3:55 AMIt seems the modules from my astranis-python dependency are taking a long time to import. When pants is running the test, the import sections take ~1.8 seconds. When I run it normally with pytest, it takes 0.002 seconds.
happy-kitchen-89482
02/03/2022, 3:55 AMhappy-kitchen-89482
02/03/2022, 3:55 AMhappy-kitchen-89482
02/03/2022, 3:56 AMhigh-yak-85899
02/03/2022, 3:56 AMhappy-kitchen-89482
02/03/2022, 3:56 AMhappy-kitchen-89482
02/03/2022, 3:58 AMhigh-yak-85899
02/03/2022, 4:00 AM.pyc
files deleted.high-yak-85899
02/03/2022, 4:01 AMimport time
t1 = time.monotonic()
<here's where all my from astranis.whatever import thing goes>
...
<end of astranis import>
raise RuntimeError(time.monotonic() - t1)
high-yak-85899
02/03/2022, 4:02 AMpytest
(whether pyc files have been nuked or not) I see those imports taking around 2 ms.
ops/utils/wheel_utils_test.py:16: in <module>
raise RuntimeError(time.monotonic() - t1)
E RuntimeError: 0.002227158984169364
and with no changes, when pants runs it, I see around 2 seconds
21:02:42.57 [ERROR] Completed: Run Pytest - ops/utils/wheel_utils_test.py:tests failed (exit code 2).
============================= test session starts ==============================
platform linux -- Python 3.8.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /tmp/process-executionXr6TSG, configfile: pytest.ini
plugins: typeguard-2.12.1, timeout-2.1.0, cov-3.0.0
timeout: 4.0s
timeout method: signal
timeout func_only: False
collected 0 items / 1 error
==================================== ERRORS ====================================
________________ ERROR collecting ops/utils/wheel_utils_test.py ________________
ops/utils/wheel_utils_test.py:16: in <module>
raise RuntimeError(time.monotonic() - t1)
E RuntimeError: 1.5522927539423108
high-yak-85899
02/03/2022, 4:04 AMfrom astranis import something
like statements I havehigh-yak-85899
02/03/2022, 4:12 AMenvironment.py
). There's nothing heavy running on import (just normal class and function definitions). The only outliar thing is that file needs to import psycopg2
. I know that one is special in how it's downloaded so maybe it's taking it a while to know that was bundled with astranis-python to find?high-yak-85899
02/03/2022, 4:21 AMcurved-television-6568
02/03/2022, 5:33 AMSorry for the wild ride.Not at all, these cases are always interesting, because it shows an area that can be improved, in terms of insights/feedback/transparency whats going on etc. 🙂 (at least my personal view)
high-yak-85899
02/03/2022, 7:12 AMhigh-yak-85899
02/03/2022, 7:14 AMhundreds-father-404
02/03/2022, 4:03 PM.pyc
files. But curious that you said it didn't make a difference. Dang I wish I remembered to put that in the 2022 prioritization surveyenough-analyst-54434
02/03/2022, 4:10 PMenough-analyst-54434
02/03/2022, 4:12 PMhigh-yak-85899
02/03/2022, 4:28 PMhigh-yak-85899
02/03/2022, 4:33 PMhigh-yak-85899
02/03/2022, 4:45 PMbusy-vase-39202
02/03/2022, 5:43 PMhappy-kitchen-89482
02/03/2022, 9:49 PMhappy-kitchen-89482
02/03/2022, 9:50 PMpsycopg2
should take 2 seconds even in that situationhappy-kitchen-89482
02/03/2022, 9:52 PMhappy-kitchen-89482
02/03/2022, 9:52 PM(venv) statler:[/tmp/venv]$ time python -c "import psycopg2"
real 0m0.757s
user 0m0.044s
sys 0m0.018s
(venv) statler:[/tmp/venv]$ time python -c "import psycopg2"
real 0m0.062s
user 0m0.043s
sys 0m0.016s
high-yak-85899
02/03/2022, 9:53 PMhigh-yak-85899
02/03/2022, 9:54 PMpsycopg2
was kind of a false positive it seemed. The real issue is just the number of imports and lack of caching. So each test (which lives in a different process) all have to do the same heavy import from scratch each time.happy-kitchen-89482
02/03/2022, 9:54 PMhappy-kitchen-89482
02/03/2022, 9:54 PMhappy-kitchen-89482
02/03/2022, 9:54 PMhappy-kitchen-89482
02/03/2022, 9:55 PMhappy-kitchen-89482
02/03/2022, 9:55 PMhappy-kitchen-89482
02/03/2022, 9:57 PM__pycache__
(and I'm not sure we can easily, since it's not append-only)high-yak-85899
02/03/2022, 9:57 PMhappy-kitchen-89482
02/03/2022, 9:58 PMhigh-yak-85899
02/03/2022, 9:58 PMhigh-yak-85899
02/03/2022, 9:59 PMhappy-kitchen-89482
02/03/2022, 9:59 PMhigh-yak-85899
02/03/2022, 10:01 PMhappy-kitchen-89482
02/03/2022, 10:01 PMhappy-kitchen-89482
02/03/2022, 10:02 PMhappy-kitchen-89482
02/03/2022, 10:02 PMhigh-yak-85899
02/03/2022, 11:00 PMpytest-xdist
. You still only need to collect/batch what has changed according to the dependency graph. Feels like "advanced option" territory, but maybe more tractable than handling the general problem. It's definitely fair to suggest that we don't architect code that has such a heavy dependency tree.high-yak-85899
02/03/2022, 11:15 PMbusy-vase-39202
02/03/2022, 11:30 PMyup, will link here when I get to it.Just an aside: since we're on Slack's free tier, messages disappear from here relatively quickly. So it's best to recap conversation when opening a Pants issue, rather than just linking.
high-yak-85899
02/03/2022, 11:44 PMhappy-kitchen-89482
02/03/2022, 11:54 PMenough-analyst-54434
02/04/2022, 12:12 AMhigh-yak-85899
02/04/2022, 12:14 AMenough-analyst-54434
02/04/2022, 12:17 AMvenv_use_symlinks
here: https://www.pantsbuild.org/docs/reference-pex#advanced-options should make 3rdparty (psychopg?) compilation fully shared leaving only 1st party code dealt with via PEX_EXTRA_SYS_PATH
internally by Pants pytest setup suspect. IOW your 1st party code compilation time would have to be large assuming it is still added to the sys.path
for pytest via PEX_EXTRA_SYS_PATH
.high-yak-85899
02/04/2022, 12:19 AMhigh-yak-85899
02/04/2022, 12:21 AM(mono-venv) ~/devel/monorepo (better-bootstrap)$ ipython
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import time
In [2]: def test():
...: t1 = time.monotonic()
...: from astranis.service import handler
...: print(time.monotonic() - t1)
...:
In [3]: test()
1.0756074539385736
to give a sense of the time involved.