https://qiita.com/shotaTsuge/items/0ad41fcee63a00a52f68
@shotaTsuge
posted at 2015-12-01
updated at 2015-12-02
beginner
,
memorandum
,
The Basics
I've decided to start over with MySQL from the basics for 6 months, and I'll post what I've learned during that time on Qiita.
Rough differences between threads and multiprocesses
One major difference is that child threads share heap (global program data) with their parent, whereas
child processes do not share.
Advantages and disadvantages of threads
Advantages
Low memory usage.
No need for sophisticated techniques to access server global data.
Even when data is modified by concurrent threads, only the relevant section needs to be protected using mutual exclusion locks (mutex).
Heap segments do not need to be copied and can be created in much less time than processes
Scheduler context switches take less time for the kernel than processes
Disadvantages
One thread crash can affect the entire server
Easy to make programming mistakes
Synchronization bugs in threaded servers (due to shared address space)
Mutex contention can be difficult to contain (causing excessive context switches)
Advantages and disadvantages of multiprocessing
Advantages
Even if there is a rogue server process, the entire server is not affected
Since only one thread of execution needs to be kept in mind, programming errors are less likely to occur
Easy to reproduce bugs, since phantom bugs (bugs that cannot be reproduced intentionally) are unlikely to occur.
Individual processes have their own address space, so interactions between processes are not large.
Disadvantages
When a child process branches, a large memory segment may be copied unnecessarily.
Data sharing between processes is time-consuming, and access to server global data is cumbersome
Imposes more overhead on the kernel to create processes
Parent process data segments must be copied
Context switches between processes consume a lot of time
Considerations
If you need to share a large amount of data between connection handlers (high programming skill), I personally thought that a threaded server I personally think that a threaded server is a good choice.
Why not register and get more from Qiita?
We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
You can read useful information later efficiently
By "stocking" the articles you like, you can search right away
What you can do with signing up
Shota Tsuge
Shota Tsuge
@shotaTsuge
Follow
0 コメント:
コメントを投稿