-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadBalancer.cpp
More file actions
64 lines (59 loc) · 1.45 KB
/
LoadBalancer.cpp
File metadata and controls
64 lines (59 loc) · 1.45 KB
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
#include <chrono>
#include <iostream>
#include <thread>
#include <vector>
#include "ServerSocket.h"
#include "LoadThread.h"
int main(int argc, char *argv[])
{
int port;
int engineer_cnt = 0;
int num_experts = 1;
int num_replicas = 1;
int cache_capacity = 0;
ServerSocket socket;
LoadFactory factory;
std::unique_ptr<ServerSocket> new_socket;
std::vector<std::thread> thread_vector;
if (argc < 3)
{
std::cout << "not enough arguments" << std::endl;
std::cout << argv[0] << " [port #] [# experts] " << std::endl;
// return 0;
port = 12347;
num_experts = 1;
factory.cache_capacity = cache_capacity;
}
else
{
port = atoi(argv[1]);
factory.cache_capacity = atoi(argv[2]);
num_replicas = atoi(argv[3]);
int startindex = 4;
for (int k = 0; k < num_replicas; k++)
{
factory.AddReplica(atoi(argv[startindex]), argv[startindex + 1], atoi(argv[startindex + 2]));
startindex += 3;
}
}
for (int i = 0; i < num_experts; i++)
{
std::thread expert_thread(&LoadFactory::ExpertThread,
&factory, engineer_cnt++);
thread_vector.push_back(std::move(expert_thread));
}
if (!socket.Init(port))
{
std::cout << "Socket initialization failed" << std::endl;
return 0;
}
while ((new_socket = socket.Accept()))
{
std::thread engineer_thread(&LoadFactory::EngineerThread,
&factory, std::move(new_socket),
engineer_cnt++);
thread_vector.push_back(std::move(engineer_thread));
}
return 0;
// }
}