jina-ai / jina

☁️ Build multimodal AI applications with cloud-native stack
https://docs.jina.ai
Apache License 2.0
21k stars 2.22k forks source link

Engine consumes a large amount of Memory. What methods can be used to optimize memory usage? #6168

Closed Janus-Xu closed 1 month ago

Janus-Xu commented 4 months ago

jina ver: 3.25.1 latest

When using an empty example to observe the idle memory usage without adding any executor, the situation is as follows:

flow.py

from jina import Flow

f = Flow()

with f:
    f.block()

In the x86 environment:

python(16985)───python(17051)─┬─{default-executo}(17054)
                              ├─{event_engine}(17058)
                              ├─{event_engine}(17059)
                              ├─{event_engine}(17060)
                              ├─{event_engine}(17061)
                              ├─{event_engine}(17077)
                              ├─{event_engine}(17080)
                              ├─{grpc_global_tim}(17056)
                              ├─{python}(17057)
                              ├─{resolver-execut}(17055)
                              └─{timer_manager}(17081)

PID 16985 occupies 80M, PID 17051 occupies 66M.

In the ARM environment:

python(3740)───python(8001)─┬─{python}(8014)
                            ├─{python}(8015)
                            ├─{python}(8016)
                            ├─{python}(8017)
                            ├─{python}(8020)
                            ├─{python}(8021)
                            ├─{python}(8022)
                            ├─{python}(8023)
                            ├─{python}(8024)
                            ├─{python}(8025)
                            └─{python}(8026)

PID 3740 occupies 308M, PID 8001 occupies 214M.

The executor is designed as multiple processes, We have also tested the memory usage of each process is around 250M-350M. In this way, when all processes are combined in a flow, it is easy to exceed 3-4G.

There is no mention of memory in the entire documentation. Is there any solution to this problem?

JoanFM commented 4 months ago

what is the Executor you are using?

Janus-Xu commented 4 months ago

what is the Executor you are using?

just some business logic processing. like data format, calling external APIs, saving results to a database, etc. and I forgot to attach flow.py. The original question has been updated. the statistics do not include the executors, only the engine itself.

JoanFM commented 4 months ago

The same Flow structure with empty executors, what consumption does it have?

Janus-Xu commented 4 months ago

The same Flow structure with empty executors, what consumption does it have?

no consumers. We initially thought it was the executors usage problem, so we removed all the other configurations and tried to find the problem using elimination.

The ARM environment is a Nvidia Jetson box, and we also confused why there is such a difference just by changing the hardware. The box only has 16GB of memory, we originally expected it to support dozens of flows.

JoanFM commented 4 months ago

I am not sure why the memory usage is different in both? Maybe some forking differences between both architectures, or some dpeendency using more in one or the other

Janus-Xu commented 4 months ago

I am not sure why the memory usage is different in both? Maybe some forking differences between both architectures, or some dpeendency using more in one or the other

disregarding the issue with the ARM terminal, on our standard x86 server, the total memory usage we observed during idle testing was around 150MB. Is this memory usage consistent with the testing conducted by your team? We were hoping for a lighter footprint, ideally under 20MB.

JoanFM commented 4 months ago

yes, can be. I think most of it comes from the importing of docarray and the forking copying memory

jina-bot commented 1 month ago

@jina-ai/product This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 14 days