Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing with-activity-counter for percentage; variable inc/dec #61

Open
loeschzwerg opened this issue Mar 12, 2024 · 0 comments
Open

Missing with-activity-counter for percentage; variable inc/dec #61

loeschzwerg opened this issue Mar 12, 2024 · 0 comments

Comments

@loeschzwerg
Copy link

loeschzwerg commented Mar 12, 2024

My use-case is rather straight forward, but I think it is generalizable, so I keep it that way.
In a request-response scenario, I have a max amount of tokens. So I have a range of e.g. 0-10. For my dashboard I have the requirement to show the saturation of this piece of software, which is best represented using a percentage. I would like to use iapetos for that. However, iapetos currently only provides the with-activity-counter to achieve saturation representation. While observe had to be used customly for percentage calculation

As my suggestion would also add value to the library, I decided to put up an issue.

Alternatives I considered:

  • Implement myself - I could do that, but I think this is something other people would also benefit from.
  • While I could measure the activity using the with-activity-counter, I would still need to cross-reference that by the number of threads I provide. This is variable, so I would need to publish another metric. Infeasible.
  • Change the requirement - nah... Percentage is an intuitive metric, which doesn't change the meaning when scaling horizontally. On startup, I can acquire the (0, max) directly, while to get it from another source would be overly tedious.

I have 2 possible solutions:

  • Extend inc/dec to allow variable
  • Add only the with-saturation-percentage wrapper

Suggestion for a discussible implementation:

;; with inc/dec modifications
(defmacro with-saturation-percentage
  [collector max-count & body]
  `(let [c#       ~collector
           steps# (/ max-count 100)]
     (inc c# steps#)
     (try
       (do ~@body)
       (finally
         (dec c# steps#)))))

;; in-situ implementation
(defmacro with-saturation-percentage
  [collector max-count & body]
  `(let [c# ~collector
         cnt# (atom 0)]
     (observe c# (/ (swap! cnt# inc) max-count))
     (try
       (do ~@body)
       (finally
         (observe c# (/ (swap! cnt# dec) max-count))))))

I find the in-situ implementation not that great, as it would introduce possibly a lot of single-use atoms.
I also thought about calculation on (value c#), but I think that would not be thread safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant