Skip to content

Commit

Permalink
[PERFORMANCE] Address performance concerns regarding publishing updat…
Browse files Browse the repository at this point in the history
…es and system resources (#4575)

* minimal hierarchy, quell log worker creation, expose queue sizes

* streamline publication update processing, hide raw data export

* revert synchronous execution

* Auto format

---------

Co-authored-by: darrensiegel <darrensiegel@users.noreply.github.com>
  • Loading branch information
darrensiegel and darrensiegel authored Jan 19, 2024
1 parent e36009c commit 8d00688
Show file tree
Hide file tree
Showing 6 changed files with 470 additions and 254 deletions.
16 changes: 16 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,20 @@ if config_env() == :prod do

config :oli, :datashop,
cache_limit: String.to_integer(System.get_env("DATASHOP_CACHE_LIMIT", "200"))

config :oli, Oban,
repo: Oli.Repo,
plugins: [Oban.Plugins.Pruner],
queues: [
default: String.to_integer(System.get_env("OBAN_QUEUE_SIZE_DEFAULT", "10")),
snapshots: String.to_integer(System.get_env("OBAN_QUEUE_SIZE_SNAPSHOTS", "20")),
s3_uploader: String.to_integer(System.get_env("OBAN_QUEUE_SIZE_S3UPLOADER", "20")),
selections: String.to_integer(System.get_env("OBAN_QUEUE_SIZE_SELECTIONS", "20")),
updates: String.to_integer(System.get_env("OBAN_QUEUE_SIZE_UPDATES", "2")),
grades: String.to_integer(System.get_env("OBAN_QUEUE_SIZE_GRADES", "30")),
auto_submit: String.to_integer(System.get_env("OBAN_QUEUE_SIZE_AUTOSUBMIT", "3")),
analytics_export: String.to_integer(System.get_env("OBAN_QUEUE_SIZE_ANALYTICS", "1")),
datashop_export: String.to_integer(System.get_env("OBAN_QUEUE_SIZE_DATASHOP", "1")),
objectives: String.to_integer(System.get_env("OBAN_QUEUE_SIZE_OBJECTIVES", "3"))
]
end
73 changes: 38 additions & 35 deletions lib/oli/delivery/experiments/log_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,38 @@ defmodule Oli.Delivery.Experiments.LogWorker do

@impl Oban.Worker
def perform(%Oban.Job{
args: %{"activity_attempt_guid" => attempt_guid, "section_slug" => section_slug}
args: %{"activity_attempt_guid" => attempt_guid}
}) do
perform_now(attempt_guid, section_slug)
perform_now(attempt_guid)
end

def perform_now(attempt_guid, section_slug) do
# Fetch the section, fail fast if experiments are not enabled, we are done
case Oli.Delivery.Sections.get_section_by(slug: section_slug) do
%Oli.Delivery.Sections.Section{has_experiments: true} ->
{score, out_of, enrollment_id} =
from(aa in ActivityAttempt,
join: ra in ResourceAttempt,
on: aa.resource_attempt_id == ra.id,
join: a in ResourceAccess,
on: ra.resource_access_id == a.id,
join: e in Enrollment,
on: a.section_id == e.section_id and a.user_id == e.user_id,
where: aa.attempt_guid == ^attempt_guid,
select: {aa.score, aa.out_of, e.id}
)
|> Repo.one()
def perform_now(attempt_guid) do
{score, out_of, enrollment_id} =
from(aa in ActivityAttempt,
join: ra in ResourceAttempt,
on: aa.resource_attempt_id == ra.id,
join: a in ResourceAccess,
on: ra.resource_access_id == a.id,
join: e in Enrollment,
on: a.section_id == e.section_id and a.user_id == e.user_id,
where: aa.attempt_guid == ^attempt_guid,
select: {aa.score, aa.out_of, e.id}
)
|> Repo.one()

correctness =
case score do
0.0 ->
0.0
correctness =
case score do
0.0 ->
0.0

s ->
case out_of do
0.0 -> 0.0
o -> s / o
end
s ->
case out_of do
0.0 -> 0.0
o -> s / o
end
end

Oli.Delivery.Experiments.log(enrollment_id, correctness)

_ ->
{:ok, :nothing_to_do}
end
Oli.Delivery.Experiments.log(enrollment_id, correctness)
end

@doc """
Expand All @@ -67,9 +60,19 @@ defmodule Oli.Delivery.Experiments.LogWorker do
def maybe_schedule(result, activity_attempt_guid, section_slug) do
case Oli.Delivery.Experiments.experiments_enabled?() do
true ->
%{activity_attempt_guid: activity_attempt_guid, section_slug: section_slug}
|> Oli.Delivery.Experiments.LogWorker.new()
|> Oban.insert()
case from(s in Oli.Delivery.Sections.Section,
where: s.slug == ^section_slug,
select: s.has_experiments
)
|> Repo.one() do
true ->
%{activity_attempt_guid: activity_attempt_guid}
|> Oli.Delivery.Experiments.LogWorker.new()
|> Oban.insert()

_ ->
true
end

_ ->
true
Expand Down
12 changes: 12 additions & 0 deletions lib/oli/delivery/previous_next_index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,16 @@ defmodule Oli.Delivery.PreviousNextIndex do
{:error, e} -> e
end
end

def rebuild(%Section{} = section, hierarchy) do
case Repo.transaction(fn _ ->
Hierarchy.build_navigation_link_map(hierarchy)
|> then(fn previous_next_index ->
Sections.update_section(section, %{previous_next_index: previous_next_index})
end)
end) do
{:ok, result} -> result
{:error, e} -> e
end
end
end
Loading

0 comments on commit 8d00688

Please sign in to comment.