Open myoss opened 2 hours ago
@myoss Hello! I'm here to help you with any bugs, questions, or contributions. Let's work together to solve this issue.
I found a similar closed issue that might be relevant to your problem: Fork Join Parallelism for Workflows. This issue was last updated on September 04, 2024, and it references other related issues like batched data, need multiple branch supported, and Feature Request: Add "Parallel" Execution Capability to the LLM Module. The suggested solution can be found in the 0.8.0-beta1 release notes [1].
To optimize the workflow execution time for if/else logic in your self-hosted Dify version 0.8.2 environment using Docker, consider the following strategies:
IfElseNode
configuration to reduce computational overhead.Here is an example of how you might refactor the IfElseNode
configuration to reduce the number of conditions:
node = IfElseNode(
id=str(uuid.uuid4()),
graph_init_params=init_params,
graph=graph,
graph_runtime_state=GraphRuntimeState(variable_pool=pool, start_at=time.perf_counter()),
config={
"id": "if-else",
"data": {
"title": "123",
"type": "if-else",
"logical_operator": "and",
"conditions": [
{
"comparison_operator": "contains",
"variable_selector": ["start", "array_contains"],
"value": "ab",
},
{
"comparison_operator": "not contains",
"variable_selector": ["start", "array_not_contains"],
"value": "ab",
},
# Remove or combine other conditions as needed
],
},
},
)
Additionally, ensure efficient variable management:
# Optimize variable pool initialization
pool = VariablePool(
system_variables={SystemVariableKey.FILES: [], SystemVariableKey.USER_ID: "aaa"},
user_inputs={}
)
pool.add(["start", "array_contains"], ["ab", "def"])
pool.add(["start", "array_not_contains"], ["ac", "def"])
# Add only necessary variables
For more complex logic, consider using the code node:
def main(variable1: list, variable2: list) -> dict:
# Custom logic to replace complex if/else conditions
result = some_complex_logic(variable1, variable2)
return {
'result': result
}
By reducing the complexity of the conditions, ensuring efficient variable management, and leveraging the code node for complex logic, you can potentially reduce the execution time of the if/else logic.
To continue talking to Dosu, mention @dosu.
This does not involve complex conditional checks; it simply checks whether the input parameter string is equal to a specific value.
Self Checks
Dify version
0.8.2
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
I am currently experiencing slow execution in my workflow, where the if/else logic takes 60 milliseconds to execute. What are some good suggestions to reduce this time? Or are there any directions for troubleshooting the issue?
✔️ Expected Behavior
No response
❌ Actual Behavior
No response