napalm icon indicating copy to clipboard operation
napalm copied to clipboard

JunOS: Caching of interface_list in get_facts()

Open kzorba opened this issue 2 years ago • 5 comments

Caching of interface_list in get_facts

In junos driver when get_facts() is called a get-interface-information rpc call is issued that can be a very expensive operation in some cases (eg BNG devices). Caching of interface_list in facts can greatly benefit performance.

When NAPALM is used in a Salt(stack) environment during proxy minion startup get_facts() is called multiple times. On some devices, like BNG boxes, the get-interface-information is a very expensive operation and can cause the minion to wait multiple minutes to be able to start receiving and servicing requests from the salt master after its boot. While a lot of other facts are cached smartly in the underlying PyEZ library, NAPALM does not cache interface_lists. A PR will follow with a fix to enable further discussion. This caching mechanism could also benefit get_interfaces().

Setup

Install Salt v3002.7 and NAPALM 3.3.1, configure a proxy minion to target a BNG box with thousands on sessions terminated on it.

napalm version

root@proxy-mxlar1-mq:~# pip freeze | grep napalm
napalm==3.3.1

Network operating system version

Tested with:

Junos: 17.3R3-S3.3

Problem is most probably there with other (or all) recent JunOS versions.

Steps to Reproduce the Issue

Configure a Salt proxy minion targeting a BNG box with many sessions of users. Watch the startup process of the minion and observe the many times get-interfaces-information rpc is called via get_facts() that cause the minion to wait even for 10s of minutes.

kzorba avatar Oct 12 '21 15:10 kzorba

@kzorba If you don’t need grains you could disable grains on your minion.

network-shark avatar Feb 20 '22 23:02 network-shark

@network-shark Thanks for the input, unfortunately I don't see any option that allows you to do that on the minion. Any references?

kzorba avatar Mar 01 '22 18:03 kzorba

@kzorba

From the Saltstack docs , there is a blacklist grains option .

 grains_blacklist:
  - cpu_flags
  - zmq*
  - ipv[46]

Let me know if it is working for you never have to use it.

network-shark avatar Mar 01 '22 20:03 network-shark

Hello @network-shark, I had seen this option and I just tested it. It works as I expected, the grains collections happen like before but the specific items you put in this option are filtered out afterwards. No effect in my problem, the router is overwhelmed with get-interface-information netconf requests. I believe the way to go is to use 'provider' option in napalm proxy minion, overriding napalm_base with my implementation.

kzorba avatar Mar 02 '22 11:03 kzorba

@kzorba Ok , maybe the naming here is a bit odd. For me blacklisting is that it should not be executed anyway. But maybe this is more a salt issue / feature request.

One last thing you could check what @mirceaulinic did with salt-sproxy --cache-grains

https://salt-sproxy.readthedocs.io/en/latest/opts.html

There is a option --cache-grains This argument has been defaulted to True

Even if you are not using it , maybe it helps how he implemented it.

network-shark avatar Mar 02 '22 21:03 network-shark