Home Database Mysql Tutorial SSDB:一个高性能的支持丰富数据结构的 NoSQL 数据库, 用于替代

SSDB:一个高性能的支持丰富数据结构的 NoSQL 数据库, 用于替代

Jun 07, 2016 pm 03:23 PM
nosql support number data structure high performance

http://ssdb.io/zh_cn/ SSDB是一个开源的高性能数据库服务器, 使用Google LevelDB作为存储引擎, 支持T级别的数据, 同时支持类似Redis中的zset和hash等数据结构, 在同时需求高性能和大数据的条件下, 作为Redis的替代方案. 因为SSDB的最初目的是替代Redis, 所

http://ssdb.io/zh_cn/


SSDB是一个开源的高性能数据库服务器, 使用Google LevelDB作为存储引擎, 支持T级别的数据, 同时支持类似Redis中的zset和hash等数据结构, 在同时需求高性能和大数据的条件下, 作为Redis的替代方案.

因为SSDB的最初目的是替代Redis, 所以SSDB会经常和Redis进行比较. 我们知道, Redis是经常的”主-从”架构, 虽然可以得到负载均衡以及数据跨地域备份的功能, 但无法实现高可用性. 考虑这种情况, Redis的主和从分别在两个IDC机房, 当主所在的机房出现故障时, 整个服务其实就相当于停止了. 因为所有写操作都失败, 而应用一般不会实现自动降级服务.

而SSDB支持”双主”架构(SSDB分布式架构: https://github.com/ideawu/ssdb/wiki/Replication), 两个或者更多的主服务器. 当其中一部分出现故障时, 剩余的主服务器仍然能正常接受写请求, 从而保证服务正常可用, 再将DNS解析修改之后, 就能在机房故障后立即恢复100%可用.

SSDB 被开发和开源出来后, 已经在生产环境经受了3个季度的考验,SSDB最先在”IT牛人博客聚合网站“进行尝试应用, 接着在360游戏部门得到大规模应用, 目前支撑的数据量已经达到数百G. 这些应用最初是使用Redis的, 迁移到SSDB的成本非常低, 涉及的代码改动极小.

SSDB开源数据库项目地址: https://github.com/ideawu/ssdb

作者博客地址: http://www.ideawu.net/blog/ssdb

安装

SSDB 的建议安装?方式是源码编译安装, 建议运?行环境是主流 Linux 发?行版. 远程 SSH 登录你的服务器, 然后?用下?面的命令下载, 编译, 安装和运?行:

$ sudo wget --no-check-certificate https://github.com/ideawu/ssdb/archive/master.zip

$ sudo unzip master

$ cd ssdb-master

$ sudo make

$ #optional, install ssdb in /usr/local/ssdb

$ sudo make install

# start master

$ sudo ./ssdb-server ssdb.conf

# or start as daemon

$ sudo ./ssdb-server -d ssdb.conf

# ssdb command line

$ sudo ./ssdb-cli -p 8888

# stop ssdb-server

$ sudo kill `cat ./var/ssdb.pid`

SSDB 默认安装在 /usr/local/ssdb ??目录下. ssdb-server 是服务器的程序, ssdb-cli 是命令?行客户端.

SSDB配置文件【http://www.ideawu.net/blog/archives/733.html】

SSDB  附带的 ssdb.conf 你不用修改便可以使用. 如果你要高度定制, 还是需要修改一些配置的. 下面做介绍. SSDB 的配置文件是一种层级 key-value 的静态配置文件, 通过一个 TAB 缩进来表示层级关系. 以 ‘#’ 号开始的行是注释. 标准的配置文件如下:

# ssdb-server config 
# MUST indent by TAB!

# relative to path of this file, directory must exists 
work_dir = ./var 
pidfile = ./var/ssdb.pid

server: 
        ip: 127.0.0.1 
        port: 8888 
        # bind to public ip 
        #ip: 0.0.0.0 
        # format: allow|deny: all|ip_prefix 
        # multiple allows or denys is supported 
        #deny: all 
        #allow: 127.0.0.1 
        #allow: 192.168

replication: 
        slaveof: 
                # to identify a master even if it moved(ip, port changed) 
                # if set to empty or not defined, ip:port will be used. 
                #id: svc_2 
                # sync|mirror, default is sync 
                #type: sync 
                #ip: 127.0.0.1 
                #port: 8889

logger: 
        level: info 
        output: log.txt 
        rotate: 
                size: 1000000000

leveldb: 
        # in MB 
        cache_size: 500 
        # in KB 
        block_size: 32 
        # in MB 
        write_buffer_size: 64 
        # in MB 
        compaction_speed: 1000 
        # yes|no 
        compression: no

work_dir: ssdb-server 的工作目录, 启动后, 会在这个目录下生成 data 和 meta 两个目录, 用来保存 LevelDB 的数据库文件. 这个目录是相对于 ssdb.conf 的相对路径, 也可以指定绝对路径.

server: ip 和 port 指定了服务器要监听的 IP 和端口号. 如果 ip 是 0.0.0.0, 则表示绑定所有的 IP. 基于安全考虑, 可以将 ip 设置为 127.0.0.1, 这样, 只有本机可以访问了. 如果要做更严格的更多的网络安全限制, 就需要依赖操作系统的 iptables.

replication: 用于指定主从同步复制. slaveof.ip, slaveof.port 表示, 本台 SSDB 服务器将从这个目标机上同步数据(也即这个配置文件对应的服务器是 slave). 你可以参考 ssdb_slave.conf 的配制.

logger: 配置日志记录. level 是日志的级别, 可以是 trace|debug|info|error. output 是日志文件的名字, SSDB 支持日志轮转, 在日志文件达到一定大小后, 将 log.txt 改名, 然后创建一个新的 log.txt.

leveldb: 配置 LevelDB 的参数. 你一般想要修改的是 cache_size 参数, 用于指定缓存大小. 适当的缓存可以提高读性能, 但是过大的缓存会影响写性能.

在使?用?自带的 ssdb.conf 配置?文件时, SSDB ?生成的?日志?文件按体积进?行分割, 仅此?而已. 所以, 你需要编写?自?己的 crontab 进?行?日志压缩和定期清理. 
如果出现服务器掉电, kernel panic 等系统故障, 在系统重新启动之后, 你需要?手动删除 ssdb的 PID ?文件 ssdb.pid, 然后才能启动 ssdb-server.另外, 你可以参考下?面的做法, 在系统启动和关机时, 启动和关闭 ssdb-server: 
# /bin/sh 

# chkconfig:345 98 98 
# description: SSDB is a fast NoSQL database for storing big list of billions of elements 
# processname:ssdb

case "$1" in 
  'start') 
    /usr/local/ssdb/ssdb-server -d /usr/local/ssdb/ssdb.conf 
    echo "ssdb started." 
    ;; 
  'stop') 
    kill `cat /usr/local/ssdb/var/ssdb.pid` 
    echo "ssdb stopped." 
    ;; 
  'restart') 
    kill `cat /usr/local/ssdb/var/ssdb.pid` 
    echo "ssdb stopped." 
    sleep 0.5 
    /usr/local/ssdb/ssdb-server -d /usr/local/ssdb/ 
ssdb.conf 
    echo "ssdb started." 
    ;; 
  *) 
    echo "Usage: $0 {start|stop|restart}" 
    exit 1 
  ;; 
esac

exit 0

把?件保存为 /etc/init.d/ssdb.sh(需要 root 权限), 然后执?: 
chmod ugo+x /etc/init.d/ssdb.sh

把 ssdb加入chkconfig,并设置开机启动。

[azureuser@mono init.d]$ sudo chkconfig --add ssdb.sh 
[azureuser@mono init.d]$ chkconfig ssdb.sh on

启动、停止的命令如下:

[azureuser@mono init.d]$ sudo service ssdb.sh stop 
ssdb stopped. 
[azureuser@mono init.d]$ sudo service ssdb.sh start 
ssdb 1.6.7 
Copyright (c) 2012-2013 ideawu.com

ssdb started.

项目代码中已经加入c# 的api,https://github.com/ssdb/dotnetssdb,在Mono上跑了一下:

[azureuser@mono dotnet]$ sudo dmcs Client.cs Link.cs Program.cs -out:ssdbClient.exe 
[azureuser@mono dotnet]$ mono ssdbClient.exe 
ok 

ok 
100 
99 
----------------- 
1 kvs 
    a: 99 
----------------- 
0 kvs 
----------------- 
0 kvs 
0

另外, SSDB 提供了预编译的 Windows 下的可执行安装包, Windows 用户可以下载后直接运行 ssdb-server.exe. Windows 下的 SSDB 依赖 cygwin, 所以附带了几个 dll 文件. 使用方式:

1. 从 https://github.com/ideawu/ssdb-bin 下载可执行文件 ssdb-server.exe 和相关 dll.

2. 从 https://github.com/ideawu/ssdb 下载 ssdb.conf 配置文件.

3. 解压, 然后从开始菜单中运行 cmd.exe.

4. 在 cmd.exe 启动后, cd ssdb-server.exe 所在的目录.

5. 执行 ssdb-server.exe ssdb.conf

SSDB 入门基础(Chinese)





Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Compare complex data structures using Java function comparison Compare complex data structures using Java function comparison Apr 19, 2024 pm 10:24 PM

When using complex data structures in Java, Comparator is used to provide a flexible comparison mechanism. Specific steps include: defining the comparator class, rewriting the compare method to define the comparison logic. Create a comparator instance. Use the Collections.sort method, passing in the collection and comparator instances.

Java data structures and algorithms: in-depth explanation Java data structures and algorithms: in-depth explanation May 08, 2024 pm 10:12 PM

Data structures and algorithms are the basis of Java development. This article deeply explores the key data structures (such as arrays, linked lists, trees, etc.) and algorithms (such as sorting, search, graph algorithms, etc.) in Java. These structures are illustrated through practical examples, including using arrays to store scores, linked lists to manage shopping lists, stacks to implement recursion, queues to synchronize threads, and trees and hash tables for fast search and authentication. Understanding these concepts allows you to write efficient and maintainable Java code.

PHP data structure: The balance of AVL trees, maintaining an efficient and orderly data structure PHP data structure: The balance of AVL trees, maintaining an efficient and orderly data structure Jun 03, 2024 am 09:58 AM

AVL tree is a balanced binary search tree that ensures fast and efficient data operations. To achieve balance, it performs left- and right-turn operations, adjusting subtrees that violate balance. AVL trees utilize height balancing to ensure that the height of the tree is always small relative to the number of nodes, thereby achieving logarithmic time complexity (O(logn)) search operations and maintaining the efficiency of the data structure even on large data sets.

Top 10 Global Digital Virtual Currency Trading Platform Ranking (2025 Authoritative Ranking) Top 10 Global Digital Virtual Currency Trading Platform Ranking (2025 Authoritative Ranking) Mar 06, 2025 pm 04:36 PM

In 2025, global digital virtual currency trading platforms are fiercely competitive. This article authoritatively releases the top ten digital virtual currency trading platforms in the world in 2025 based on indicators such as transaction volume, security, and user experience. OKX ranks first with its strong technical strength and global operation strategy, and Binance follows closely with high liquidity and low fees. Platforms such as Gate.io, Coinbase, and Kraken are at the forefront with their respective advantages. The list covers trading platforms such as Huobi, KuCoin, Bitfinex, Crypto.com and Gemini, each with its own characteristics, but investment should be cautious. To choose a platform, you need to consider factors such as security, liquidity, fees, user experience, currency selection and regulatory compliance, and invest rationally

Top 10 digital currency trading platforms The latest list of top 10 digital currency trading platforms Top 10 digital currency trading platforms The latest list of top 10 digital currency trading platforms Mar 17, 2025 pm 05:57 PM

Top 10 digital currency trading platforms: 1. OKX, 2. Binance, 3. Gate.io, 4. Huobi Global, 5. Kraken, 6. Coinbase, 7. KuCoin, 8. Bitfinex, 9. Crypto.com, 10. Gemini, these exchanges have their own characteristics, and users can choose the platform that suits them based on factors such as security, fees, currency selection, user interface and customer support.

Top 10 exchanges in the currency circle in 2025 latest digital currency app rankings Top 10 exchanges in the currency circle in 2025 latest digital currency app rankings Feb 27, 2025 pm 06:33 PM

Ranking of the top ten virtual currency trading platforms (latest in 2025): Binance: Global leader, high liquidity, and regulation has attracted attention. OKX: Large user base, supports multiple currencies, and provides leveraged trading. Gate.io: A senior exchange, with a variety of fiat currency payment methods, providing a variety of trading pairs and investment products. Bitget: Derivatives Exchange, high liquidity, low fees. Huobi: An old exchange that supports a variety of currencies and trading pairs. Coinbase: A well-known American exchange, strictly regulated. Phemex and so on.

Hash table-based data structure optimizes PHP array intersection and union calculations Hash table-based data structure optimizes PHP array intersection and union calculations May 02, 2024 pm 12:06 PM

The hash table can be used to optimize PHP array intersection and union calculations, reducing the time complexity from O(n*m) to O(n+m). The specific steps are as follows: Use a hash table to map the elements of the first array to a Boolean value to quickly find whether the element in the second array exists and improve the efficiency of intersection calculation. Use a hash table to mark the elements of the first array as existing, and then add the elements of the second array one by one, ignoring existing elements to improve the efficiency of union calculations.

Top 10 trading platforms for digital currency apps, regular currency speculation platform app recommendations Top 10 trading platforms for digital currency apps, regular currency speculation platform app recommendations Mar 07, 2025 pm 06:51 PM

This article recommends ten digital currency trading apps: 1. OKX; 2. Binance; 3. Gate.io; 4. Huobi Global; 5. Kraken; 6. Coinbase; 7. KuCoin; 8. Crypto.com; 9. Bitfinex; 10. Poloniex. When choosing a platform, you need to consider factors such as security, liquidity, transaction fees, currency selection, user interface, customer service support and regulatory compliance, and carefully evaluate risks and never blindly follow the trend.

See all articles