Skip to content

docs: add ADR 0003 for the content search reindex - #39464

Open
dwong2708 wants to merge 3 commits into
masterfrom
improve-reindexing
Open

dwong2708 wants to merge 3 commits into
masterfrom
improve-reindexing

Conversation

@dwong2708

@dwong2708 dwong2708 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Resolves: #39463

Description

Adds ADR 0003, openedx/core/djangoapps/content/search/docs/decisions/0003-bounded-in-flight-reindex-tasks.rst. It records why a full ./manage.py cms reindex_studio is slow and proposes how to speed it up. This PR changes documentation only. No code, settings, or migrations change.

Problem. rebuild_index() indexes courses one at a time. After each course it calls _wait_for_meili_task(), which blocks until Meilisearch finishes that course's task. Only then does it create the IncrementalIndexCompleted row. On a large instance (1,698 courses, 5 libraries, 599,934 blocks) a real run took 13,002 s (3 h 37 min). About 59% of that time (about 5.3 s per non-empty course) was spent waiting, not building documents.

What the ADR proposes (status: Draft).

  • Option A (recommended, implement first): keep at most N unconfirmed Meilisearch tasks in memory. Wait for the oldest task when the window is full, and create its IncrementalIndexCompleted row only after the task succeeded. This needs no migration, and a row still means "confirmed indexed". N should be configurable, and the default is to be chosen with the maintainers.
  • Option B (possible follow-up): persist task status and task_uid on IncrementalIndexCompleted. This needs a migration.
  • Other options considered: waiting once at the end (rejected, because it leaves silent gaps on resume), batching several courses per add_documents call, concurrent document building, per-course tag batching, and bulk_operations around get_course.

Measurements on one instance (prototypes, not part of this PR):

Run Time Versus real run
Real reindex_studio (wait per course) 13,002 s 1.0x
Option A, window of 20 5,273 s 2.5x faster
Option A + per-course tag prefetch 2,574 s 5.1x faster

No task failed in any run. The tag prefetch result came from an instance with no tagged content, so it shows the speedup but not correctness. The ADR lists this caveat and says to verify on tagged content before relying on it.

Who is affected.

  • Operator and Developer: this is a design record for a future change to the reindex job. Nothing changes in behavior yet.
  • Learner and Course Author: not affected.

No screenshots or configuration changes. The ADR says the window size should be configurable, but no setting is added here, so there is nothing to annotate.

Supporting information

Deadline

None

Other information

  • Limitations stated in the ADR: failure and crash-resume paths were exercised only by unit tests of the prototype,
    not by a run on the instance. Measurements come from a single instance and a single run each, so differences of
    a few percent are noise.
  • No migrations, deprecations, security, or accessibility impact. Rolling back means reverting one file.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Nov 30, 2026
@openedx-webhooks

openedx-webhooks commented Nov 30, 2026 •

Copy link
Copy Markdown

Thanks for the pull request, @dwong2708!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform-oncall.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

Record a full reindex run with option A plus per-course tag prefetch
on the same instance (1,688 courses, 599,897 blocks).

Total time went from 5,273 s to 2,574 s, which is 5.1 times faster
than the original run (13,002 s). Tag time dropped from 2,715 s to
19 s. The old cost was one tag lookup per block (about 4.5 ms each),
and all of them returned nothing because the instance has no tags.

Document building is now 88% of the remaining time.

The instance has no tagged content, so correctness with tags is not
verified (blocks_with_tags=0, verified=False). Add this caveat to the
Consequences section and to the tag batching entry in Other options.
@dwong2708
dwong2708 marked this pull request as ready for review December 1, 2026 22:04
@dwong2708 dwong2708 assigned ormsbee and unassigned ormsbee Dec 1, 2026
@dwong2708
dwong2708 requested a review from ormsbee December 1, 2026 22:13
@dwong2708 dwong2708 self-assigned this Dec 1, 2026
@ormsbee

ormsbee commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@rpenido, @blarghmatey: Wanted to make sure you folks also saw this, as it's search-related.

@rpenido

rpenido commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Hi @dwong2708! Thanks for the ADR!

We are currently working on search across the platform, creating an api that abstracts the search engine: https://github.com/openedx/openedx-search/

You can check https://github.com/openedx/openedx-search/tree/main/docs/decisions to see what we are planning.

We haven't implemented the rebuild path yet, but we plan to have the library handle it. So, on the openedx-platform content/search side, it should look like:

def course_documents():
    for course in courses:
        yield build_documents(course)

def library_documents():
    for library in libraries:
        yield component_documents(library)
        for page in collection_pages(library):
            yield collection_documents(page)
        for page in container_pages(library):
            yield container_documents(page)

search_api.rebuild(
    "studio_content",
    course_documents,
)

search_api.rebuild(
    "studio_library_content",
    library_documents,
)

After thinking on your ADR here, I think the rebuild should look like this:

# openedx_search/api.py (sketch)

MAX_IN_FLIGHT = 20
POLL_INTERVAL = 0.2


def rebuild(use_case, document_source):
    # ... resolve the registration and adapter, mint the target,
    # take the rebuild lease, begin_rebuild(target) ...

    pending = []               # WriteReceipt, in submission order
    indexed = 0

    def check_all():
        # One poll for the whole window. check_writes checks every receipt and
        # raises WriteFailed if any task failed or was canceled.
        updated = adapter.check_writes(pending)
        pending[:] = [receipt for receipt in updated if not receipt.complete]

    for documents in document_source():
        if not documents:
            continue
        # Hand the batch off; no wait here while the window has room.
        pending.append(adapter.upsert(documents, target=target))
        indexed += len(documents)

        while len(pending) >= MAX_IN_FLIGHT:
            # ... refresh the lease ...
            check_all()
            if len(pending) >= MAX_IN_FLIGHT:
                time.sleep(POLL_INTERVAL)   # check_writes never sleeps; the worker does

    while pending:          # drain the last tasks before the swap
        # ... refresh the lease ...
        check_all()
        if pending:
            time.sleep(POLL_INTERVAL)

    # ... commit_rebuild(target) on success, abort_rebuild(target) on failure ...
    return RebuildResult(target=target, documents=indexed)

So, the context in this ADR would probably be transferred to openedx-search.
Could we move this discussion there? The issue is openedx/openedx-search#16

Also, we are not planning an incremental rebuild.
Could you share the context in which you need to rebuild your index?

content, so it does not show correctness or timing when tags exist. Create
tags in a test course and compare the prefetch path with the per-block path
before relying on it.
* Library collection and container indexing in ``rebuild_index()`` can use the

@rpenido rpenido Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
Note that currently, we are doing the "oposite": we take a list for collections and containers, put it in batches and create a task for each batch, increasing the wait time.

@mphilbrick211 mphilbrick211 moved this from Needs Triage to In Eng Review in Contributions Dec 2, 2026
@ormsbee
ormsbee removed their request for review December 2, 2026 23:19

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: In Eng Review

Development

Successfully merging this pull request may close these issues.

Full Studio reindex waits for Meilisearch after every course (about 59% of runtime)

4 participants