From fcd74dcb5b22fada5fa432f3c0a3d3701ee8f551 Mon Sep 17 00:00:00 2001 From: nik012003 Date: Sat, 25 Jun 2022 20:25:19 +0200 Subject: [PATCH] Added multithreading --- Dockerfile | 4 +-- backend/proxy/proxy.cpp | 11 ++++--- backend/proxy/test | 72 +++++++++++++++++++++++++++++++++++++++++ backend/utils.py | 5 ++- tests/benchmark.py | 6 +++- 5 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 backend/proxy/test diff --git a/Dockerfile b/Dockerfile index f12e86b..e838872 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ #Building main conteiner FROM python:slim-buster -RUN apt-get update && apt-get -y install curl supervisor gettext-base build-essential libboost-dev nginx libboost-system-dev +RUN apt-get update && apt-get -y install curl supervisor gettext-base build-essential libboost-dev nginx libboost-system-dev libboost-thread-dev RUN curl -sL https://deb.nodesource.com/setup_16.x | bash RUN apt-get install nodejs @@ -14,7 +14,7 @@ ADD ./backend/requirements.txt /execute/requirements.txt RUN pip install --no-cache-dir -r /execute/requirements.txt COPY ./backend/ /execute/ -RUN c++ -O3 -o proxy/proxy proxy/proxy.cpp -pthread -lboost_system +RUN c++ -O3 -o proxy/proxy proxy/proxy.cpp -pthread -lboost_system -lboost_thread COPY ./config/supervisord.conf /etc/supervisor/supervisord.conf COPY ./config/nginx.conf /tmp/nginx.conf COPY ./config/start_nginx.sh /tmp/start_nginx.sh diff --git a/backend/proxy/proxy.cpp b/backend/proxy/proxy.cpp index 367c6e4..682f0f7 100644 --- a/backend/proxy/proxy.cpp +++ b/backend/proxy/proxy.cpp @@ -4,16 +4,15 @@ #include #include #include - #include + +#include #include #include #include #include #include -#include // is* - //#define DEBUG using namespace std; @@ -439,7 +438,11 @@ int main(int argc, char* argv[]) acceptor.accept_connections(); - ios.run(); + boost::thread_group tg; + for (unsigned i = 0; i < thread::hardware_concurrency(); ++i) + tg.create_thread(boost::bind(&boost::asio::io_service::run, &ios)); + + tg.join_all(); } catch(exception& e) { diff --git a/backend/proxy/test b/backend/proxy/test new file mode 100644 index 0000000..156e119 --- /dev/null +++ b/backend/proxy/test @@ -0,0 +1,72 @@ +1C3733353138303461313162386234323563313931613664373937666264356630 +1S3733353138303461313162386234323563313931613664373937666264356630 +1C3065376433366539666631353833373263633764613966396235313538633766 +1S3065376433366539666631353833373263633764613966396235313538633766 +1C3638316561366437356466353765656265383933396630326262393338336438 +1S3638316561366437356466353765656265383933396630326262393338336438 +1C3739663566343265663536633261656665623338346135616464633539663930 +1S3739663566343265663536633261656665623338346135616464633539663930 +1C3733353138303461313162386234323563313931613664373937666264356630 +1S3733353138303461313162386234323563313931613664373937666264356630 +1C3065376433366539666631353833373263633764613966396235313538633766 +1S3065376433366539666631353833373263633764613966396235313538633766 +1C3638316561366437356466353765656265383933396630326262393338336438 +1S3638316561366437356466353765656265383933396630326262393338336438 +1C3739663566343265663536633261656665623338346135616464633539663930 +1S3739663566343265663536633261656665623338346135616464633539663930 +1C3733353138303461313162386234323563313931613664373937666264356630 +1S3733353138303461313162386234323563313931613664373937666264356630 +1C3065376433366539666631353833373263633764613966396235313538633766 +1S3065376433366539666631353833373263633764613966396235313538633766 +1C3638316561366437356466353765656265383933396630326262393338336438 +1S3638316561366437356466353765656265383933396630326262393338336438 +1C3739663566343265663536633261656665623338346135616464633539663930 +1S3739663566343265663536633261656665623338346135616464633539663930 +1C3733353138303461313162386234323563313931613664373937666264356630 +1S3733353138303461313162386234323563313931613664373937666264356630 +1C3065376433366539666631353833373263633764613966396235313538633766 +1S3065376433366539666631353833373263633764613966396235313538633766 +1C3638316561366437356466353765656265383933396630326262393338336438 +1S3638316561366437356466353765656265383933396630326262393338336438 +1C3739663566343265663536633261656665623338346135616464633539663930 +1S3739663566343265663536633261656665623338346135616464633539663930 +1C3733353138303461313162386234323563313931613664373937666264356630 +1S3733353138303461313162386234323563313931613664373937666264356630 +1C3065376433366539666631353833373263633764613966396235313538633766 +1S3065376433366539666631353833373263633764613966396235313538633766 +1C3638316561366437356466353765656265383933396630326262393338336438 +1S3638316561366437356466353765656265383933396630326262393338336438 +1C3739663566343265663536633261656665623338346135616464633539663930 +1S3739663566343265663536633261656665623338346135616464633539663930 +1C3733353138303461313162386234323563313931613664373937666264356630 +1S3733353138303461313162386234323563313931613664373937666264356630 +1C3065376433366539666631353833373263633764613966396235313538633766 +1S3065376433366539666631353833373263633764613966396235313538633766 +1C3638316561366437356466353765656265383933396630326262393338336438 +1S3638316561366437356466353765656265383933396630326262393338336438 +1C3739663566343265663536633261656665623338346135616464633539663930 +1S3739663566343265663536633261656665623338346135616464633539663930 +1C3733353138303461313162386234323563313931613664373937666264356630 +1S3733353138303461313162386234323563313931613664373937666264356630 +1C3065376433366539666631353833373263633764613966396235313538633766 +1S3065376433366539666631353833373263633764613966396235313538633766 +1C3638316561366437356466353765656265383933396630326262393338336438 +1S3638316561366437356466353765656265383933396630326262393338336438 +1C3739663566343265663536633261656665623338346135616464633539663930 +1S3739663566343265663536633261656665623338346135616464633539663930 +1C3733353138303461313162386234323563313931613664373937666264356630 +1S3733353138303461313162386234323563313931613664373937666264356630 +1C3065376433366539666631353833373263633764613966396235313538633766 +1S3065376433366539666631353833373263633764613966396235313538633766 +1C3638316561366437356466353765656265383933396630326262393338336438 +1S3638316561366437356466353765656265383933396630326262393338336438 +1C3739663566343265663536633261656665623338346135616464633539663930 +1S3739663566343265663536633261656665623338346135616464633539663930 +1C3733353138303461313162386234323563313931613664373937666264356630 +1S3733353138303461313162386234323563313931613664373937666264356630 +1C3065376433366539666631353833373263633764613966396235313538633766 +1S3065376433366539666631353833373263633764613966396235313538633766 +1C3638316561366437356466353765656265383933396630326262393338336438 +1S3638316561366437356466353765656265383933396630326262393338336438 +1C3739663566343265663536633261656665623338346135616464633539663930 +1S3739663566343265663536633261656665623338346135616464633539663930 diff --git a/backend/utils.py b/backend/utils.py index 4918dc2..504d050 100755 --- a/backend/utils.py +++ b/backend/utils.py @@ -153,9 +153,8 @@ class ProxyManager: self.__update_status_db(id, next_status) if saved_status[0] == "wait": saved_status[0] = next_status proxy_status = proxy.start(in_pause=(next_status==STATUS.PAUSE)) - if proxy_status != 0: - saved_status[0] = STATUS.STOP - self.__update_status_db(id, STATUS.STOP) + saved_status[0] = STATUS.STOP + self.__update_status_db(id, STATUS.STOP) return else: time.sleep(.5) diff --git a/tests/benchmark.py b/tests/benchmark.py index 8d8aa82..7f4473c 100755 --- a/tests/benchmark.py +++ b/tests/benchmark.py @@ -29,6 +29,7 @@ parser.add_argument("--password", "-p", type=str, required=True, help='Firegex p parser.add_argument("--num_of_regexes", "-r", type=int, required=True, help='Number of regexes to benchmark with') parser.add_argument("--duration", "-d", type=int, required=False, help='Duration of the Benchmark in seconds', default=5) parser.add_argument("--output_file", "-o", type=str, required=False, help='Output results csv file', default="benchmark.csv") +parser.add_argument("--num_of_streams", "-s", type=int, required=False, help='Output results csv file', default=1) args = parser.parse_args() sep() @@ -75,7 +76,10 @@ def getReading(port): client.server_hostname = '127.0.0.1' client.port = port client.protocol = 'tcp' - return round(client.run().json['end']['sum_received']['bits_per_second']/8e+6 , 3) + client.num_streams = args.num_of_streams + run = client.run() + print(run) + return round(run.json['end']['sum_received']['bits_per_second']/8e+6 , 3) server = Process(target=startServer) server.start()