Multi-threaded, multi-process design on servers with data communication and database write

Asked 2 months ago, Updated 2 months ago, 4 views

Preface: I'm sorry if I wrote something wrong or off the mark due to my lack of knowledge.

What I don't know: Optimal design using multi-threaded (multi-process) server applications

Program you want to create: A server that stores data received from your smartphone
Communicating with Smartphones: gRPC
Manage data received from your smartphone: MySQL

Flow of thought

To implement this, we considered two configurations:

スマートフォン A communication thread of gRPC generated by communication with smartphones is used as a parent, and an authentication thread of a user token and a data storage thread in SQL are generated as a child thread.Each thread is communicated by Pipe, and gRPC reception data, user authentication results, and SQL writing results are exchanged.
When you finish communicating with your smartphone, the gRPC communications thread ends and so does the child thread.

Benefits: Fewer threads are deployed all the time?
Disadvantages: Does every gRPC communication cost a new thread?

Enter a description of the image here
②A gRPC thread is generated by communication with a smartphone.An authentication thread of the user token and a fixed number of data storage threads to the SQL are generated in advance and kept waiting in a loop sentence.
Each thread is communicated by Pipe, and gRPC reception data, user authentication results, and SQL writing results are exchanged.
Benefits: Fast response to user authentication and SQL data storage?
Disadvantages: Many threads are constantly deployed.Can user authentication and SQL data storage threads be insufficient when gRPC threads increase?
Enter a description of the image here

Also, as a common question between 分かりません and の, I don't know if it's okay to create a pipe that matches the number of threads.
Is it better to have only one pipe connecting each module?
(For example, putting identifiers such as thread IDs in and out of Pipe, putting data from Pipe into shared memory for each module, and referring to shared memory for each thread?)

I would appreciate it if you could let me know which design is better, which one is wrong in the first place, and if there is a correct design.
Thank you for your cooperation.

Note: Up to 5000 concurrent clients are expected.
It's only a few dozen cars.
The frequency of communication is about two or three hours once a day.During that time, it receives tens of kilobytes of data in approximately 500 ms cycles.
It doesn't require high real-time performance, but I want to return the response to my smartphone, so I want to keep the delay between a few seconds and 10 seconds.

python python3 python-multiprocessing

2022-09-30 11:50

1 Answers

The maximum number of simultaneous connections for clients is approximately 5000.

Personally, I think it's an asynchronous choice.As the questionnaire does not mention asynchronous, a fundamental design review may be necessary.

It's a very rough description, but asynchronous is a programming model that leaves the network and other IO operations to the operating system and notifies you when they're done.The main thing is to give instructions from the program side, so you don't need a lot of threads.

I would like to return the response to my smartphone, so I would like to limit the delay to a few seconds to 10 seconds.

Do you ever wait for the screen of your smartphone for 10 seconds? Don't you want to rerun or press it for now? At that moment, your request will swell several times.

2022-09-30 11:50

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.