前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >微软开源的garnet的docker化实验

微软开源的garnet的docker化实验

原创
作者头像
保持热爱奔赴山海
修改2024-03-25 21:40:51
3810
修改2024-03-25 21:40:51
举报
文章被收录于专栏:饮水机管理员饮水机管理员

最近 微软开源了用c#编写的redis兼容缓存组件garnet。

官方没有提供现成的docker版本,我们可以根据它的文档自行构建。具体如下:

下载源码

代码语言:bash
复制
mkdir /root/abc/
cd /root/abc/
wget https://github.com/microsoft/garnet/archive/refs/tags/v1.0.0.tar.gz
tar czf garnet-1.0.0.tar.gz -C ./
mv garnet-1.0.0/* ./

vim Dockerfile 内容如下:

代码语言:bash
复制
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /source

# Copy files
COPY . .
RUN dotnet restore
RUN dotnet build -c Release

# Copy and publish app and libraries
WORKDIR /source/main/GarnetServer
RUN dotnet publish -c Release -o /app --self-contained false -f net8.0

# Final stage/image
FROM mcr.microsoft.com/dotnet/runtime:8.0
WORKDIR /app
COPY --from=build /app .

# Run GarnetServer with an index size of 128MB
ENTRYPOINT ["/app/GarnetServer", "-i", "128m"]

构建镜像

代码语言:bash
复制
docker build .
docker tag 85aa314262b0 garnet:v1.0.0

编写 docker-compose.yaml 文件

代码语言:bash
复制
version: '3'
networks:
    monitor:
        driver: bridge
services:
    garnet:
        image: garnet:v1.0.0
        container_name: garnet
        hostname: garnet
        restart: always
        # 可以直接在启动的命令行里传参,也可基于配置文件传参,这里简单起见直接使用默认参数
        # command: --memory 8g --auth Password --password 123456  
        ports:
            - "3278:3278"
        networks:
            - monitor

启动

代码语言:bash
复制
docker-compose up -d

连接测试

代码语言:bash
复制
redis-cli -p 3278
127.0.0.1:3278> info

性能

garnet 官网上面也有一页讲garnet和其它几款redis like组件的比对。

本人之前也简单测过redis keydb dragonfly 这几款的get set等性能。这次又加上garnet的测试结果。

总体来说,dragonfly和garnet的性能差不多,都比keydb和redis单机的要好。【测试工具:https://github.com/vipshop/vire】

兼容性测试

可以使用参考 杨一大佬的这篇文章 ,用的是compatibility-test-suite-for-redis 这个python包。在测试 garnet的兼容性时候,python脚本出现报错,这里没有进行深入探究,就此作罢。

附录,Garnet支持的命令行参数

代码语言:plaintext
复制


root@garnet:/app# ./GarnetServer --help
GarnetServer
Copyright (c) Microsoft Corporation

  --port                                   (Default: 3278) Port to run server on

  --bind                                   IP address to bind server to
                                           (default: any)

  -m, --memory                             (Default: "16g") Total log memory used in bytes
                                           (rounds down to power of 2)

  -p, --page                               (Default: "32m") Size of each page in bytes (rounds
                                           down to power of 2)

  -s, --segment                            (Default: "1g") Size of each log segment in bytes on
                                           disk (rounds down to power of 2)

  -i, --index                              (Default: "8g") Size of hash index in bytes (rounds
                                           down to power of 2)

  --index-max-size                         Max size of hash index in bytes
                                           (rounds down to power of 2)

  --mutable-percent                        (Default: 90) Percentage of log memory that is kept
                                           mutable

  --obj-total-memory                       Total object store log memory used
                                           including heap memory in bytes

  --obj-memory                             (Default: "32m") Object store log memory used in bytes
                                           excluding heap memory

  --obj-page                               (Default: "1m") Size of each object store page in
                                           bytes (rounds down to power of 2)

  --obj-segment                            (Default: "32m") Size of each object store log segment
                                           in bytes on disk (rounds down to
                                           power of 2)

  --obj-index                              (Default: "1g") Size of object store hash index in
                                           bytes (rounds down to power of 2)

  --obj-index-max-size                     Max size of object store hash index
                                           in bytes (rounds down to power of 2)

  --obj-mutable-percent                    (Default: 90) Percentage of object store log memory
                                           that is kept mutable

  --storage-tier                           (Default: False) Enable tiering of records (hybrid
                                           log) to storage, to support a
                                           larger-than-memory store. Use
                                           --logdir to specify storage
                                           directory.

  --copy-reads-to-tail                     (Default: False) When records are read from the main
                                           store's in-memory immutable region or
                                           storage device, copy them to the tail
                                           of the log.

  --obj-copy-reads-to-tail                 (Default: False) When records are read from the object
                                           store's in-memory immutable region or
                                           storage device, copy them to the tail
                                           of the log.

  -l, --logdir                             Storage directory for tiered records
                                           (hybrid log), if storage tiering
                                           (--storage) is enabled. Uses current
                                           directory if unspecified.

  -c, --checkpointdir                      Storage directory for checkpoints.
                                           Uses logdir if unspecified.

  -r, --recover                            (Default: False) Recover from latest checkpoint and
                                           log, if present.

  --no-pubsub                              (Default: False) Disable pub/sub feature on server.

  --incsnap                                (Default: False) Enable incremental snapshots.

  --pubsub-pagesize                        (Default: "4k") Page size of log used for pub/sub
                                           (rounds down to power of 2)

  --no-obj                                 (Default: False) Disable support for data structure
                                           objects.

  --cluster                                (Default: False) Enable cluster.

  --clean-cluster-config                   (Default: False) Start with clean cluster config.

  --auth                                   (Default: NoAuth) Authentication mode of Garnet. This
                                           impacts how AUTH command is processed
                                           and how clients are authenticated
                                           against Garnet. Value options:
                                           NoAuth, Password, Aad, ACL

  --password                               Authentication string for password
                                           authentication.

  --cluster-username                       Username to authenticate
                                           intra-cluster communication with.

  --cluster-password                       Password to authenticate
                                           intra-cluster communication with.

  --acl-file                               External ACL user file.

  --aad-authority                          (Default: "https://login.microsoftonline.com") The authority of AAD 

  --aad-audiences                          The audiences of AAD token for AAD
                                           authentication. Should be a comma
                                           separated string.

  --aad-issuers                            The issuers of AAD token for AAD
                                           authentication. Should be a comma
                                           separated string.

  --aad-authorized-app-ids                 The authorized client app Ids for AAD
                                           authentication. Should be a comma
                                           separated string.

  --aof                                    (Default: False) Enable write ahead logging
                                           (append-only file).

  --aof-memory                             (Default: "64m") Total AOF memory buffer used in bytes
                                           (rounds down to power of 2) - spills
                                           to disk after this limit

  --aof-page-size                          (Default: "4m") Size of each AOF page in bytes(rounds
                                           down to power of 2)

  --aof-commit-freq                        (Default: 0) Write ahead logging (append-only
                                           file) commit issue frequency in
                                           milliseconds. 0 = issue an immediate
                                           commit per operation, -1 = manually
                                           issue commits using COMMITAOF command

  --aof-commit-wait                        (Default: False) Wait for AOF to flush the commit
                                           before returning results to client.
                                           Warning: will greatly increase
                                           operation latency.

  --aof-size-limit                         Maximum size of AOF (rounds down to
                                           power of 2) after which unsafe
                                           truncation will be applied. Left
                                           empty AOF will grow without bound
                                           unless a checkpoint is taken

  --compaction-freq                        (Default: 0) Background hybrid log compaction
                                           frequency in seconds. 0 = disabled
                                           (compaction performed before
                                           checkpointing instead)

  --compaction-type                        (Default: None) Hybrid log compaction type. Value
                                           options: None - No compaction, Shift
                                           - shift begin address without
                                           compaction (data loss), ShiftForced -
                                           shift begin address without
                                           compaction (data loss). Immediately
                                           deletes files - do not use if you
                                           plan to recover after failure, Scan -
                                           scan old pages and move live records
                                           to tail (no data loss - take a
                                           checkpoint to actually delete the
                                           older data files from disk), Lookup -
                                           Lookup each record in compaction
                                           range, for record liveness checking
                                           using hash chain (no data loss - take
                                           a checkpoint to actually delete the
                                           older data files from disk)

  --compaction-max-segments                (Default: 32) Number of log segments created on
                                           disk before compaction triggers.

  --obj-compaction-max-segments            (Default: 32) Number of object store log segments
                                           created on disk before compaction
                                           triggers.

  --gossip-sp                              (Default: 100) Percent of cluster nodes to gossip
                                           with at each gossip iteration.

  --gossip-delay                           (Default: 5) Cluster mode gossip protocol per node
                                           sleep (in seconds) delay to send
                                           updated config.

  --cluster-timeout                        (Default: 60) Cluster node timeout is the amount of
                                           seconds a node must be unreachable.

  --cluster-tls-client-target-host         (Default: "GarnetTest") Name for the client target host when
                                           using TLS connections in cluster
                                           mode.

  --tls                                    (Default: False) Enable TLS.

  --cert-file-name                         TLS certificate file name (example:
                                           testcert.pfx).

  --cert-password                          TLS certificate password (example:
                                           placeholder).

  --cert-subject-name                      TLS certificate subject name.

  --cert-refresh-freq                      (Default: 0) TLS certificate refresh frequency in
                                           seconds (0 to disable).

  --client-certificate-required            (Default: True) Whether TLS client certificate
                                           required.

  --certificate-revocation-check-mode      (Default: NoCheck) Certificate revocation check mode for
                                           certificate validation (NoCheck,
                                           Online, Offline).

  --issuer-certificate-path                Full path of file with issuer
                                           certificate for validation. If empty
                                           or null, validation against issuer
                                           will not be performed.

  --latency-monitor                        (Default: False) Track latency of various events.

  --metrics-sampling-freq                  (Default: 0) Metrics sampling frequency in
                                           seconds. Value of 0 disables metrics
                                           monitor task.

  -q                                       Enabling quiet mode does not print
                                           server version and text art.

  --logger-level                           (Default: Warning) Logging level. Value options: Trace,
                                           Debug, Information, Warning, Error,
                                           Critical, None

  --disable-console-logger                 (Default: False) Disable console logger.

  --file-logger                            Enable file logger and write to the
                                           specified path.

  --minthreads                             (Default: 0) Minimum worker and completion threads
                                           in thread pool, 0 uses the system
                                           default.

  --maxthreads                             (Default: 0) Maximum worker and completion threads
                                           in thread pool, 0 uses the system
                                           default.

  --use-azure-storage                      (Default: False) Use Azure Page Blobs for storage
                                           instead of local storage.

  --storage-string                         The connection string to use when
                                           establishing connection to Azure
                                           Blobs Storage.

  --checkpoint-throttle-delay              (Default: 0) Whether and by how much should we
                                           throttle the disk IO for checkpoints:
                                           -1 - disable throttling; >= 0 - run
                                           checkpoint flush in separate task,
                                           sleep for specified time after each
                                           WriteAsync

  --fast-commit                            (Default: False) Use FastCommit when writing AOF.

  --fast-commit-throttle                   (Default: 1000) Throttle FastCommit to write metadata
                                           once every K commits.

  --network-send-throttle                  (Default: 8) Throttle the maximum outstanding
                                           network sends per session.

  --sg-get                                 (Default: False) Whether we use scatter gather IO for
                                           MGET or a batch of contiguous GET
                                           operations - useful to saturate disk
                                           random read IO.

  --replica-sync-delay                     (Default: 5) Whether and by how much
                                           (milliseconds) should we throttle the
                                           replica sync: 0 - disable throttling

  --main-memory-replication                (Default: False) Use main-memory replication model.

  --on-demand-checkpoint                   (Default: False) Used with main-memory replication
                                           model. Take on demand checkpoint to
                                           avoid missing data when attaching

  --aof-null-device                        (Default: False) With main-memory replication, use
                                           null device for AOF. Ensures no disk
                                           IO, but can cause data loss during
                                           replication.

  --config-import-path                     Import (load) configuration options
                                           from the provided path

  --config-import-format                   (Default: GarnetConf) Format of configuration options in
                                           path specified by config-import-path

  --config-export-format                   (Default: GarnetConf) Format to export configuration
                                           options to path specified by
                                           config-export-path

  --use-azure-storage-for-config-import    (Default: false) Use Azure storage to
                                           import config file

  --config-export-path                     Export (save) current configuration
                                           options to the provided path

  --use-azure-storage-for-config-export    (Default: false) Use Azure storage to
                                           export config file

  --use-native-device-linux                (Default: False) Use native device on Linux for local
                                           storage

  --reviv-bin-record-sizes                 #,#,...,#: For the main store, the
                                           sizes of records in each
                                           revivification bin, in order of
                                           increasing size.           Supersedes
                                           the default --reviv; cannot be used
                                           with --reviv-in-chain-only

  --reviv-bin-record-counts                #,#,...,#: For the main store, the
                                           number of records in each bin:
                                           Default (not specified): If
                                           reviv-bin-record-sizes is specified,
                                           each bin is 256 records    # (one
                                           value): If reviv-bin-record-sizes is
                                           specified, then all bins have this
                                           number of records, else error
                                           #,#,...,# (multiple values): If
                                           reviv-bin-record-sizes is specified,
                                           then it must be the same size as that
                                           array, else error
                                           Supersedes the default --reviv;
                                           cannot be used with
                                           --reviv-in-chain-only

  --reviv-fraction                         (Default: 1) #: Fraction of mutable in-memory log
                                           space, from the highest log address
                                           down to the read-only region, that is
                                           eligible for revivification.
                                           Applies to both main and object
                                           store.

  --reviv                                  (Default: False) A shortcut to specify revivification
                                           with default power-of-2-sized bins.
                                           This default can be overridden by
                                           --reviv-in-chain-only (Default: False) or by the
                                           combination of reviv-bin-record-sizes
                                           and reviv-bin-record-counts.

  --reviv-search-next-higher-bins          (Default: 0) Search this number of next-higher
                                           bins if the search cannot be
                                           satisfied in the best-fitting bin.
                                           Requires --reviv or the combination
                                           of rconeviv-bin-record-sizes and
                                           reviv-bin-record-counts

  --reviv-bin-best-fit-scan-limit          (Default: 0) Number of records to scan for best
                                           fit after finding first fit.
                                           Requires --reviv or the combination
                                           of reviv-bin-record-sizes and
                                           reviv-bin-record-counts    0: Use
                                           first fit    #: Limit scan to this
                                           many records after first fit, up to
                                           the record count of the bin

  --reviv-in-chain-only                    (Default: False) Revivify tombstoned records in tag
                                           chains only (do not use free list).
                                           Cannot be used with
                                           reviv-bin-record-sizes or
                                           reviv-bin-record-counts. Propagates
                                           to object store by default.

  --reviv-obj-bin-record-count             (Default: 256) Number of records in the single free
                                           record bin for the object store. The
                                           Object store has only a single bin,
                                           unlike the main store.        Ignored
                                           unless the main store is using the
                                           free record list.

  --object-scan-count-limit                (Default: 1000) Limit of items to return in one
                                           iteration of *SCAN command

  --extension-bin-paths                    List of directories on server from
                                           which custom command binaries can be
                                           loaded by admin users

  --extension-allow-unsigned               (Default: False) Allow loading custom commands from
                                           digitally unsigned assemblies (not
                                           recommended)

  --index-resize-freq                      (Default: 60) Index resize check frequency in
                                           seconds

  --index-resize-threshold                 (Default: 50) Overflow bucket count over total
                                           index size in percentage to trigger
                                           index resize

  --help                                   Display this help screen.

  --version                                Display version information.

  value pos. 0                             

参考 https://microsoft.github.io/garnet/docs/getting-started

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 Redis
腾讯云数据库 Redis(TencentDB for Redis)是腾讯云打造的兼容 Redis 协议的缓存和存储服务。丰富的数据结构能帮助您完成不同类型的业务场景开发。支持主从热备,提供自动容灾切换、数据备份、故障迁移、实例监控、在线扩容、数据回档等全套的数据库服务。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档