-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgram.cs
117 lines (100 loc) · 4.38 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Bogus;
using Bogus.Extensions;
using HBaseNet.Console.Models;
using HBaseNet.Const;
using HBaseNet.HRpc;
using HBaseNet.HRpc.Descriptors;
using HBaseNet.Utility;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
namespace HBaseNet.Console
{
using System;
class Program
{
private const string ZkQuorum = "hbase-docker";
public const string Table = "student";
public static Dictionary<string, Dictionary<string, byte[]>> Values;
public static Faker<Student> StudentFaker;
public static string GenerateRandomKey()
{
return Guid.NewGuid().ToString();
}
static async Task Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.MinimumLevel.Debug()
.WriteTo.Console(
outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.CreateLogger();
HBaseConfig.Instance.ServiceProvider = new ServiceCollection()
.AddLogging(cfg => cfg.AddSerilog(Log.Logger))
.BuildServiceProvider();
StudentFaker = new Faker<Student>()
.StrictMode(true)
.RuleFor(t => t.Name, f => f.Name.FindName())
.RuleFor(t => t.Address, f => f.Address.FullAddress())
.RuleFor(t => t.Age, f => f.Random.Int(1, 100))
.RuleFor(t => t.Create, f => f.Date.Recent())
.RuleFor(t => t.Modify, f => f.Date.Soon().OrNull(f))
.RuleFor(t => t.Score, f => f.Random.Float(0, 5))
.RuleFor(t => t.IsMarried, f => f.Random.Bool().OrNull(f))
.RuleFor(t => t.Courses, f => Enumerable.Range(0, f.Random.Int(0, 10)).Select(i => f.Company.CompanyName()).ToList().OrNull(f))
;
Values = new Dictionary<string, Dictionary<string, byte[]>>
{
{
ConstString.DefaultFamily, new Dictionary<string, byte[]>
{
{"key", "value".ToUtf8Bytes()}
}
}
};
var client = await new StandardClient(ZkQuorum).Build();
if (client == null) return;
var admin = await new AdminClient(ZkQuorum).Build();
if (admin == null) return;
var ado = new AdminClientOperation(admin);
await ado.ExecAll();
var sth = new Stopwatch();
var sto = new SingleThreadOperation(client);
var create = new CreateTableCall(Table.ToUtf8Bytes(), new[] { new ColumnFamily(ConstString.DefaultFamily), new ColumnFamily("special") })
{
SplitKeys = Enumerable.Range('1', 9).Concat(Enumerable.Range('a', 6)).Select(t => $"{(char)t}")
.ToArray()
};
var tables = await admin.ListTableNames(new ListTableNamesCall { Regex = Table });
if (true != tables?.Any())
{
await admin.CreateTable(create);
}
await sto.ExecCheckAndPut();
const int putCount = 10000;
var mto = new MultiThreadOperation(client);
sth.Restart();
await mto.ExecPut(putCount);
Log.Logger.Information($"exec multi thread put ,count: {putCount},take :{sth.Elapsed}");
sth.Restart();
await sto.ExecPut(putCount / 100);
Log.Logger.Information($"exec single thread put ,count: {putCount / 100},take :{sth.Elapsed}");
await sto.ExecAppend();
await sto.ExecIncrement();
sth.Restart();
await sto.ExecScan();
Log.Logger.Information($"exec scan,take :{sth.Elapsed}");
await sto.ExecScanAndDelete();
Console.WriteLine($"Do you want to delete table {Table}?(y)");
if (Console.ReadKey().Key == ConsoleKey.Y)
{
await admin.DisableTable(new DisableTableCall(Table.ToUtf8Bytes()));
var dt = await admin.DeleteTable(new DeleteTableCall(Table.ToUtf8Bytes()));
Log.Logger.Information($"del table:{Table},result:{dt}");
}
}
}
}