没用的测试项目,干扰视线
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -86,3 +86,7 @@
|
|||||||
/mypwsh/bin
|
/mypwsh/bin
|
||||||
/回收/bin
|
/回收/bin
|
||||||
/消费/bin
|
/消费/bin
|
||||||
|
/Faster
|
||||||
|
/MyFaster
|
||||||
|
/MyFunctioncache
|
||||||
|
/mypwsh
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.FASTER.Core" Version="2.6.5" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
using FASTER.core;
|
|
||||||
|
|
||||||
namespace Faster
|
|
||||||
{
|
|
||||||
internal class Program
|
|
||||||
{
|
|
||||||
static void Main(string[] args)
|
|
||||||
{
|
|
||||||
using var settings = new FasterKVSettings<long, long>("c:/temp"); // backing storage device
|
|
||||||
using var store = new FasterKV<long, long>(settings);
|
|
||||||
|
|
||||||
// Create a session per sequence of interactions with FASTER
|
|
||||||
// We use default callback functions with a custom merger: RMW merges input by adding it to value
|
|
||||||
using var session = store.NewSession(new SimpleFunctions<long, long>((a, b) => a + b));
|
|
||||||
|
|
||||||
long key = 1, value = 1, input = 10, output = 0;
|
|
||||||
|
|
||||||
// Upsert and Read
|
|
||||||
session.Upsert(ref key, ref value);
|
|
||||||
session.Read(ref key, ref output);
|
|
||||||
|
|
||||||
// Read-Modify-Write (add input to value)
|
|
||||||
session.RMW(ref key, ref input);
|
|
||||||
session.RMW(ref key, ref input, ref output);
|
|
||||||
Console.WriteLine("Hello, World!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using FASTER.core;
|
|
||||||
|
|
||||||
namespace MyFaster
|
|
||||||
{
|
|
||||||
public class LengRe
|
|
||||||
{
|
|
||||||
public void AAA()
|
|
||||||
{
|
|
||||||
// 创建存储设备(混合内存+磁盘)
|
|
||||||
var logDevice = Devices.CreateLogDevice("colddata.log"); // 冷数据存储到磁盘
|
|
||||||
var logSettings = new LogSettings
|
|
||||||
{
|
|
||||||
LogDevice = logDevice,
|
|
||||||
MemorySizeBits = 20, // 1MB 内存(热数据区)
|
|
||||||
PageSizeBits = 16 // 64KB 磁盘页
|
|
||||||
};
|
|
||||||
|
|
||||||
// 创建 FASTER 实例
|
|
||||||
var store = new FasterKV<Key, Value>(
|
|
||||||
size: 1 << 16, // 哈希表大小
|
|
||||||
logSettings: logSettings
|
|
||||||
);
|
|
||||||
|
|
||||||
// 创建会话
|
|
||||||
var session = store.NewSession(new SimpleFunctions<Key, Value>());
|
|
||||||
|
|
||||||
// 写入数据(自动处理热/冷数据)
|
|
||||||
Key key = new Key { Id = 1 };
|
|
||||||
Value value = new Value { Data = "示例数据", LastAccessed = DateTime.UtcNow };
|
|
||||||
|
|
||||||
session.Upsert(ref key, ref value);
|
|
||||||
|
|
||||||
// 读取数据(热数据在内存,冷数据从磁盘加载)
|
|
||||||
Value output = default;
|
|
||||||
Status status = session.Read(ref key, ref output);
|
|
||||||
|
|
||||||
Console.WriteLine($"读取数据: {output.Data}");
|
|
||||||
Console.WriteLine($"最后访问: {output.LastAccessed}");
|
|
||||||
|
|
||||||
// 更新访问时间(保持数据热度)
|
|
||||||
output.LastAccessed = DateTime.UtcNow;
|
|
||||||
session.Upsert(ref key, ref output);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 填充测试数据
|
|
||||||
for (int i = 0; i < 1000; i++)
|
|
||||||
{
|
|
||||||
Key k = new Key { Id = i };
|
|
||||||
Value v = new Value { Data = $"Item-{i}", LastAccessed = DateTime.UtcNow };
|
|
||||||
session.Upsert(ref k, ref v);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 访问部分数据保持热度
|
|
||||||
for (int i = 0; i < 10; i++) // 频繁访问前10条
|
|
||||||
{
|
|
||||||
Key k = new Key { Id = i };
|
|
||||||
Value v = default;
|
|
||||||
session.Read(ref k, ref v);
|
|
||||||
v.LastAccessed = DateTime.UtcNow;
|
|
||||||
session.Upsert(ref k, ref v);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 此时:
|
|
||||||
// - 前10条是热数据(在内存)
|
|
||||||
// - 其余990条是冷数据(在磁盘)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Read()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public struct Key : IEquatable<Key>
|
|
||||||
{
|
|
||||||
public int Id;
|
|
||||||
public bool Equals(Key other) => Id == other.Id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct Value
|
|
||||||
{
|
|
||||||
public string Data;
|
|
||||||
public DateTime LastAccessed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="MemoryPack" Version="1.21.4" />
|
|
||||||
<PackageReference Include="MemoryPack.Core" Version="1.21.4" />
|
|
||||||
<PackageReference Include="Microsoft.FASTER.Core" Version="2.6.5" />
|
|
||||||
<PackageReference Include="Microsoft.FASTER.Server" Version="2.6.5" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
using FASTER.core;
|
|
||||||
|
|
||||||
// 定义数据结构
|
|
||||||
public struct MyKey : IEquatable<MyKey>
|
|
||||||
{
|
|
||||||
public int Id;
|
|
||||||
public bool Equals(MyKey other) => Id == other.Id;
|
|
||||||
public override int GetHashCode() => Id.GetHashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct MyValue
|
|
||||||
{
|
|
||||||
public byte[] Data;
|
|
||||||
public DateTime Timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct MyInput
|
|
||||||
{
|
|
||||||
public byte[] NewData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct MyOutput
|
|
||||||
{
|
|
||||||
public MyValue Value;
|
|
||||||
public bool Updated;
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct MyContext
|
|
||||||
{
|
|
||||||
public string OperationId;
|
|
||||||
public DateTime StartTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 实现自定义 Functions
|
|
||||||
public class MyCustomFunctions : FunctionsBase<MyKey, MyValue, MyInput, MyOutput, MyContext>
|
|
||||||
{
|
|
||||||
// 读取完成回调
|
|
||||||
public override void ReadCompletionCallback(ref MyKey key, ref MyInput input, ref MyOutput output, MyContext ctx, Status status, RecordMetadata recordMetadata)
|
|
||||||
{
|
|
||||||
base.ReadCompletionCallback(ref key, ref input, ref output, ctx, status, recordMetadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//// 写入完成回调
|
|
||||||
//public override void UpsertCompletionCallback(
|
|
||||||
// ref MyKey key, ref MyValue value, MyContext ctx)
|
|
||||||
//{
|
|
||||||
// Console.WriteLine($"Upsert completed for key {key.Id}");
|
|
||||||
//}
|
|
||||||
|
|
||||||
//// 删除完成回调
|
|
||||||
//public override void DeleteCompletionCallback(
|
|
||||||
// ref MyKey key, MyContext ctx)
|
|
||||||
//{
|
|
||||||
// Console.WriteLine($"Delete completed for key {key.Id}");
|
|
||||||
//}
|
|
||||||
|
|
||||||
//// RMW (Read-Modify-Write) 操作 - 核心功能!
|
|
||||||
//public override void RMWCompletionCallback(
|
|
||||||
// ref MyKey key, ref MyInput input, ref MyOutput output,
|
|
||||||
// MyContext ctx, Status status)
|
|
||||||
//{
|
|
||||||
// if (status == Status.OK)
|
|
||||||
// {
|
|
||||||
// Console.WriteLine($"RMW completed for key {key.Id}");
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//// 并发控制:当多个线程同时修改相同键时调用
|
|
||||||
//public override bool ConcurrentWriter(
|
|
||||||
// ref MyKey key, ref MyValue value, ref MyValue newValue)
|
|
||||||
//{
|
|
||||||
// // 返回 true 表示接受新值,false 表示拒绝
|
|
||||||
// return newValue.Timestamp > value.Timestamp;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//// 读取时复制:允许在读取时修改返回值
|
|
||||||
//public override bool SingleReader(
|
|
||||||
// ref MyKey key, ref MyInput input, ref MyValue value, ref MyOutput dst)
|
|
||||||
//{
|
|
||||||
// dst.Value = value;
|
|
||||||
// dst.Updated = false;
|
|
||||||
// return true;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//// 写入时处理:自定义写入逻辑
|
|
||||||
//public override bool ConcurrentWriter(
|
|
||||||
// ref MyKey key, ref MyValue value, ref MyValue newValue)
|
|
||||||
//{
|
|
||||||
// // 只有新数据的时间戳更晚时才更新
|
|
||||||
// if (newValue.Timestamp > value.Timestamp)
|
|
||||||
// {
|
|
||||||
// value = newValue;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
using System.Diagnostics;
|
|
||||||
using System.Net;
|
|
||||||
using FASTER.core;
|
|
||||||
using MemoryPack;
|
|
||||||
|
|
||||||
namespace MyFaster
|
|
||||||
{
|
|
||||||
[MemoryPackable()]
|
|
||||||
public partial class MyData
|
|
||||||
{
|
|
||||||
public string? FirstName { get; set; }
|
|
||||||
public string? LastName { get; set; }
|
|
||||||
public int Age { get; set; }
|
|
||||||
public string? DetailData { get; set; }
|
|
||||||
}
|
|
||||||
internal class Program
|
|
||||||
{
|
|
||||||
public static byte[] Serialize<T>(T obj)
|
|
||||||
{
|
|
||||||
return MemoryPackSerializer.Serialize(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static T Deserialize<T>(byte[] data)
|
|
||||||
{
|
|
||||||
return MemoryPackSerializer.Deserialize<T>(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class MyValueSerializer1 : BinaryObjectSerializer<MyData>
|
|
||||||
{
|
|
||||||
public override void Serialize(ref MyData value)
|
|
||||||
{
|
|
||||||
writer.Write(value.FirstName);
|
|
||||||
writer.Write(value.LastName);
|
|
||||||
writer.Write(value.Age);
|
|
||||||
writer.Write(value.DetailData);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Deserialize(out MyData value)
|
|
||||||
{
|
|
||||||
value = new MyData
|
|
||||||
{
|
|
||||||
FirstName = reader.ReadString(),
|
|
||||||
LastName = reader.ReadString(),
|
|
||||||
Age = reader.ReadInt32(),
|
|
||||||
DetailData = reader.ReadString()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class MyValueSerializer : BinaryObjectSerializer<MyData>
|
|
||||||
{
|
|
||||||
public override void Serialize(ref MyData value)
|
|
||||||
{
|
|
||||||
//writer.Write(IPAddress.HostToNetworkOrder(Q.Length)); // 4字节长度头
|
|
||||||
var Q = MemoryPackSerializer.Serialize(value);
|
|
||||||
writer.Write(Q.Length); // 4字节长度头
|
|
||||||
writer.Write(Q);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Deserialize(out MyData value)
|
|
||||||
{
|
|
||||||
int length = reader.ReadInt32(); // 读长度头
|
|
||||||
byte[] buffer = reader.ReadBytes(length); // 读数据体
|
|
||||||
value = MemoryPackSerializer.Deserialize<MyData>(buffer); // 反序列化
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async Task Main(string[] args)
|
|
||||||
{
|
|
||||||
using var settings = new FasterKVSettings<string, MyData>()
|
|
||||||
{
|
|
||||||
LogDevice = Devices.CreateLogDevice("c:/mytemp/log"), // 元数据日志
|
|
||||||
ObjectLogDevice = Devices.CreateLogDevice("c:/mytemp/obj"), // 对象数据日志
|
|
||||||
TryRecoverLatest = true,
|
|
||||||
ValueSerializer = () => new MyValueSerializer()
|
|
||||||
};
|
|
||||||
using var store = new FasterKV<string, MyData>(settings);
|
|
||||||
using var session = store.NewSession(new SimpleFunctions<string, MyData>());
|
|
||||||
|
|
||||||
MyData mydata0 = new MyData() { FirstName = "1", LastName = "fdfdf", DetailData = "detail1" };
|
|
||||||
MyData mydata1 = new MyData() { FirstName = "1", LastName = "fdfdf", DetailData = "detail1" };
|
|
||||||
MyData mydata2 = new MyData() { FirstName = "1", LastName = "fdfdf", DetailData = "detail1" };
|
|
||||||
|
|
||||||
string mma0 = "a";
|
|
||||||
string mma1 = "b";
|
|
||||||
string mma2 = "c";
|
|
||||||
|
|
||||||
session.Upsert(ref mma0, ref mydata0);
|
|
||||||
session.Upsert(ref mma1, ref mydata1);
|
|
||||||
session.Upsert(ref mma2, ref mydata2);
|
|
||||||
|
|
||||||
session.CompletePending(true);
|
|
||||||
// 创建增量检查点(性能更好)
|
|
||||||
await store.TakeHybridLogCheckpointAsync(CheckpointType.FoldOver);
|
|
||||||
|
|
||||||
// 方法1:完整检查点(推荐)
|
|
||||||
await store.TakeFullCheckpointAsync(CheckpointType.Snapshot);
|
|
||||||
|
|
||||||
//完整检查点
|
|
||||||
await store.TakeFullCheckpointAsync(CheckpointType.FoldOver);
|
|
||||||
|
|
||||||
MyData output = null;
|
|
||||||
var status = session.Read(ref mma0, ref output);
|
|
||||||
|
|
||||||
Console.WriteLine("Hello, World!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="ZiggyCreatures.FusionCache" Version="2.4.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
using ZiggyCreatures.Caching.Fusion;
|
|
||||||
|
|
||||||
namespace MyFunctioncache
|
|
||||||
{
|
|
||||||
internal class Program
|
|
||||||
{
|
|
||||||
static void Main(string[] args)
|
|
||||||
{
|
|
||||||
var entryOptions = new FusionCacheEntryOptions().SetDuration(TimeSpan.FromMinutes(10));
|
|
||||||
|
|
||||||
// 创建缓存实例
|
|
||||||
var cache = new FusionCache(new FusionCacheOptions()
|
|
||||||
{
|
|
||||||
DefaultEntryOptions = new FusionCacheEntryOptions
|
|
||||||
{
|
|
||||||
Duration = TimeSpan.FromMinutes(5) // 默认缓存5分钟
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// 设置缓存值
|
|
||||||
cache.Set("product_123", new PersonInfo {UserName="aaa"});
|
|
||||||
|
|
||||||
// 获取缓存值
|
|
||||||
var product = cache.TryGet<PersonInfo>("product_123");
|
|
||||||
|
|
||||||
// 删除缓存项
|
|
||||||
cache.Remove("product_123");
|
|
||||||
Console.WriteLine("Hello, World!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PersonInfo
|
|
||||||
{
|
|
||||||
public string UserName { get; set; }
|
|
||||||
|
|
||||||
public int Age { get; set; }
|
|
||||||
|
|
||||||
public string Nationality { get; set; }
|
|
||||||
|
|
||||||
public string CacheMsg { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Management.Automation;
|
|
||||||
using System.Management.Automation.Runspaces;
|
|
||||||
namespace mypwsh
|
|
||||||
{
|
|
||||||
internal class Program
|
|
||||||
{
|
|
||||||
static void Main(string[] args)
|
|
||||||
{
|
|
||||||
using (var ps = PowerShell.Create())
|
|
||||||
{
|
|
||||||
// 避免使用 AddScript,改用 AddCommand
|
|
||||||
ps.AddCommand("Get-Service");
|
|
||||||
|
|
||||||
var results = ps.Invoke();
|
|
||||||
foreach (var result in results)
|
|
||||||
{
|
|
||||||
var service = result.BaseObject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Console.WriteLine("Hello, World!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFramework>net8.0-windows</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.5.1" />
|
|
||||||
<PackageReference Include="System.Management.Automation" Version="7.4.12" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
Reference in New Issue
Block a user