k3s-io / kine

Run Kubernetes on MySQL, Postgres, sqlite, dqlite, not etcd.
Apache License 2.0
1.56k stars 233 forks source link

Support pure go sqlite driver #140

Closed iyear closed 1 year ago

iyear commented 1 year ago

https://gitlab.com/cznic/sqlite is the sqlite driver that uses pure go. And it is constantly being updated, using the latest sqlite version.

Supported platforms and architectures: https://pkg.go.dev/modernc.org/sqlite#hdr-Supported_platforms_and_architectures

About Performance:

Related issue: https://gitlab.com/cznic/sqlite/-/issues/39

I also ran the benchmark with the latest code:

goos:   windows
goarch: amd64
cpu:    AMD Ryzen 5 5600G with Radeon Graphics
repeat: 1 time(s)
in-memory SQLite: false

bench_create_index                  |  2.05x | CGo:  89.092 ms/op | Pure-Go: 183.012 ms/op
bench_select_on_string_comparison   |  1.74x | CGo:  21.505 ms/op | Pure-Go:  37.510 ms/op
bench_select_with_index             |  5.36x | CGo:   0.002 ms/op | Pure-Go:   0.009 ms/op
bench_select_without_index          |  1.67x | CGo:   6.594 ms/op | Pure-Go:  11.013 ms/op
bench_insert                        |  1.02x | CGo:   0.576 ms/op | Pure-Go:   0.586 ms/op
bench_insert_in_transaction         |  1.71x | CGo:   0.003 ms/op | Pure-Go:   0.005 ms/op
bench_insert_into_indexed           |  1.20x | CGo:   0.013 ms/op | Pure-Go:   0.015 ms/op
bench_insert_from_select            |  1.75x | CGo:  22.710 ms/op | Pure-Go:  39.655 ms/op
bench_update_text_with_index        |  2.57x | CGo:   0.003 ms/op | Pure-Go:   0.008 ms/op
bench_update_with_index             |  3.41x | CGo:   0.002 ms/op | Pure-Go:   0.007 ms/op
bench_update_without_index          |  1.52x | CGo:   6.447 ms/op | Pure-Go:   9.789 ms/op
bench_delete_without_index          |  1.18x | CGo: 228.750 ms/op | Pure-Go: 270.940 ms/op
bench_delete_with_index             |  1.88x | CGo:  24.371 ms/op | Pure-Go:  45.886 ms/op

It's not as good as cgo sqlite driver, but I think most scenarios that are not performance sensitive. It's better than nothing.

For the CGO_ENABLED=0, I have compiled it locally and started it successfully, but did not do any further testing.

brandond commented 1 year ago

It's not as good as cgo sqlite driver, but I think most scenarios that are not performance sensitive. It's better than nothing.

The Kubernetes datastore is VERY performance sensitive. If it performs worse, and we still need to embed the sqlite C code itself in the binary, why would we use this?

Also, rather than adding support for a pure-go driver, this appears to be wholesale replacing the driver, which I don't think I would want to do unless there were clear benefits.

iyear commented 1 year ago

My mistake, I thought it was a TODO. Sorry :(

iyear commented 1 year ago

Also, rather than adding support for a pure-go driver, this appears to be wholesale replacing the driver, which I don't think I would want to do unless there were clear benefits.

Sorry, I didn't get this sentence. I didn't replace the original cgo sqlite, I just added the nocgo implementation.

This has no impact on the existing process or future packaging, it just adds an option.

kine can only provide the cgo version for performance, but developers can also choose a cross-compile friendly version for themselves.

It's not as good as cgo sqlite driver, but I think most scenarios that are not performance sensitive. It's better than nothing.

The scenario refers to the fact that the cluster using sqlite is usually not too large.

And the point of this sentence is that nocgo sqlite is better than a disabled error.

brandond commented 1 year ago

Are the release artifacts still built without cgo/sqlite support? If so that's unintentional. The docker image should support sqlite, as of https://github.com/k3s-io/kine/pull/69

iyear commented 1 year ago

Compile and package the same as before. Will this cause any problems?

brandond commented 1 year ago
brandond@dev01:~/kine$ curl -ksL -o kine https://github.com/k3s-io/kine/releases/download/v0.9.4/kine-amd64; chmod a+x kine; ./kine --debug
INFO[0000] metrics server is starting to listen at :8080
INFO[0000] starting metrics server path /metrics
INFO[0000] Configuring sqlite3 database connection pooling: maxIdleConns=2, maxOpenConns=0, connMaxLifetime=0s
INFO[0000] Configuring database table schema and indexes, this may take a moment...

seems to work fine. I think I'm still not understanding what problem you're trying to solve.

iyear commented 1 year ago

Just like https://github.com/pocketbase/pocketbase#running-and-building

Maybe this is not necessary for kine🤔

brandond commented 1 year ago

Use the docker image, use the release artifact, or use the build script if you want to compile it yourself

iyear commented 1 year ago

Get. Thanks.