Skip to content

feat: add in-memory repo to improve workflow performance #20050

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

xinlmain
Copy link

@xinlmain xinlmain commented May 21, 2025

Summary

Addresses #20147
See also #10982, See also #19325

The default workflow-run api is very slow on simple tasks, making it unacceptable for real time interactions. The api calls spend most of the time interacting with DB. In a scenario where the api is called by another service, there is not much sense to save each call into DB.
image

So here I added a fast mode for workflow api, it can be turned on by setting WORKFLOW_NODE_EXECUTION_REPO_MODE=memory. This enables deploying a dedicated api service for external api calls, with the tradeoff of not able to see execution detail in application logs from the web page.

Checklist

Important

Please review the checklist below before submitting your pull request.

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. 🌊 feat:workflow Workflow related stuff. 📚 documentation Improvements or additions to documentation labels May 21, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces an in-memory repository mode to improve workflow API performance by avoiding unnecessary database interactions. Key changes include:

  • Adding a new environment variable WORKFLOW_NODE_EXECUTION_REPO_MODE and its documentation.
  • Implementing an in-memory workflow node execution repository and integrating it via a new repository factory.
  • Updating application configuration and app generator code to use the new repository factory.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
docker/docker-compose.yaml Adds WORKFLOW_NODE_EXECUTION_REPO_MODE environment variable with default sql.
docker/.env.example Updates the environment file with the new repository mode option.
api/core/workflow/repository/workflow_node_execution_repository.py Introduces the ExecRepoMode enum for repository mode selection.
api/core/repositories/workflow_node_execution_factory.py Implements a factory to choose between SQL and in-memory repository modes.
api/core/repositories/in_memory_workflow_node_execution_repository.py Provides the in-memory repository implementation for execution records.
api/core/repositories/init.py Exports the new in-memory repository.
api/core/app/apps/workflow/app_generator.py Refactors to use the repository factory instead of directly instantiating SQL.
api/configs/feature/init.py Adds new configuration field for repository mode.
api/.env.example Updates the environment file with the new repository mode setting.

@laipz8200 laipz8200 self-requested a review May 21, 2025 14:30
@laipz8200
Copy link
Member

Great PR! However, the two issues(PRs) you’ve referenced are not currently open. Could you please create a proposal for this implementation? We’d like to discuss some implementation details there. You can refer to issue #19429 for guidance.

@xinlmain
Copy link
Author

Great PR! However, the two issues(PRs) you’ve referenced are not currently open. Could you please create a proposal for this implementation? We’d like to discuss some implementation details there. You can refer to issue #19429 for guidance.

@laipz8200 Thanks, I have created this one #20147

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 documentation Improvements or additions to documentation 🌊 feat:workflow Workflow related stuff. size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants