feat(state,parse): Perform partial updates on StopEvent - #1065
feat(state,parse): Perform partial updates on StopEvent#1065runkelcorey wants to merge 5 commits into
StopEvent#1065Conversation
| # Get the maximum timestamp from existing data in the table. | ||
| # Uses a dynamic match spec based on the StopEvent struct to avoid brittleness | ||
| # from hardcoded field positions. |
There was a problem hiding this comment.
nitpick: could make this a @doc block instead of just a comment.
| # Parse with timestamp filtering if we have existing data | ||
| opts = if max_timestamp, do: [newer_than: max_timestamp], else: [] | ||
|
|
||
| parser = Parse.StopEvents |
There was a problem hiding this comment.
nitpick: this is only used in one place and doesn't have any possible value other than Parse.StopEvents and not any test module or anything - could the variable be removed?
| # log_parse_error returns nil, so we return nil on error to avoid passing | ||
| # invalid data to super/1. State.Server expects nil to mean | ||
| # "no data to insert" and will handle it gracefully. |
There was a problem hiding this comment.
question: I'm kind of confused by this comment because we don't actually pass nil to super below because we intercept it in the case statement and pass :ok instead.
|
|
||
| __MODULE__ | ||
| |> :mnesia.dirty_select(match_spec) | ||
| |> Enum.each(&:mnesia.dirty_delete(__MODULE__, &1)) |
There was a problem hiding this comment.
question: could anything weird possibly happen because of using dirty_delete here instead of deleting in a transaction? Could we have an API query return some of the StopEvents that are to be deleted but not others?
Co-authored-by: Eddie Maldonado <eddie@lemald.org>
Asana Ticket: 🐞 State.StopEvent times out on refresh
What changes does this PR propose?
Changes refresh strategy for
StopEventfrom a full load to an incremental update by:handle_new_statecallback that filters incoming stop event JSONs for records that are newer than a configurable timestamp (defaulting to 2 hours, the same that Flashback aims for)post_commit_hookcallback that evicts records from the mnesia table if they are older than the configurable timestampSince
StopEventis a:settable, incoming values with the same keys will overwrite existing values.How were these changes validated?
State.StopEventandParse.StopEventthat different cases of partial updatesdev-blueanddev-green(which is running the current, full-load strategy):dev-greendev-blueThese are crazy improvements so I feel like I'm missing a logging statement to capture the full overhead of the partial load. However, we should expect something like this: of the 116,740 events in the stop events dataset I downloaded yesterday, only 356 (0.3%) were updated or inserted the last 30 seconds of the dataset.
As a sanity check, I also counted the number of times each of these function were executed: since this is an event loop dictated by the time it takes to refresh data + sleep time, the more times something is invoked can indicate performance impacts.
dev-bluecompleted 1,059 refreshes ofStopEventin 30 minutes, which translates to once per 1.7s, whiledev-greencompleted 432 refreshes in the same time period, a rate of one refresh every 4s.Performance-wise, these changes seem very impactful.
What questions should reviewers consider?
timestampbe a datetime or is it ok to have as a Unix timestamp?