slaclab / pysmurf

Other
2 stars 9 forks source link

Cache PVs #744

Closed swh76 closed 1 year ago

swh76 commented 1 year ago

Description

This PR changes the way we caget/caput all EPICs registers to address issue https://github.com/slaclab/pysmurf/issues/742; EPICs PVs are now cached in the pysmurf.client.SmurfControl instance instead of every PV request being a new caget/caput call. This change is being made to solve some issues we ran into running the SO SAT1 systems where PV gets/sets seem to get slower and slower in proportion to the total number of calls (and in the worst cases, stalling out completely). This change was cribbed from https://cars9.uchicago.edu/software/python/pyepics3/advanced.html, where the pyepics developers suggest caching PV objects to avoid cumulative overhead of large numbers of cagets/caputs.

For the majority of registers accessed via smurf_command gets and sets, the PV objects are cached in a dictionary called _pv_cache in the SmurfControl instance:

https://github.com/slaclab/pysmurf/blob/6d57a474d9fbc39fcf189c2a6b05af75bcd7b849/python/pysmurf/client/base/smurf_control.py#L113

the keys in that dictionary are the EPICs paths of the registers, and the values are PV objects instantiated on those paths. PV objects are only instantiated on the first get or set of a register. See e.g.

https://github.com/slaclab/pysmurf/blob/issue742/python/pysmurf/client/command/smurf_command.py#L104-L108

Some special handling was required for the CryoCard class that handles cryostat card PIC gets/sets; here the class variables readpv and writepv that had held the EPICs path to the cryostat card PIC read/write PV now are instantiated as pyepics PV objects, see https://github.com/slaclab/pysmurf/blob/6d57a474d9fbc39fcf189c2a6b05af75bcd7b849/python/pysmurf/client/command/cryo_card.py#L42 and gets/sets are called on those.

No interface changes ; this change should be invisible to the user other than an improvement in performance, particularly for users doing a lot of high cadence register polling.