Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Reduce logging system overhead #3416

Merged
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev/environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies:
- mitmproxy
- pytest >=7.3.0
- pytest-asyncio
- pytest-timeout
- pytest-xprocess
- requests
- sel(win): pywin32
Expand Down
14 changes: 13 additions & 1 deletion libmamba/src/solver/libsolv/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,19 @@ namespace mamba::solver::libsolv

void Database::set_logger(logger_type callback)
{
::pool_setdebuglevel(pool().raw(), std::numeric_limits<int>::max()); // All
// We must not use more than the penultimate level of verbosity of libsolv (which is 3) to
// avoid the most verbose messages (of type SOLV_DEBUG_RULE_CREATION | SOLV_DEBUG_WATCHES),
// which might spam the output and make mamba hang. See:
// https://github.com/openSUSE/libsolv/blob/27aa6a72c7db73d78aa711ae412231768e77c9e0/src/pool.c#L1623-L1637
// TODO: Make `level` configurable once the semantics and UX for verbosity are clarified.
// Currently, we use the behavior of `1.x` whose default value for the verbosity level was
// `0` in which case the logs of libsolv were not transferred. See:
// https://github.com/mamba-org/mamba/blob/4f269258b4237a342da3e9891045cdd51debb27c/libmamba/include/mamba/core/context.hpp#L88
// See: https://github.com/mamba-org/mamba/blob/1.x/libmamba/src/core/pool.cpp#L72
// Instead use something like:
// const int level = Context().output_params.verbosity - 1;
const int level = 0;
::pool_setdebuglevel(pool().raw(), level);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 1.x we were doing:
pool_setdebuglevel(pool().raw(), Context::instance().output_params.verbosity - 1);
when verbosity >= 3
Otherwise pool_setdebuglevel wasn't called. That means that it was set to something in libsolv internals not to the default value of verbosity in mamba.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value of libsolv's pool->debugmask is SOLV_DEBUG_RESULT.

If we call it with 0 we only &=SOLV_DEBUG_TO_STDERR it. Not sure if it causes a problem in practice, but let's thus not call it for now at all.

pool().set_debug_callback(
[logger = std::move(callback)](const solv::ObjPoolView&, int type, std::string_view msg) noexcept
{
Expand Down
17 changes: 17 additions & 0 deletions micromamba/tests/env-logging-overhead-regression.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This environment was observed to have the spdlog-based logging system make
# mamba hang when environments are created with:
#
# {micromamba,mamba} env create -n repro-create -f ./env-logging-overhead-regression.yaml
#
# or updated with:
#
# {micromamba,mamba} env update -n repro-create -f ./env-logging-overhead-regression.yaml
#
channels:
- conda-forge
dependencies:
- python=3.9
- xeus-cling=0.6.0
- xtensor=0.20.8
- xtensor-blas=0.16.1
- notebook
18 changes: 18 additions & 0 deletions micromamba/tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,24 @@ def test_env_lockfile_different_install_after_create(tmp_home, tmp_root_prefix,
helpers.install("-p", env_prefix, "-f", install_spec_file, "-y", "--json")


# Only run this test on Linux, as it is the only platform where xeus-cling
# (which is part of the environment) is available.
@pytest.mark.timeout(20)
@pytest.mark.skipif(platform.system() != "Linux", reason="Test only available on Linux")
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
def test_env_logging_overhead_regression(tmp_home, tmp_root_prefix, tmp_path):
# Non-regression test https://github.com/mamba-org/mamba/issues/3415.

env_prefix = tmp_path / "myenv"
create_spec_file = tmp_path / "env-logging-overhead-regression.yaml"

shutil.copyfile(__this_dir__ / "env-logging-overhead-regression.yaml", create_spec_file)

# Must not hang
res = helpers.create("-p", env_prefix, "-f", create_spec_file, "-y", "--json", "--dry-run")
assert res["success"]
jjerphan marked this conversation as resolved.
Show resolved Hide resolved


@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
@pytest.mark.parametrize("root_prefix_type", (None, "env_var", "cli"))
@pytest.mark.parametrize("target_is_root", (False, True))
Expand Down
7 changes: 2 additions & 5 deletions micromamba/tests/test_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ def test_remove_orphaned(tmp_home, tmp_root_prefix, tmp_xtensor_env, tmp_env_nam
assert keys.issubset(set(res.keys()))
assert res["success"]

if sys.platform == "darwin" and platform.machine() == "arm64":
assert len(res["actions"]["UNLINK"]) == 12
else:
assert len(res["actions"]["UNLINK"]) == 11
assert len(res["actions"]["UNLINK"]) == 12
jjerphan marked this conversation as resolved.
Show resolved Hide resolved
assert res["actions"]["UNLINK"][0]["name"] == "xtensor-python"
assert res["actions"]["PREFIX"] == str(tmp_xtensor_env)

Expand All @@ -64,7 +61,7 @@ def test_remove_orphaned(tmp_home, tmp_root_prefix, tmp_xtensor_env, tmp_env_nam
# assert len(res["actions"]["UNLINK"]) == len(env_pkgs) + (
assert len(res["actions"]["UNLINK"]) == 3 + (
1 if helpers.dry_run_tests == helpers.DryRun.DRY else 0
)
) + (platform.system() == "Linux") # xtl is not removed on Linux
for p in res["actions"]["UNLINK"]:
assert p["name"] in env_pkgs
assert res["actions"]["PREFIX"] == str(tmp_xtensor_env)
Expand Down
Loading