Skip to content

Commit 79b3c77

Browse files
committed
Merge branch 'feature/multi-codex-folder-saver'
2 parents 9ccc4c5 + 3a8c2a3 commit 79b3c77

File tree

14 files changed

+337
-347
lines changed

14 files changed

+337
-347
lines changed

Framework/NethereumWorkflow/NethereumInteraction.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public decimal GetEthBalance(string address)
6262
log.Debug(typeof(TFunction).ToString());
6363
var handler = web3.Eth.GetContractQueryHandler<TFunction>();
6464
var result = Time.Wait(handler.QueryRawAsync(contractAddress, function, new BlockParameter(blockNumber)));
65-
var aaaa = 0;
6665
}
6766

6867
public string SendTransaction<TFunction>(string contractAddress, TFunction function) where TFunction : FunctionMessage, new()

Tools/AutoClient/App.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,13 @@ public App(Configuration config)
2020
new FileLog(Path.Combine(config.LogPath, "performance")),
2121
new ConsoleLog()
2222
));
23-
24-
var httpFactory = new HttpFactory(Log, new AutoClientWebTimeSet());
25-
26-
CodexNodeFactory = new CodexNodeFactory(log: Log, httpFactory: httpFactory, dataDir: Config.DataPath);
2723
}
2824

2925
public Configuration Config { get; }
3026
public ILog Log { get; }
3127
public IFileGenerator Generator { get; }
3228
public CancellationTokenSource Cts { get; } = new CancellationTokenSource();
3329
public Performance Performance { get; }
34-
public CodexNodeFactory CodexNodeFactory { get; }
3530

3631
private IFileGenerator CreateGenerator()
3732
{

Tools/AutoClient/AutomaticPurchaser.cs

Lines changed: 0 additions & 145 deletions
This file was deleted.

Tools/AutoClient/Configuration.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ public class Configuration
66
{
77
[Uniform("codex-endpoints", "ce", "CODEXENDPOINTS", false, "Codex endpoints. Semi-colon separated. (default 'http://localhost:8080')")]
88
public string CodexEndpoints { get; set; } =
9-
"http://localhost:8080";
9+
"http://localhost:8080" + ";" +
10+
"http://localhost:8081" + ";" +
11+
"http://localhost:8082" + ";" +
12+
"http://localhost:8083" + ";" +
13+
"http://localhost:8084" + ";" +
14+
"http://localhost:8085" + ";" +
15+
"http://localhost:8086" + ";" +
16+
"http://localhost:8087";
1017

1118
[Uniform("datapath", "dp", "DATAPATH", false, "Root path where all data files will be saved.")]
1219
public string DataPath { get; set; } = "datapath";
@@ -21,7 +28,7 @@ public class Configuration
2128
// Cluster nodes configured for max 7-day storage.
2229

2330
[Uniform("contract-expiry", "ce", "CONTRACTEXPIRY", false, "contract expiry in minutes. (default 15 minutes)")]
24-
public int ContractExpiryMinutes { get; set; } = 60;
31+
public int ContractExpiryMinutes { get; set; } = 15;
2532

2633
[Uniform("num-hosts", "nh", "NUMHOSTS", false, "Number of hosts for contract. (default 10)")]
2734
public int NumHosts { get; set; } = 5;
@@ -41,8 +48,16 @@ public class Configuration
4148
[Uniform("folderToStore", "fts", "FOLDERTOSTORE", false, "When set, autoclient will attempt to upload and purchase storage for every non-JSON file in the provided folder.")]
4249
public string FolderToStore { get; set; } = "/data/EthereumMainnetPreMergeEraFiles";
4350

44-
[Uniform("ethAddressFile", "eaf", "ETHADDRESSFILE", false, "File with eth address used by codex node. Used for balance checking if geth/contracts information is provided.")]
45-
public string EthAddressFile { get; set; } = "/root/codex-testnet-starter/scripts/eth.address";
51+
[Uniform("ethAddressFile", "eaf", "ETHADDRESSFILE", false, "File(s) with eth address used by codex node. Used for balance checking if geth/contracts information is provided. Semi-colon separated.")]
52+
public string EthAddressFile { get; set; } =
53+
"/root/codex-testnet-starter/scripts/eth.address" + ";" +
54+
"/root/codex-testnet-starter/scripts/eth_2.address" + ";" +
55+
"/root/codex-testnet-starter/scripts/eth_3.address" + ";" +
56+
"/root/codex-testnet-starter/scripts/eth_4.address" + ";" +
57+
"/root/codex-testnet-starter/scripts/eth_5.address" + ";" +
58+
"/root/codex-testnet-starter/scripts/eth_6.address" + ";" +
59+
"/root/codex-testnet-starter/scripts/eth_7.address" + ";" +
60+
"/root/codex-testnet-starter/scripts/eth_8.address";
4661

4762
public string LogPath
4863
{

Tools/AutoClient/LoadBalancer.cs

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
using Logging;
2+
3+
namespace AutoClient
4+
{
5+
public class LoadBalancer
6+
{
7+
private readonly List<Cdx> instances;
8+
private readonly object instanceLock = new object();
9+
10+
private class Cdx
11+
{
12+
private readonly ILog log;
13+
private readonly CodexWrapper instance;
14+
private readonly List<Action<CodexWrapper>> queue = new List<Action<CodexWrapper>>();
15+
private readonly object queueLock = new object();
16+
private bool running = true;
17+
private Task worker = Task.CompletedTask;
18+
19+
public Cdx(App app, CodexWrapper instance)
20+
{
21+
Id = instance.Node.GetName();
22+
log = new LogPrefixer(app.Log, $"[Queue-{Id}]");
23+
this.instance = instance;
24+
}
25+
26+
public string Id { get; }
27+
28+
public void Start()
29+
{
30+
worker = Task.Run(Worker);
31+
}
32+
33+
public void Stop()
34+
{
35+
running = false;
36+
worker.Wait();
37+
}
38+
39+
public void CheckErrors()
40+
{
41+
if (worker.IsFaulted) throw worker.Exception;
42+
}
43+
44+
public void Queue(Action<CodexWrapper> action)
45+
{
46+
if (queue.Count > 2) log.Log("Queue full. Waiting...");
47+
while (queue.Count > 2)
48+
{
49+
Thread.Sleep(TimeSpan.FromSeconds(5.0));
50+
}
51+
52+
lock (queueLock)
53+
{
54+
queue.Add(action);
55+
}
56+
}
57+
58+
private void Worker()
59+
{
60+
try
61+
{
62+
while (running)
63+
{
64+
while (queue.Count == 0) Thread.Sleep(TimeSpan.FromSeconds(5.0));
65+
66+
Action<CodexWrapper> action = w => { };
67+
lock (queueLock)
68+
{
69+
action = queue[0];
70+
queue.RemoveAt(0);
71+
}
72+
73+
action(instance);
74+
}
75+
}
76+
catch (Exception ex)
77+
{
78+
log.Error("Exception in worker: " + ex);
79+
throw;
80+
}
81+
}
82+
}
83+
84+
public LoadBalancer(App app, CodexWrapper[] instances)
85+
{
86+
this.instances = instances.Select(i => new Cdx(app, i)).ToList();
87+
}
88+
89+
public void Start()
90+
{
91+
foreach (var i in instances) i.Start();
92+
}
93+
94+
public void Stop()
95+
{
96+
foreach (var i in instances) i.Stop();
97+
}
98+
99+
public void DispatchOnCodex(Action<CodexWrapper> action)
100+
{
101+
lock (instanceLock)
102+
{
103+
var i = instances.First();
104+
instances.RemoveAt(0);
105+
instances.Add(i);
106+
107+
i.Queue(action);
108+
}
109+
}
110+
111+
public void DispatchOnSpecificCodex(Action<CodexWrapper> action, string id)
112+
{
113+
lock (instanceLock)
114+
{
115+
var i = instances.Single(a => a.Id == id);
116+
instances.Remove(i);
117+
instances.Add(i);
118+
119+
i.Queue(action);
120+
}
121+
}
122+
123+
public void CheckErrors()
124+
{
125+
lock (instanceLock)
126+
{
127+
foreach (var i in instances) i.CheckErrors();
128+
}
129+
}
130+
}
131+
}

0 commit comments

Comments
 (0)