-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfarm_prod.cpp
66 lines (50 loc) · 1.83 KB
/
farm_prod.cpp
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
#include <getopt.h>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <unistd.h>
#include "demo.h"
#include <iostream>
using namespace std;
int main(int argc, char **argv) {
std::ofstream fout("prod.csv", std::ios_base::out);
const char *server_name = consumer_name;
for(auto msgsize : msg_size_list) {
printf("producer(%lu msgsize) running\n", msgsize);
param.buffer_size = get_ringbuffer_size(msgsize);
uint8_t *message = new uint8_t[msgsize]();
{ /* thput test */
uint64_t iterations = get_iterations(msgsize);
RingBufferFarmProducer rb(device_name, param);
rb.exchangeQPInfo(server_name, port);
rb.start();
fout << "\t\t\t msg_size = " << msgsize << endl;
printf("=== Start ThroughPut Test ===\n");
auto start = std::chrono::system_clock::now();
void *msgend = message + msgsize;
for (uint64_t round = 0; round < iterations; ++round) {
*(uint64_t*)message = round;
*(uint64_t*)(message + msgsize - 8) = round;
#ifdef VERIFY_ALL
for(void *z = message; z < msgend; z += 8) {
*(uint64_t*)z = round;
}
#endif
rb.sendBlock(message, msgsize);
}
auto end = std::chrono::system_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::microseconds>(end - start);
printf("=== Finish ===\n");
double trans_size = 1.0 * msgsize * iterations;
printf("size %.0lf B, %.2lf ms, %.2lf MiB/s\n", trans_size, duration.count() / 1e3,
trans_size / (1 << 20) / (duration.count() / 1e6));
printf("=== Cleaning ===\n");
rb.close_connection();
fout << std::fixed << std::setprecision(6)
<< trans_size / (1 << 20) / (duration.count() / 1e6)
<< std::endl;
}
}
}