Skip to content
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

pref: Optimize the memory usage of SortedSet #560

Open
GitUserHk opened this issue Dec 20, 2023 · 5 comments
Open

pref: Optimize the memory usage of SortedSet #560

GitUserHk opened this issue Dec 20, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@GitUserHk
Copy link

GitUserHk commented Dec 20, 2023

版本:github.com/nutsdb/nutsdb v0.14.3

本地数据(100000000条数据,)2.2G database
image

@GitUserHk GitUserHk changed the title 服务重启,从本地磁盘恢复数据,程序被Killed 服务重启,从本地磁盘恢复数据,程序被Killed Dec 20, 2023
@xujiajun
Copy link
Member

hi 怎么复现 你的问题呢?有没有代码啥的之类的。。

@GitUserHk
Copy link
Author

GitUserHk commented Dec 21, 2023

阿里云ecs:8核16G

  1. 首次运行,写入100000000条数据,耗时大概一晚(产生数据文件9个)
  2. 二次运行,磁盘恢复数据中被killed(加载到第8个数据文件程序被killed)
package main
import (
	"fmt"
	"github.com/nutsdb/nutsdb"
	"strconv"
	"time"
)

func main() {
	st := time.Now().UnixMilli()
	db, err := nutsdb.Open(
		nutsdb.DefaultOptions,
		nutsdb.WithDir("./database/nutsdb"),
	)
	if err != nil {
		panic(err)
	}
	et := time.Now().UnixMilli()
	fmt.Printf("init speed time:%v\n", et-st)
	defer db.Close()

	limit := 100000
	loop := 1000
	for i := 0; i < limit; i++ {
		key := "test:" + strconv.FormatUint(uint64(i), 10)
		score := time.Now().UnixMilli()

		for j := 0; j < loop; j++ {
			mid := strconv.FormatUint(uint64(j), 10)
			err = db.Update(
				func(tx *nutsdb.Tx) error {
					return tx.ZAdd("test", []byte(key), float64(score), []byte(mid))
				})
		}
	}
}

image
image
image

@bigboss2063
Copy link
Member

判断是SkipList的实现内存开销太大,@TremblingV5 正在尝试优化,现在要使用的话建议先更新到最新版本,对内存有优化,然后可以使用HintKeyAndRAMIdxMode模式开启nutsdb,应该是暂时够用的。

@bigboss2063 bigboss2063 added the enhancement New feature or request label Dec 26, 2023
@TremblingV5
Copy link
Contributor

判断是SkipList的实现内存开销太大,@TremblingV5 正在尝试优化,现在要使用的话建议先更新到最新版本,对内存有优化,然后可以使用HintKeyAndRAMIdxMode模式开启nutsdb,应该是暂时够用的。

另外分享下我自己的验证,我使用@GitUserHk 提供的代码在一台2C2G的服务器(只有这种配置了😭)测试

插入大概330万条数据后,进程被kill。通过dmesg命令,确认是OOM。

@bigboss2063 bigboss2063 changed the title 服务重启,从本地磁盘恢复数据,程序被Killed pref: Optimize the memory usage of SortedSet Dec 27, 2023
@jianzhiyao
Copy link

skiplist is designed for RAM,maybe b+tree is better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants