|
|
@ -4,19 +4,20 @@ |
|
|
|
using namespace std; |
|
|
|
using namespace std; |
|
|
|
using namespace chrono; |
|
|
|
using namespace chrono; |
|
|
|
|
|
|
|
|
|
|
|
#include "../lib/mysql.hpp" |
|
|
|
|
|
|
|
using namespace marcelb::mysql; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "../../asynco/lib/asynco.hpp" |
|
|
|
#include "../../asynco/lib/asynco.hpp" |
|
|
|
#include "../../asynco/lib/timers.hpp" |
|
|
|
#include "../../asynco/lib/timers.hpp" |
|
|
|
using namespace marcelb::asynco; |
|
|
|
using namespace marcelb::asynco; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "../lib/mysql.hpp" |
|
|
|
|
|
|
|
using namespace marcelb::mysql; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main() { |
|
|
|
int main() { |
|
|
|
auto inis = rtime_ms(); |
|
|
|
auto inis = rtime_ms(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
const int n = 30; |
|
|
|
const int n = 5; |
|
|
|
// MySQL mydb("tcp://192.168.2.10:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", 5, time_loop_type::internal);
|
|
|
|
// MySQL mydb("tcp://192.168.2.10:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", 5, time_loop_type::internal);
|
|
|
|
MySQL mydb("tcp://bitelex.ddns.net:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", n, time_loop_type::external); |
|
|
|
MySQL mydb("tcp://bitelex.ddns.net:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", n); |
|
|
|
// MySQL mydb("tcp://bitelex.ddns.net:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", 5);
|
|
|
|
// MySQL mydb("tcp://bitelex.ddns.net:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", 5);
|
|
|
|
|
|
|
|
|
|
|
|
cout << "init: " << rtime_ms() - inis << endl; |
|
|
|
cout << "init: " << rtime_ms() - inis << endl; |
|
|
@ -25,23 +26,23 @@ int main() { |
|
|
|
cout << error << endl; |
|
|
|
cout << error << endl; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
periodic mysql_tloop ( [&mydb] () { |
|
|
|
// periodic mysql_tloop ( [&mydb] () {
|
|
|
|
auto l_start = rtime_ms(); |
|
|
|
// auto l_start = rtime_ms();
|
|
|
|
vector<future<void>> to_wait; |
|
|
|
// vector<future<void>> to_wait;
|
|
|
|
for (int i=0, old_i=0; i<n; old_i=i) { |
|
|
|
// for (int i=0, old_i=0; i<n; old_i=i) {
|
|
|
|
i += 5; |
|
|
|
// i += 5;
|
|
|
|
to_wait.push_back( nonsync ([&, i, old_i](){ |
|
|
|
// to_wait.push_back( async_ ([&, i, old_i](){
|
|
|
|
try { |
|
|
|
// try {
|
|
|
|
auto start = rtime_ms(); |
|
|
|
// auto start = rtime_ms();
|
|
|
|
mydb.tloop(old_i, i); |
|
|
|
// mydb.tloop(old_i, i);
|
|
|
|
cout << "old " << old_i << " i " << i << endl; |
|
|
|
// cout << "old " << old_i << " i " << i << endl;
|
|
|
|
cout << "loop--------------------------- nema error, trajalo: " << rtime_ms() - start << endl; |
|
|
|
// cout << "loop--------------------------- nema error, trajalo: " << rtime_ms() - start << endl;
|
|
|
|
} catch (...) { |
|
|
|
// } catch (...) {
|
|
|
|
cout << "Bude neki error u loopu" << endl; |
|
|
|
// cout << "Bude neki error u loopu" << endl;
|
|
|
|
} |
|
|
|
// }
|
|
|
|
})); |
|
|
|
// }));
|
|
|
|
} |
|
|
|
// }
|
|
|
|
// nonsync ([&](){
|
|
|
|
// async_ ([&](){
|
|
|
|
// try {
|
|
|
|
// try {
|
|
|
|
// auto start = rtime_ms();
|
|
|
|
// auto start = rtime_ms();
|
|
|
|
// mydb.tloop(4, 8);
|
|
|
|
// mydb.tloop(4, 8);
|
|
|
@ -50,7 +51,7 @@ int main() { |
|
|
|
// cout << "Bude neki error u loopu" << endl;
|
|
|
|
// cout << "Bude neki error u loopu" << endl;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// nonsync ([&](){
|
|
|
|
// async_ ([&](){
|
|
|
|
// try {
|
|
|
|
// try {
|
|
|
|
// auto start = rtime_ms();
|
|
|
|
// auto start = rtime_ms();
|
|
|
|
// mydb.tloop(8, 12);
|
|
|
|
// mydb.tloop(8, 12);
|
|
|
@ -59,18 +60,18 @@ int main() { |
|
|
|
// cout << "Bude neki error u loopu" << endl;
|
|
|
|
// cout << "Bude neki error u loopu" << endl;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
for (auto& tw : to_wait) { |
|
|
|
// for (auto& tw : to_wait) {
|
|
|
|
wait (tw); |
|
|
|
// wait (tw);
|
|
|
|
} |
|
|
|
// }
|
|
|
|
cout << "all loop !!!!!!!!!!!!!!1, trajalo: " << rtime_ms() - l_start << endl; |
|
|
|
// cout << "all loop !!!!!!!!!!!!!!1, trajalo: " << rtime_ms() - l_start << endl;
|
|
|
|
}, 5000); |
|
|
|
// }, 5000);
|
|
|
|
|
|
|
|
|
|
|
|
while (true) { |
|
|
|
while (true) { |
|
|
|
sleep(60); |
|
|
|
sleep(60); |
|
|
|
|
|
|
|
|
|
|
|
auto start = high_resolution_clock::now(); |
|
|
|
auto start = high_resolution_clock::now(); |
|
|
|
|
|
|
|
|
|
|
|
auto a1 = nonsync ( [&mydb] () { |
|
|
|
auto a1 = async_ ( [&mydb] () { |
|
|
|
try { |
|
|
|
try { |
|
|
|
auto response = mydb.exec<int,string>("SELECT id,domain FROM records WHERE enabled = 1;"); |
|
|
|
auto response = mydb.exec<int,string>("SELECT id,domain FROM records WHERE enabled = 1;"); |
|
|
|
cout << response.affected << " " << response.have_result << endl; |
|
|
|
cout << response.affected << " " << response.have_result << endl; |
|
|
@ -89,7 +90,7 @@ while (true) { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
auto a2 = nonsync ( [&mydb] () { |
|
|
|
auto a2 = async_ ( [&mydb] () { |
|
|
|
try { |
|
|
|
try { |
|
|
|
auto response = mydb.exec<string,string>("SELECT zonename,auth_key FROM zones;"); |
|
|
|
auto response = mydb.exec<string,string>("SELECT zonename,auth_key FROM zones;"); |
|
|
|
cout << response.affected << " " << response.have_result << endl; |
|
|
|
cout << response.affected << " " << response.have_result << endl; |
|
|
@ -108,7 +109,7 @@ while (true) { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
auto a3 = nonsync ( [&mydb] () { |
|
|
|
auto a3 = async_ ( [&mydb] () { |
|
|
|
try { |
|
|
|
try { |
|
|
|
auto response = mydb.exec<string,string>("SELECT username,email FROM users WHERE enabled = 1;"); |
|
|
|
auto response = mydb.exec<string,string>("SELECT username,email FROM users WHERE enabled = 1;"); |
|
|
|
cout << response.affected << " " << response.have_result << endl; |
|
|
|
cout << response.affected << " " << response.have_result << endl; |
|
|
@ -127,7 +128,7 @@ while (true) { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
auto a4 = nonsync ( [&mydb] () { |
|
|
|
auto a4 = async_ ( [&mydb] () { |
|
|
|
try { |
|
|
|
try { |
|
|
|
auto response = mydb.exec<int,string>("SELECT id,domain FROM records WHERE enabled = 1;"); |
|
|
|
auto response = mydb.exec<int,string>("SELECT id,domain FROM records WHERE enabled = 1;"); |
|
|
|
cout << response.affected << " " << response.have_result << endl; |
|
|
|
cout << response.affected << " " << response.have_result << endl; |
|
|
@ -146,7 +147,7 @@ while (true) { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
auto a5 = nonsync ( [&mydb] () { |
|
|
|
auto a5 = async_ ( [&mydb] () { |
|
|
|
try { |
|
|
|
try { |
|
|
|
auto response = mydb.exec<string,string>("SELECT zonename,auth_key FROM zones;"); |
|
|
|
auto response = mydb.exec<string,string>("SELECT zonename,auth_key FROM zones;"); |
|
|
|
cout << response.affected << " " << response.have_result << endl; |
|
|
|
cout << response.affected << " " << response.have_result << endl; |
|
|
@ -165,7 +166,7 @@ while (true) { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
auto a6 = nonsync ( [&mydb] () { |
|
|
|
auto a6 = async_ ( [&mydb] () { |
|
|
|
try { |
|
|
|
try { |
|
|
|
auto response = mydb.exec<string,string>("SELECT username,email FROM users WHERE enabled = 1;"); |
|
|
|
auto response = mydb.exec<string,string>("SELECT username,email FROM users WHERE enabled = 1;"); |
|
|
|
cout << response.affected << " " << response.have_result << endl; |
|
|
|
cout << response.affected << " " << response.have_result << endl; |
|
|
@ -184,12 +185,12 @@ while (true) { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
wait(a1); |
|
|
|
await_(a1); |
|
|
|
wait(a2); |
|
|
|
await_(a2); |
|
|
|
wait(a3); |
|
|
|
await_(a3); |
|
|
|
wait(a4); |
|
|
|
await_(a4); |
|
|
|
wait(a5); |
|
|
|
await_(a5); |
|
|
|
wait(a6); |
|
|
|
await_(a6); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto end = high_resolution_clock::now(); |
|
|
|
auto end = high_resolution_clock::now(); |
|
|
|