multi-threaded python reptiles

1, procedures, processes and threads of understanding      

    Program: equivalent to an application (app), for example, an application to open on the computer.
    Process: the smallest unit to run resource (memory resources) allocation, a program can have multiple processes.
    Thread: cpu scheduling smallest unit, we must rely on the process exist. Thread no independent resources, all threads share all the resources of the process. Division of the scale is smaller than the thread of the process.

2, how to improve the program speed through multi-threaded and multi-process?

    a, a first method of improving the running speed: increase cpu utilization.

        Solution to this: cpu without rest can be done.
        Now our program usually only one main thread
        if they are in the program: obstruction. Once blocked, cpu to rest. The rest of this time, wasted resources cpu's.
        There are two ways obstruction: 1, time.sleep () 2, io operation encountered
        multiple threads: multiple tasks. cpu can switch between multiple tasks, if one thread is blocked, cpu will not rest, will deal with other threads.

    b, increase the running speed of the second approach: increasing the number of cpu processing, so that each cpu handle a task.

        multi-core cpu's. --- take advantage of multi-core cpu be resolved. --- cpu each core handle a process. - to deal with multiple processes.

    c, concurrency and parallelism.

Guess you like

Origin www.cnblogs.com/FantasticBlog/p/12327866.html