Skip to content

Commit 695cc9a

Browse files
authored
Upgrade pyroute2 and improve cli response time (#3513)
What I did Older pyroute2 depends on distutils. Thus upgrade the version to latest to improve import time. A similar issue for natsort is reported here [warm-reboot] natsort import is taking more time with python 3.11 in bookworm sonic-buildimage#17246. However pyroute2 import is still heavy in bookworm and thus every CLI command is slow compared to bullseye. <Bullseye> root@msn2700:/home/admin# time python3 -c "import pyroute2" real 0m0.378s user 0m0.308s sys 0m0.060s <Before upgrade> root@msn2700:/home/admin# time python3 -c "import pyroute2" real 0m0.707s user 0m0.425s sys 0m0.097s <After upgrade> root@msn2700:/home/admin# time python3 -c "import pyroute2" real 0m0.511s user 0m0.433s sys 0m0.075s To fix this, i've delayed the pyroute2 import into the method where it is actually used, this has an improvement of 0.4 sec for all the CLI commands on slower CPU devices root@msn2700:/home/admin# time python3 -c "import utilities_common.cli as clicommon" real 0m0.693s user 0m0.579s sys 0m0.109s root@msn2700/home/admin# time python3 -c "import utilities_common.cli as clicommon" real 0m0.363s user 0m0.271s sys 0m0.072s
1 parent 867fc54 commit 695cc9a

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
'pexpect>=4.8.0',
249249
'semantic-version>=2.8.5',
250250
'prettyprinter>=0.18.0',
251-
'pyroute2>=0.5.14, <0.6.1',
251+
'pyroute2==0.7.12',
252252
'requests>=2.25.0, <=2.31.0',
253253
'tabulate==0.9.0',
254254
'toposort==1.6',

utilities_common/multi_asic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import click
55
import netifaces
6-
import pyroute2
76
from natsort import natsorted
87
from sonic_py_common import multi_asic, device_info
98
from utilities_common import constants
@@ -170,6 +169,7 @@ def multi_asic_args(parser=None):
170169
return parser
171170

172171
def multi_asic_get_ip_intf_from_ns(namespace):
172+
import pyroute2
173173
if namespace != constants.DEFAULT_NAMESPACE:
174174
pyroute2.netns.pushns(namespace)
175175
interfaces = natsorted(netifaces.interfaces())
@@ -181,6 +181,7 @@ def multi_asic_get_ip_intf_from_ns(namespace):
181181

182182

183183
def multi_asic_get_ip_intf_addr_from_ns(namespace, iface):
184+
import pyroute2
184185
if namespace != constants.DEFAULT_NAMESPACE:
185186
pyroute2.netns.pushns(namespace)
186187
ipaddresses = netifaces.ifaddresses(iface)

0 commit comments

Comments
 (0)