yjs / y-websocket

Websocket Connector for Yjs
https://docs.yjs.dev/ecosystem/connection-provider/y-websocket
MIT License
526 stars 263 forks source link

the new heap suddenly increase #163

Open jiangxiaoqiang opened 11 months ago

jiangxiaoqiang commented 11 months ago

Describe the bug

the y-websocket always restart automatically(I am deployment this application in kubernetes pod), I am using the grafana to monitor the y-websocket memory, now I found the momory are increase suddenly and there is no new connection to y-websoket. My document is small(less than 1MB).

image

Expected behavior

The momory could back to normal.

Screenshots

image

Environment Information

I tried to dump the memory and found there have 50000+ map take 68% memory like this:

image

this is the level db file size:

[root@k8smasterone yjs-storage]# pwd
/data/k8s/reddwarf-pro/texhub-server-service/yjs-storage
[root@k8smasterone yjs-storage]# ls -alh
total 13M
drwxr-xr-x 2 root root 4.0K Nov 28 22:13 .
drwxr-xr-x 9 root root 4.0K Oct 18 22:54 ..
-rw-r--r-- 1 root root  450 Nov 28 22:16 001891.log
-rw-r--r-- 1 root root 5.3M Nov 28 22:13 001893.ldb
-rw-r--r-- 1 root root 3.3M Nov 28 22:13 001894.ldb
-rw-r--r-- 1 root root 3.3M Nov 28 22:13 001895.ldb
-rw-r--r-- 1 root root 780K Nov 28 22:13 001896.ldb
-rw-r--r-- 1 root root   16 Nov 28 22:03 CURRENT
-rw-r--r-- 1 root root    0 Sep 12 16:08 LOCK
-rw-r--r-- 1 root root 1.6K Nov 28 22:13 LOG
-rw-r--r-- 1 root root 1.7K Nov 28 20:32 LOG.old
-rw-r--r-- 1 root root 1.6K Nov 28 22:13 MANIFEST-001889

I have tried to diff the dump, somewhere map in the y-websocket did not release. this issue was look like the same with https://github.com/yjs/y-websocket/issues/145

dmonad commented 11 months ago

The y-websocket server keeps all documents around forever, unless you specify a persistence provider (like y-leveldb). Is that what's happening?

jiangxiaoqiang commented 11 months ago

The y-websocket server keeps all documents around forever, unless you specify a persistence provider (like y-leveldb). Is that what's happening?

I have already specify the leveldb and I also checked the level db only have 5MB. load the full db may not take so much memory.

jiangxiaoqiang commented 11 months ago

the destroy function are just create a new map? I am confused with this:

if (doc.conns.size === 0 && persistence !== null) {
      // if persisted, we store state and destroy ydocument
      persistence.writeState(doc.name, doc).then(() => {
        doc.destroy()
      })
      docs.delete(doc.name)
    }

this is the destroy implement:

destroy () {
    this._observers = map.create()
  }