Open kefeimo opened 1 year ago
Update: from the bench mark the install_agent method in platformwrapper.py rought takes 102 seconds. Here is the log
Note: the significant delay happens at line 1010: stdout = execute_command(cmd, logger=_log, env=self.env,
-- roughly 97 seconds. (97918245634.0 97918245634.0 nm )
To reproduce the result, use the following code snippet (ref: https://pypi.org/project/pytest-line-profiler/)
from volttrontesting.platformwrapper import PlatformWrapper
@pytest.mark.line_profile.with_args(PlatformWrapper.install_agent,)
def test_install_platform_driver(volttron_instance):
print(volttron_instance)
vi = volttron_instance
# install platform driver
config = {
"driver_scrape_interval": 0.05,
"publish_breadth_first_all": "false",
"publish_depth_first": "false",
"publish_breadth_first": "false"
}
puid = vi.install_agent(agent_dir="volttron-platform-driver",
config_file=config,
start=False,
vip_identity=PLATFORM_DRIVER)
assert puid is not None
gevent.sleep(1) # TODO use retry logic/flexible sleep
assert vi.start_agent(puid)
assert vi.is_agent_running(puid)
print(f"=============== puid {puid}")
Log related to bench mark is as follows: (full pytest log here at: gistfile1.txt
Total time: 102.923 s
File: /home/kefei/project/dev-volttron-modular/volttron-testing/src/volttrontesting/platformwrapper.py
Function: install_agent at line 926
Line # Hits Time Per Hit % Time Line Contents
==============================================================
926 def install_agent(self, agent_wheel: Optional[str] = None,
927 agent_dir: Optional[str] = None,
928 config_file: Optional[Union[dict, str]] = None,
...
957 1 88210.0 88210.0 0.0 with with_os_environ(self.env):
958 1 191071.0 191071.0 0.0 _log.debug(f"install_agent called with params\nagent_wheel: {agent_wheel}\nagent_dir: {agent_dir}")
959 1 756171.0 756171.0 0.0 self.__wait_for_control_connection_to_exit__()
960 1 378150.0 378150.0 0.0 assert self.is_running(), "Instance must be running to install agent."
961 1 836.0 836.0 0.0 assert agent_wheel or agent_dir, "Invalid agent_wheel or agent_dir."
962 1 406.0 406.0 0.0 assert isinstance(startup_time, int), "Startup time should be an integer."
963
...
977 1 2275.0 2275.0 0.0 os.path.basename(agent_dir) + "_config_file")
978 1 210.0 210.0 0.0 if isinstance(config_file, dict):
979 1 1954.0 1954.0 0.0 from os.path import join, basename
980 1 1469.0 1469.0 0.0 temp_config = join(self.volttron_home,
981 1 933.0 933.0 0.0 basename(agent_dir) + "_config_file")
982 1 240690.0 240690.0 0.0 with open(temp_config, "w") as fp:
983 1 18119.0 18119.0 0.0 fp.write(jsonapi.dumps(config_file))
984 1 314.0 314.0 0.0 config_file = temp_config
...
1009 1 102675.0 102675.0 0.0 self.logit(f"Command installation is: {cmd}")
1010 1 97918245634.0 97918245634.0 95.1 stdout = execute_command(cmd, logger=_log, env=self.env,
1011 1 160.0 160.0 0.0 err_prefix="Error installing agent")
1012 1 341448.0 341448.0 0.0 self.logit(f"RESPONSE FROM INSTALL IS: {stdout}")
...
1045 1 279.0 279.0 0.0 assert agent_uuid
1046 1 5002389988.0 5002389988.0 4.9 time.sleep(5)
1047 1 2295.0 2295.0 0.0 if start:
...
Is your feature request related to a problem? Please describe. Volttron testing related to platformwrapper.py is un reasonably slow due to multiple un-flexible and un-robust manual timeout (i.e., time.sleep). As a result, when installing platform driver from volttron-wrapper fixture, the average processing time is 3 minutes, e.g.,
Note that within platformwrapper.py, it use time.sleep syntax, e.g., time.sleep(5) at L1046
Describe the solution you'd like Use more flexible time-out/waiting methods to improve performance.