Async fork start commit
This commit is contained in:
parent
c84fcf5bf6
commit
33d25fb181
@ -154,7 +154,7 @@ class MySQL {
|
|||||||
* Internal tloop periodic
|
* Internal tloop periodic
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void _tloop();
|
void _tloop(uint32_t b, uint32_t e);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
function<void(const string&)> on_error;
|
function<void(const string&)> on_error;
|
||||||
@ -219,7 +219,7 @@ public:
|
|||||||
* please call this function in it for proper operation at a certain time interval.
|
* please call this function in it for proper operation at a certain time interval.
|
||||||
* You can use the default MYSQL_PERIODIC_INTERNAL_TIME
|
* You can use the default MYSQL_PERIODIC_INTERNAL_TIME
|
||||||
*/
|
*/
|
||||||
void tloop();
|
void tloop(uint32_t b, uint32_t e);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destruktor
|
* Destruktor
|
||||||
|
@ -15,7 +15,7 @@ marcelb::mysql::MySQL::MySQL(const string _path, const string _username, const s
|
|||||||
tloop_future = async(launch::async, [&](){
|
tloop_future = async(launch::async, [&](){
|
||||||
while (run_tloop) {
|
while (run_tloop) {
|
||||||
usleep(MYSQL_PERIODIC_INTERNAL_TIME*1000);
|
usleep(MYSQL_PERIODIC_INTERNAL_TIME*1000);
|
||||||
_tloop();
|
_tloop(0, connection_pool.size());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
@ -93,11 +93,11 @@ bool marcelb::mysql::MySQL::disconnect_connection(Connection* connection) {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void marcelb::mysql::MySQL::_tloop() {
|
void marcelb::mysql::MySQL::_tloop(uint32_t b, uint32_t e) {
|
||||||
if (!run_tloop) {
|
if (!run_tloop) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (size_t i=0; i<connection_pool.size(); i++) {
|
for (size_t i=b; i<connection_pool.size() && i<e; i++) {
|
||||||
try {
|
try {
|
||||||
Connection *conn = nullptr;
|
Connection *conn = nullptr;
|
||||||
{
|
{
|
||||||
@ -112,13 +112,13 @@ void marcelb::mysql::MySQL::_tloop() {
|
|||||||
} else {
|
} else {
|
||||||
cout << "Nije validno----" << endl;
|
cout << "Nije validno----" << endl;
|
||||||
if (!conn->isClosed()){
|
if (!conn->isClosed()){
|
||||||
cout << "Zatvori----" << endl;
|
cout << "Zatvori----" << endl;
|
||||||
|
|
||||||
conn->close();
|
conn->close();
|
||||||
}
|
}
|
||||||
Connection *n_conn = create_connection();
|
Connection *n_conn = create_connection();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
cout << "Otvori----" << endl;
|
||||||
lock_guard<mutex> lock(io);
|
lock_guard<mutex> lock(io);
|
||||||
connection_pool.push(n_conn);
|
connection_pool.push(n_conn);
|
||||||
condition.notify_one();
|
condition.notify_one();
|
||||||
@ -168,12 +168,12 @@ marcelb::mysql::MySQL::~MySQL() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void marcelb::mysql::MySQL::tloop() {
|
void marcelb::mysql::MySQL::tloop(uint32_t b, uint32_t e) {
|
||||||
if (tloop_type == time_loop_type::internal) {
|
if (tloop_type == time_loop_type::internal) {
|
||||||
if (on_error) {
|
if (on_error) {
|
||||||
on_error("Can't start external call tloop, internal is active!");
|
on_error("Can't start external call tloop, internal is active!");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_tloop();
|
_tloop(b,e);
|
||||||
}
|
}
|
@ -14,8 +14,9 @@ using namespace marcelb::asynco;
|
|||||||
int main() {
|
int main() {
|
||||||
auto inis = rtime_ms();
|
auto inis = rtime_ms();
|
||||||
try {
|
try {
|
||||||
|
const int n = 30;
|
||||||
// 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", 12, time_loop_type::external);
|
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", 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,14 +26,44 @@ int main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
periodic mysql_tloop ( [&mydb] () {
|
periodic mysql_tloop ( [&mydb] () {
|
||||||
try {
|
auto l_start = rtime_ms();
|
||||||
auto start = rtime_ms();
|
vector<future<void>> to_wait;
|
||||||
mydb.tloop();
|
for (int i=0, old_i=0; i<n; old_i=i) {
|
||||||
cout << "loop--------------------------- nema error, trajalo: " << rtime_ms() - start << endl;
|
i += 5;
|
||||||
} catch (...) {
|
to_wait.push_back( nonsync ([&, i, old_i](){
|
||||||
cout << "Bude neki error u loopu" << endl;
|
try {
|
||||||
|
auto start = rtime_ms();
|
||||||
|
mydb.tloop(old_i, i);
|
||||||
|
cout << "old " << old_i << " i " << i << endl;
|
||||||
|
cout << "loop--------------------------- nema error, trajalo: " << rtime_ms() - start << endl;
|
||||||
|
} catch (...) {
|
||||||
|
cout << "Bude neki error u loopu" << endl;
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}, 2000);
|
// nonsync ([&](){
|
||||||
|
// try {
|
||||||
|
// auto start = rtime_ms();
|
||||||
|
// mydb.tloop(4, 8);
|
||||||
|
// cout << "loop--------------------------- nema error, trajalo: " << rtime_ms() - start << endl;
|
||||||
|
// } catch (...) {
|
||||||
|
// cout << "Bude neki error u loopu" << endl;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// nonsync ([&](){
|
||||||
|
// try {
|
||||||
|
// auto start = rtime_ms();
|
||||||
|
// mydb.tloop(8, 12);
|
||||||
|
// cout << "loop--------------------------- nema error, trajalo: " << rtime_ms() - start << endl;
|
||||||
|
// } catch (...) {
|
||||||
|
// cout << "Bude neki error u loopu" << endl;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
for (auto& tw : to_wait) {
|
||||||
|
wait (tw);
|
||||||
|
}
|
||||||
|
cout << "all loop !!!!!!!!!!!!!!1, trajalo: " << rtime_ms() - l_start << endl;
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
sleep(60);
|
sleep(60);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user