万万哇 发表于 2024-8-15 02:55:00

微软开源Garnet高性能缓存服务安装

Garnet介绍

Garnet是一款微软研究院基于C#开辟而开源的高性能缓存服务,支持Windows、Linux多平台摆设,Garnet兼容Redis服务API,在性能和利用架构上较Redis有很大提升(官方说法),并提供与Redis一样的下令操纵存储数据,因此可以在不更换现有Redis客户端与库的情况下,即可无缝利用Garnet,从而低沉开辟难度与利用成本;
官方介绍(机翻)

   Garnet 是 Microsoft Research 推出的一种新型长途缓存存储,其设计速度极快、可扩展且延迟低。Garnet 在单个节点内是线程可扩展的。它还支持分片集群实验、复制、检查点、故障转移和事件。它可以在主内存以及分层存储(比方 SSD 和 Azure 存储)上运行。Garnet支持丰富的API接口和强大的可扩展性模型。
Garnet 利用 Redis 的 RESP 作为其主要线路协议。因此,人们可以将 Garnet 与 大多数编程语言中可用的未经修改的 Redis 客户端一起利用,比方C# 中的StackExchange.Redis 。与其他开源缓存存储相比,您可以获得更好的性能、延迟、可扩展性和耐用性功能。
请注意,Garnet 是 Microsoft Research 的一个研究项目,该项目也应如此对待。也就是说,我们是一群充满热情的研究人员和开辟人员,现在正在全职研究它,以使其尽可能稳固和高效。我们的目标是围绕Garnet创建一个充满活力的社区。事实上,Garnet 的质量已经足够高,以至于 Microsoft 的多个第一方和平台团队已经在内部摆设了 Garnet 版本好几个月了。
Garnet具有以下主要长处:


[*]相对于同类开源缓存存储,小批量和很多客户端会话的服务器吞吐量(操纵/秒)提高了几个数目级。
[*]在 Windows 和 Linux 上启用加速 TCP 的商品云 (Azure) 盘算机上,单次操纵延迟极低(在 99.9% 时通常小于 300 微秒)。
[*]随着客户端数目标增加,无论有或没有客户端批处置惩罚,都可以实现更好的可扩展性。
[*]能够通过单个共享内存服务器实例利用服务器盘算机的全部 CPU/内存资源(无需节点内集群)。
[*]支持大于内存的数据集,溢出到本地和云存储设备。
[*]数据库功能,比方快速检查点和恢复以及发布/订阅。
[*]支持多节点分片哈希分区(Redis“集群”模式)、状态迁移和复制。
[*]通过全面的测试套件进行了精良的测试(针对 Garnet 及其存储层 Tsavorite 进行了数千次单位测试)。
[*]易于演变和扩展的 C# 代码库。
如果您的应用程序或服务需要一个具有大量实用功能、高性能以及基于最先进的 Microsoft Research 技能的现代设计的缓存存储,那么 Garnet 就是得当您的体系。在此处检察有关Garnet性能上风的更多详细信息。
https://i-blog.csdnimg.cn/blog_migrate/f7c17f493e8e90d3a215a04ae95ee8af.png

Garnet团体架构
官方文档

Welcome to Garnet | Garnet
github

GitHub - microsoft/garnet: Garnet is a remote cache-store from Microsoft Research that offers strong performance (throughput and latency), scalability, storage, recovery, cluster sharding, key migration, and replication features. Garnet can work with existing Redis clients.
性能预览

微软官方将 Garnet 与领先的开源缓存存储进行比力,参与评测的同类开源服务:Garnet、Redis、KeyDB、Dragonfly;
在相同配置情况下,分别基于:


[*]实验 1:差别数目标客户端会话的吞吐量
[*]实验 2:差别批量巨细的吞吐量
[*]实验 3:差别数目标客户端会话的延迟
[*]实验 4:差别批量巨细的延迟
四个维度进行性能比力;从性能评测结果上来看,Garnet各项性能测试指标,均优于同类产品;
评测结果参见:
Introducing Garnet – an open-source, next-generation, faster cache-store for accelerating applications and services - Microsoft Research
Garnet安装

此项目开源源码,但官方并未提供已编译的二进制安装包,需要自行下载源码编译成可运行应用服务,此处参考官方教程,进行编译、安装;
参考官方入门Build教程:Build and Test | Garnet
注:根据官方文档显示,提供了dockerfile配置,可参考文档尝试docker摆设;
安装情况

操纵体系:Windows 8+
情况依赖: .Net 8
github下载

微软官方将源码开源放到了github上,本地如有安装Git下令行工具,则在任意文件夹内右键打开“Git Bash Here”窗口,输入如下git下令:
git clone https://github.com/microsoft/garnet.git
$ git clone https://github.com/microsoft/garnet.git
Cloning into 'garnet'...
remote: Enumerating objects: 10055, done.
remote: Counting objects: 100% (1629/1629), done.
remote: Compressing objects: 100% (848/848), done.
remote: Total 10055 (delta 846), reused 1000 (delta 759), pack-reused 8426
Receiving objects: 100% (10055/10055), 14.51 MiB | 1.47 MiB/s, done.
Resolving deltas: 100% (7168/7168), done. 通过git下令将工程版本切换到v1.0.0(当前最新版本)
git checkout v1.0.0
$ git checkout v1.0.0
Note: switching to 'v1.0.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

git switch -c <new-branch-name>

Or undo this operation with:

git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 1e5c7ad Initial commit 安装.Net8 SDK

检查Windows情况是否已安装.Net 8可运行情况,如果没有安装,请先从微软官方网站下载安装;此情况是.net应用必需利用的可运行时核心库与情况,用来支持C#和ASP.NET开辟与运行。
进入已克隆的本地garnet工程根目录,检查本地是否安装.net 8
cd garnet/
dotnet test -c Release -f net8.0 -l "console;verbosity=detailed"
$ cd garnet/
$ dotnet test -c Release -f net8.0 -l "console;verbosity=detailed"
正在确定要还原的项目…
C:\Program Files\dotnet\sdk\7.0.203\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(144,5): error NETSDK1045: 当前 .NET SDK 不支持将 .NET 8.0 设置为目标。请将 .NET 7.0 或更低版本设置为目标,或使用支持 .NET 8.0 的 .NET SDK 版本。
C:\Program Files\dotnet\sdk\7.0.203\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(144,5): error NETSDK1045: 当前 .NET SDK 不支持将 .NET 8.0 设置为目标。请将 .NET 7.0 或更低版本设置为目标,或使用支持 .NET 8.0 的 .NET SDK 版本。
此处检查为缺少.Net8 SDK运行情况,从微软官方下载套件
.Net8.0 SDK主页:下载 .NET 8.0 (Linux、macOS 和 Windows)
.Net8.0 SDK下载页:下载 .NET 8.0 SDK (v8.0.203) - Windows x64 Installer
打开页面会主动下载dotnet-sdk-8.0.203-win-x64.exe安装程序,待下载完毕后,双击默认安装即可;
安装后,再一次检测.net8可运行情况,根据电脑硬件情况,可能需要实验几分钟。
dotnet test -c Release -f net8.0 -l "console;verbosity=detailed"
$ dotnet test -c Release -f net8.0 -l "console;verbosity=detailed"

欢迎使用 .NET 8.0!
---------------------
SDK 版本: 8.0.203

遥测
---------
.NET 工具会收集用法数据,帮助我们改善你的体验。它由 Microsoft 收集并与社区共享。你可通过使用喜欢的 shell 将 DOTNET_CLI_TELEMETRY_OPTOUT 环境变量设置为 "1" 或 "true" 来选择退出遥测。

阅读有关 .NET CLI 工具遥测的更多信息: https://aka.ms/dotnet-cli-telemetry

----------------
已安装 ASP.NET Core HTTPS 开发证书。
若要信任该证书,请运行 "dotnet dev-certs https --trust"
了解 HTTPS: https://aka.ms/dotnet-https

----------------
编写第一个应用: https://aka.ms/dotnet-hello-world
了解新增功能: https://aka.ms/dotnet-whats-new
浏览文档: https://aka.ms/dotnet-docs
报告问题并在 GitHub 上查找来源: https://github.com/dotnet/core
使用 "dotnet --help" 查看可用命令或访问: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
正在确定要还原的项目…
已还原 D:\Workspaces\garnet\libs\storage\Tsavorite\cs\src\core\Tsavorite.core.csproj (用时 53.98 sec)。
已还原 D:\Workspaces\garnet\libs\storage\Tsavorite\cs\src\devices\AzureStorageDevice\Tsavorite.devices.AzureStorageDevice.csproj (用时 53.98 sec)。
... 略 (一大堆过程打印)
已通过 ClusterTLSRPrimaryRestart(False,False)
已通过 ClusterTLSRRedirectWrites
NUnit Adapter 4.5.0.0: Test execution complete
已通过 ClusterTLSRReplicaOfTest(True)
已通过 ClusterTLSRReplicaOfTest(False)

测试运行成功。
测试总数: 206
   通过数: 206
总时间: 9.0286 分钟 构建工程

通过下令行对工程源码进行构建,从而编译与生成可运行程序;
第一步:dotnet restore
dotnet restore
正在确定要还原的项目…
已还原 D:\Workspaces\garnet\playground\ClusterStress\ClusterStress.csproj (用时 1.35 sec)。
已还原 D:\Workspaces\garnet\samples\MetricsMonitor\MetricsMonitor.csproj (用时 1.35 sec)。
... 略
已还原 D:\Workspaces\garnet\playground\Embedded.perftest\Embedded.perftest.csproj (用时 129 ms)。
1 个项目(共 19 个)是最新的,无法还原。
第二步:dotnet build -c Release
$ dotnet build -c Release
适用于 .NET MSBuild 版本 17.9.6+a4ecab324
正在确定要还原的项目…
所有项目均是最新的,无法还原。
Garnet.common -> D:\Workspaces\garnet\libs\common\bin\AnyCPU\Release\net7.0\Garnet.common.dll
Garnet.common -> D:\Workspaces\garnet\libs\common\bin\AnyCPU\Release\net6.0\Garnet.common.dll
... 略
Garnet.test.cluster -> D:\Workspaces\garnet\test\Garnet.test.cluster\bin\AnyCPU\Release\net8.0\Garnet.test.cluster.dll
Garnet.test.cluster -> D:\Workspaces\garnet\test\Garnet.test.cluster\bin\AnyCPU\Release\net6.0\Garnet.test.cluster.dll

已成功生成。
    0 个警告
    0 个错误

已用时间 00:01:08.00
实验构建乐成后,会在garnet\main\GarnetServer\bin\AnyCPU\Release目录下生成多个.net版本(如果本机有装多个.net版本)的运行程序;
https://i-blog.csdnimg.cn/blog_migrate/0e146c8049bfcb9baf32ca103fd45b8b.png
进入其中目录检察,已构建生成Garnet应用的dll库和GarnetServer.exe运行程序;可双击单独运行GarnetServer.exe,即可启动Garnet服务;
https://i-blog.csdnimg.cn/blog_migrate/9938dafe40ea44f66748cf389062681e.png
注:此net8.0文件夹下,现实就是我们已经编译后的可分发运行的exe程序和相关依赖库,理论上复制完整的net8.0文件夹在任意有安装.Net 8.0 SDK对应版本Windows操纵体系电脑上,直接双击GarnetServer.exe运行服务(暂未在别的Windows电脑上验证测试,待测试后,上传到GitCode上供下载);
本文参考官方文档,继续持行后续步骤;
运行服务

完成上述两步后,即已编译好Garnet服务,可直接摆设运行Garnet服务;如下操纵
进入garnet/main/GarnetServer/目录
$ cd main/GarnetServer/ 运行Garnet服务
dotnet run -c Release -f net8.0
Garnet可以配置索引巨细、内存巨细、页面巨细、数据文件路径、检查点路径、IP、端口等启动参数;如下,指定索引巨细为为512M;
dotnet run -c Release -f net8.0 -- -i 512m
$ dotnet run -c Release -f net8.0 -- -i 512m
    _________
   /_||___||_\      Garnet 1.0.0 64 bit; standalone mode
   '. \   / .'      Port: 3278
   '.\ /.'      https://aka.ms/GetGarnet
       '.'

* Ready to accept connections
到此服务已正常启动,Garnet默认情况下,监听服务TCP端口为3278,可通过Redis客户端工具进行长途或本地访问,如访问不通,排查防火墙是否限制端口访问;
如果想了解更多Garnet服务启动下令配置,可通过--help检察配置参数资助详情
dotnet run -c Release -f net8.0 -- --help
$ dotnet run -c Release -f net8.0 -- --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)

...略 客户端访问

RedisInsight

本地有安装RedisInsight客户端工具,该工具用于Redis服务访问利用,该工具UI雅观,利用方便,因此本处以该工具做为演示;
https://i-blog.csdnimg.cn/blog_migrate/94aa262f1f2d80e93246df74135f78e3.png
配置连接信息
Host:127.0.0.1
Port:3278
Database Alias:本地-Garnet服务 点击"Test Connection" 进行连接测试,提示测试乐成后,点击“Add Redis Database”按钮保存配置即可;
通过主界面,打开配置的“本地-Garnet服务”访问Garnet服务,Garnet高度兼容Redis下令与接口,利用上和Redis操纵相同,因此可以根据需要,添加与查询各种Key/Value键值;
redis-cli

也可通过CMD下令行窗口调用redis-cli客户端工具直接访问;
redis-cli.exe -h 127.0.0.1 -p 3278
https://i-blog.csdnimg.cn/blog_migrate/8eef4fede117f217fddd4e7a22cde41e.png
末端

到此Garnet服务安装与运行乐成,更多特性与玩法,可自行参考官方文档深入探索;
因微软刚将Garnet开源,此项目还处于连续研发与验证中,除了微软内部有利用经验外,外部企业与项目应用理因较少(未知),属于面向大众利用比力新的项目,除官方文档外,缺乏足够的社区信息和企业应用经验,来提供借鉴;
如要在项目上调研利用,需要考虑Garnet服务落地利用风险,因此尝试生产应用或大规模投产,请三思而后行;

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 微软开源Garnet高性能缓存服务安装