diff --git a/backend/proxy/proxy.cpp b/backend/proxy/proxy.cpp index 4ccc02a..b9d24e5 100644 --- a/backend/proxy/proxy.cpp +++ b/backend/proxy/proxy.cpp @@ -17,7 +17,7 @@ //#define MULTI_THREAD //#define DEBUG //#define DEBUG_PACKET - +//#define THREAD_NUM using namespace std; boost::asio::io_service *ios_loop = nullptr; @@ -459,7 +459,11 @@ int main(int argc, char* argv[]) acceptor.accept_connections(); #ifdef MULTI_THREAD boost::thread_group tg; + #ifdef THREAD_NUM + for (unsigned i = 0; i < THREAD_NUM; ++i) + #else for (unsigned i = 0; i < thread::hardware_concurrency(); ++i) + #endif tg.create_thread(boost::bind(&boost::asio::io_service::run, &ios)); tg.join_all(); diff --git a/start.py b/start.py index 30ecd53..50dc51c 100755 --- a/start.py +++ b/start.py @@ -23,6 +23,8 @@ parser = argparse.ArgumentParser() parser.add_argument('--port', "-p", type=int, required=False, help='Port where open the web service of the firewall', default=4444) parser.add_argument('--no-autostart', "-n", required=False, action="store_true", help='Auto-execute "docker-compose up -d --build"', default=False) parser.add_argument('--single-thread', "-s", required=False, action="store_true", help='Disable multi-threaded proxy"', default=False) +parser.add_argument('--thread-num', "-t", type=int, required=False, help='Number of threads to use', default=None) + args = parser.parse_args() sep() puts(f"Firegex", color=colors.yellow, end="") @@ -31,6 +33,8 @@ puts(f"{args.port}", color=colors.cyan) os.chdir(os.path.dirname(os.path.realpath(__file__))) +gcc_params = "-D MULTI_THREAD" if not args.single_thread else "" +gcc_params+= f" -D THREAD_NUM={args.thread_num}" if args.thread_num else "" with open("docker-compose.yml","wt") as compose: if "linux" in sys.platform and not 'microsoft-standard' in platform.uname().release: #Check if not is a wsl also @@ -43,7 +47,7 @@ services: build: context: . args: - - GCC_PARAMS={"-D MULTI_THREAD" if not args.single_thread else ""} + - GCC_PARAMS={gcc_params} network_mode: "host" environment: - NGINX_PORT={args.port} @@ -64,7 +68,7 @@ services: build: context: . args: - - GCC_PARAMS={"-D MULTI_THREAD" if not args.single_thread else ""} + - GCC_PARAMS={gcc_params} ports: - {args.port}:{args.port} environment: