PureConnect

 View Only
Discussion Thread View
  • 1.  Accumulators with Locks vs Structired Parameters with Semaphore Locks

    Posted 02-18-2022 13:01
    Hi,

    OK, so I have a need to maintain a (variable) number of counters that are shared between multiple instances of a handler. Obviously, Globals are not the way to go and for performance purposes, I don't really want to store them in a database...

    So, I'm thinking of using either Accumulators or Structured Parameters. I figure Accumulators, being in-memory, will be faster and have the benefit of supporting locking to prevent race conditions. I don't believe they sync across a Switchover Pair though (I may be wrong on that) Also, can anyone confirm if, when you attempt to Lock an Accumulator, does the "Lock Accumulator" step pause if it is already locked, or fail? The documentation isn't clear on that!

    Structured Parameters, being stored in DS, should sync (and I believe I can view their current values in IA) but like most DS operations, I figure they will be slower and since there is no way to lock them, I am thinking Semaphore Lock.

    Has anyone got experience of using either (or preferably both!) of these approaches that they care to share? Any other tripwires I haven't considered?

    TIA
    #Handlers

    ------------------------------
    Paul Simpson
    Senior Technical Instructor
    ------------------------------


  • 2.  RE: Accumulators with Locks vs Structired Parameters with Semaphore Locks

    Posted 02-18-2022 15:51

    The only time I've had to do something similar to this involved refreshing bearer tokens for APIs.  I use the approach that you say will be the least performant along with a structured parameter.

    1. Have a handler who's sole purpose is for refreshing your token when the date (in the structured parameter) is nearing an expiration threshold.
    2. That handler requires a global that we don't care about aside from the fact that we need it.  This facilitates locking an queuing of other handlers who come to the same conclusion.
      1. Inside this handler, we re-eval the refresh date again to see if it's already been done or not...and exit if it has.
      2. Otherwise, we update the token which we store as an encrypted value in a structured parameter, then exit.

    I'm not doing exactly what you're looking to do, since I'm just trying to prevent multiple threads from trying to refresh the token, but it works and I've never noted any performance issues.  You could do the same thing with semaphores, I just feel like it takes more work than making a minimum viable handler that locks with a global to call as a subroutine from your handler.

    That's just my experience, though, and your mileage may vary.

    ------------------------------
    Aaron Lael
    State of Utah - comments on this forum reflect my own personal opinions\observations and are separate from any entity I am otherwise involved in.
    ------------------------------



  • 3.  RE: Accumulators with Locks vs Structired Parameters with Semaphore Locks

    Posted 02-18-2022 15:57
    Thanks Aaron,

    Yeah, the problem I have is that I have about 250 of these counters (the actual number is variable - long story) and I only want to lock the one. This is why I can't use globals....

    Thanks for the insights into performance!

    ------------------------------
    Paul Simpson
    Senior Technical Instructor
    ------------------------------



  • 4.  RE: Accumulators with Locks vs Structired Parameters with Semaphore Locks

    Posted 02-21-2022 09:36
    We have a handler that starts a certain process on interactions in a queue based on logic in the handler, problem was that multiple events that would trigger the handler would happen very close to one another and we found ourselves in a situation where 2 instances of the handler would select the same interaction.

    We use the Semaphore Lock to resolve this, each instance of the handler will lock the selection process while going thru the selection logic, and unlock the process once done and the selected interaction is marked with a custom attribute, this has been working great for us.

    ------------------------------
    Eliezer Stekel
    ------------------------------



  • 5.  RE: Accumulators with Locks vs Structired Parameters with Semaphore Locks

    Posted 02-23-2022 13:12
    Thanks, Eliezer!

    I ended up going for Structured Parameters and Semaphore locks and that part seems to be working.

    ------------------------------
    Paul Simpson
    Senior Technical Instructor
    ------------------------------



  • 6.  RE: Accumulators with Locks vs Structired Parameters with Semaphore Locks

    GENESYS
    Posted 03-17-2022 14:30
    Accessing structured parameters from handlers is not a cheap operation and is not sustainable if its done as part of every call flow.

    Did you look at using IP tables for it.

    ------------------------------
    Rick Lyndon
    Staff Software Engineer - Team Lead
    ------------------------------