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

Add flag to handle running processes automatically #954

Merged
merged 5 commits into from
Apr 8, 2020

Conversation

bartier
Copy link
Contributor

@bartier bartier commented Apr 6, 2020

This PR implements a explicit flag --kill-running-processes to Rally that kills automatically previous running Rally benchmarks.

This is useful when you stop your terminal with CTRL-C and the Rally processes keeps running and the next time you run Rally you'll receive an error something like that:

[ERROR] Cannot race. There are other Rally processes running on this machine (PIDs: [4122, 4123, 4124, 4172, 4234, 4235]) but only one Rally benchmark is allowed to run at the same time. Please check and terminate these processes and retry again.

Instead of receiving the message above, you can add --kill-running-processes to automatically terminate these processes for you.

Ps: I'm not sure if I handled correctly the method with_actor_system. I tried follow the logic in this method and make the necessary changes.

def with_actor_system(runnable, cfg, kill_running_processes):
    import thespian.actors
    logger = logging.getLogger(__name__)
    already_running = actor.actor_system_already_running()
    logger.info("Actor system already running locally? [%s]", str(already_running))
    try:
        if already_running and kill_running_processes:
            actors = actor.bootstrap_actor_system(try_join=False, prefer_local_only=already_running)
        else:
            actors = actor.bootstrap_actor_system(try_join=already_running, prefer_local_only=not already_running)

        # We can only support remote benchmarks if we have a dedicated daemon that is not only bound to 127.0.0.1
        cfg.add(config.Scope.application, "system", "remote.benchmarking.supported", already_running)

Link to with_actor_system changes

If the changes in with_actor_system is not applied, I receive the following errors:
image

Refers to #922

Copy link
Member

@danielmitterdorfer danielmitterdorfer left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I did a first pass and left some suggestions.

esrally/rally.py Outdated

if kill_running_processes:
console.info("Killing running processes ...", flush=True)
for pid in pids:
Copy link
Member

Choose a reason for hiding this comment

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

We already had this functionality prior to 8adb0f8. Can you please check how it was done there and restore that functionality? I also don't recall that it was necessary to make the actor system bootstrap code aware of this so I'd try to avoid it (after restoring the functionality removed in 8adb0f8).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! I restored the previous functionality and avoided changes in the actor system bootstrap code. Thanks for your suggestion. Can you check again if something needs to be changed?

esrally/rally.py Outdated

if kill_running_processes:
console.info("Killing running processes ...", flush=True)
Copy link
Member

Choose a reason for hiding this comment

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

I think a log message is sufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed. Can you check again?

``kill-running-processes``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Only one Rally benchmark is allowed to run at the same time. If any processes is running, it is going to kill them and allow Rally to continue to run a new benchmark.
Copy link
Member

Choose a reason for hiding this comment

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

I think we could add an explanation why we want that (in order to ensure that benchmark results are not skewed due to unintentionally running multiple benchmarks at the same time).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added more information in the docs about why we want that. Can you check again?

@danielmitterdorfer danielmitterdorfer added :Usability Makes Rally easier to use enhancement Improves the status quo labels Apr 8, 2020
@danielmitterdorfer danielmitterdorfer added this to the 1.5.0 milestone Apr 8, 2020
@danielmitterdorfer
Copy link
Member

@elasticmachine test this please

Copy link
Member

@danielmitterdorfer danielmitterdorfer left a comment

Choose a reason for hiding this comment

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

Thanks! That looks much better; I left a few more comments.

``kill-running-processes``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Rally attempts to generate benchmark results that are not skewed unintentionally. Consequently, if some benchmark is running, Rally will not allow you to start another one. Instead, you should stop the current benchmark and start another one manually. This flag can be added to handle automatically for you this stop-start processes.
Copy link
Member

Choose a reason for hiding this comment

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

nit: for you this stop-start process -> this process for you?

self.assertTrue(rally_process_e.killed)
self.assertTrue(rally_process_mac.killed)
self.assertFalse(own_rally_process.killed)
self.assertFalse(night_rally_process.killed)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Missing trailing new line

esrally/rally.py Outdated
if other_rally_processes:
pids = [p.pid for p in other_rally_processes]

msg = "There are other Rally processes running on this machine (PIDs: %s) but only one Rally benchmark " \
Copy link
Member

Choose a reason for hiding this comment

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

We are using .format and recently f-strings so can you please rewrite this as:

msg = f"There are other Rally processes running on this machine (PIDs: {pids}) but only one Rally " \
      f"benchmark is allowed to run at the same time.\n\nPlease rerun with --kill-running-processes to " \
      f"terminate them automatically."

(I also suggested a slightly different wording)

esrally/rally.py Outdated


def with_actor_system(runnable, cfg):
def with_actor_system(runnable, cfg, kill_running_processes):
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be a leftover?

esrally/rally.py Outdated

with_actor_system(racecontrol.run, cfg)
with_actor_system(racecontrol.run, cfg, kill_running_processes)
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be a leftover?

esrally/rally.py Outdated
raise exceptions.RallyError(msg)
logger = logging.getLogger(__name__)

kill_running_processes = cfg.opts("system", "kill.running.processes", default_value=False, mandatory=False)
Copy link
Member

Choose a reason for hiding this comment

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

I think we can simplify this to:

kill_running_processes = cfg.opts("system", "kill.running.processes")

The value should be mandatory at this point because we added it previously in bootstrap code?

esrally/rally.py Outdated
@@ -23,6 +23,7 @@
import sys
import time
import uuid
import signal
Copy link
Member

Choose a reason for hiding this comment

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

The linter in CI raised an error that this import is unused:

12:20:20 esrally/rally.py:26:0: W0611: Unused import signal (unused-import)

Can you please remove it?

@bartier
Copy link
Contributor Author

bartier commented Apr 8, 2020

@danielmitterdorfer I made the changes you suggested. Can you check again and run the tests?

@danielmitterdorfer
Copy link
Member

@elasticmachine test this please

Copy link
Member

@danielmitterdorfer danielmitterdorfer left a comment

Choose a reason for hiding this comment

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

Thanks for your change @bartier! It looks good to me now and the CI build passes as well. I'll merge it soon and it wil be released with the next Rally release 1.5.0.

@danielmitterdorfer danielmitterdorfer merged commit 97eaa37 into elastic:master Apr 8, 2020
@bartier
Copy link
Contributor Author

bartier commented Apr 8, 2020

@danielmitterdorfer
Some issues are too complex for me to understand, but I try to help any way I can, as well improve my Python skills =)

Thanks for your attention. Glad to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improves the status quo :Usability Makes Rally easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants