分享一个使用golang实现的数据库

栏目: IT技术 · 发布时间: 4年前

内容简介:KV store

dkv

A Log-Structured Hash Table for Fast Key/Value Data

分享一个使用golang实现的数据库 分享一个使用golang实现的数据库

分享一个使用golang实现的数据库

  • low latency per item read or written
  • high throughput, especially when writing an incoming stream of random items
  • ability to handle datasets much larger than RAM w/o degradation
  • crash friendliness, both in terms of fast recovery and not losing data
  • ease of backup and restore
  • a relatively simple, understandable (and thus supportable) code structure and data format • predictable behavior under heavy access load or large volume

Install

By default, the golang environment has been installed.
first:
git clone https://github.com/xincao9/dkv.git
cd ./dkv
sudo make install
Execute: dkv -d=true -conf=config-prod.yaml

Bin directory: cd /usr/local/dkv/bin/
Configuration directory: cd /usr/local/dkv/conf/
Data directory: cd /usr/local/dkv/data/
Logger directory: cd /usr/local/dkv/log/

second:
docker pull xincao9/dkv
docker run -d -p 9090:9090 -p 6380:6380 dkv:latest

Configuration file

config.yaml Placed in the current working directory or /etc/dkv/ or $HOME/.dkv or /usr/local/dkv
data:
    dir: /usr/local/dkv/data
    invalidIndex: false
    cache:
        open: true
        size: 1073741824
    compress:
        open: false
server:
    mode: release
    port: 9090
    sequence: true
    redis:
        port: 6380
logger:
    level: info
    dir: /usr/local/dkv/log
ms:
    role: 0

HTTP interface

KV store

Add or modify
curl -X PUT -H 'content-type:application/json' 'http://localhost:9090/kv' -d '{"k":"name", "v":"xincao9"}'
Search
curl -X GET 'http://localhost:9090/kv/name'
delete
curl -X DELETE 'http://localhost:9090/kv/name'
OSS (Object Storage Service)
Upload file, file max size 64M
curl -X POST 'http://localhost:9090/oss' -F "file[]=@config.yaml" -H 'content-type:multipart/form-data'
Fetch file
curl -X GET 'http://localhost:9090/oss/116a71ebd837470652f063028127c5cd'

Redis command

  • SET key value
  • GET key
  • DEL key
  • PING
go get github.com/go-redis/redis
client := redis.NewClient(&redis.Options{
    Addr:     "localhost:6380",
    Password: "", // no password set
    DB:       0,  // use default DB
})
err := client.Set("name", "xincao9", 0).Err()
if err != nil {
    log.Println(err)
}
val, err := client.Get("name").Result()
if err != nil {
    log.Println(err)
}
log.Println(val)

GO SDK

go get github.com/xincao9/dkv/client
c, err := client.New("localhost:9090", time.Second)
if err != nil {
    log.Fatalln(err)
}
r, err := c.Put("name", "xincao9")
if err == nil {
    log.Println(r)
}
r, err = c.Get("name")
if err == nil {
    log.Println(r)
}

Management interface

View runtime configuration
curl -X GET 'http://localhost:9090/config'
Prometheus indicator
curl -X GET 'http://localhost:9090/metrics'
Pprof interface
curl -X GET 'http://localhost:9090/debug/pprof'

Grafana dashboard resources

prometheus.json

Pressure test

Execute benchmark/start.sh

Reference


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

零基础学PHP

零基础学PHP

马忠超 / 2008-3 / 56.00元

《零基础学PHP》主要内容:PHP是一种运行于服务器端并完全跨平台的嵌入式脚本编程语言,是目前开发各类Web应用的主流语言之一。PHP因其功能强大、易学易用、可扩展性强、运行速度快和良好的开放性,而成为网站开发者的首选工具,其较高的开发效率,也给开发人员在编写Web应用程序时带来极大的便利。一起来看看 《零基础学PHP》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试