method is really starting to be executed, remember LINQ, LINQ says, only a method such as ToList (), Count () is called, does it really start to compute, and does this look like it? In fact, inside LINQ, Iterators are used.Well, now that you have the basic elements of the implementation of the process, you can start to build, the two-part, the coprocessor and the coprocessor, the
Coprocessor is an attribute introduced by HBase 0.92.0. Use coprocessor. The ability to push some computational logic down to the HBase node, HBase is upgraded to a distributed data processing platform by a simple storage system.Coprocessor is divided into two types: observer and endpoint.Observer can change the existing client operation function. And endpoint can introduce a new client operation.ObserverTh
What exactly is a process and thread? How does the traditional network service model work? What are the relationships and differences between threads and processes? What time does the IO process occur?At the just-concluded PyCon2014 Shanghai station, Python senior engineer Xu Zhixiang from seven cow cloud storage brought together a python-based process, thread, coprocessor, synchronization, Async, callback.First, Context Switch technology briefBefore
time.sleep (1)
else:
print" thread_id ", Tid," No more Tickets "
Os._exit (0)
lock.release ()
time.sleep (1)
i =
lock=threading. Lock () for
K in range (Ten):
New_thread = Threading. Thread (target=booth,args= (k,))
New_thread.start ()
Second, the process (also known as micro-threading, fiber)
The coprocessor, unlike the preemptive scheduling of a thread, is a collaborative scheduling. The
when the read occurs. If it is eagain, then the current thread is marked as blocked on the corresponding FD, and then the dispatch function is executed.
The dispatch function needs to execute epoll (or fetch the data from the last returned result cache, reducing the number of cores caught) and read a ready FD from it. If not, the context should be blocked to at least one FD ready.
Finds the corresponding Coprocessor context object for this FD
trigger the system interface, the final performer is the system, and the operation of the coprocessor is the programmer. The significance of the existence of the process: for multi-threaded applications, the CPU by slicing the way to switch between threads of execution, thread switching takes time (save state, next continue). , only one thread is used, and a code block execution order is specified in one thread. Application scenario: When there are
‘ print ‘2‘ print ‘3‘def B(): print ‘x‘ print ‘y‘ print ‘z‘Assuming that the process is executed by the coprocessor, it can be interrupted at any time during the execution of a, and the execution of b,b may be interrupted during execution to execute a, and the result may be:12xy3zBut in a there is no call to B, so the call of the association is more difficult to understand than the function call.It seems that a, B's execution is a bit like multi-threa
process, thread, coprocessor three brothers, those things.1. Threads
Definition: A thread is the smallest unit that the operating system can perform operations on.
Self-Understanding: Thread open, shared resources, thread is the system's call resource order, process is directly to the CPU, is CPU-based.
Feature decision usage (multithreading)
2. Process
Definition: A program cannot run on its own, only the p
lightweight coprocessor that accesses Python in the form of a C extension module. Greenlet all run inside the main program operating system process, but they are dispatched in a collaborative manner.# usage g1=gevent.spawn (func,1,,2,3,x=4,y=5) creates a co-object g1,spawn the first argument in parentheses is the function name, such as Eat, which can be followed by multiple arguments, which can be positional arguments or keyword arguments. Are all pa
)BreakElseTime.sleep (3)Print (thread_lists)Print (' Process pool is full ')For ths in thread_lists:If not ths.is_alive ():Thread_lists.remove (THS)For ths in thread_lists:Ths.join ()Def custom_run ():Dou = Dou ()For page in range (1, 11):Dou.begin_by_page (page)Start_time = Datetime.datetime.now ()Run ()Over_time = Datetime.datetime.now ()The_time = Over_time-start_timePrint (The_time)#多线程10页时间: 0:01:04.329867#啥也不加10页的时间: 0:05:48.150459#多进程10页0:01:23.375896#多进程加线程 0:01:19.268139This code for th
This is a section of the code that analyzes the LUA coprocessor (collaboration program, Coroutine) from the LUA Reference manual interface (slightly modified):
Copy Code code as follows:
function foo (a)
Print ("foo", a)
Return Coroutine.yield (2*a)
End
CO = coroutine.create (function (a,b)Print ("Co-body1", A, B)Local r = foo (a+1)Print ("Co-body2", R)Local r, s = Coroutine.yield (A+b, A-b)Print ("Co-body3", R, s)return B,
transfer of control is temporary and voluntary, and our function will regain control in the future.For details, see: Explaining ' yield ' and ' generators ' (generator)III. Multi-process1, sub-process (subprocess package)In Python, fork a child process through the subprocess package, and run an external program.The OS module is the first to be considered when invoking the system's commands. Use Os.system () and Os.popen () to operate. However, these two commands are too simple to perform comple
everywhere to write code everywhere to find, directly a function inside, in fact, the principle is very simple, unity in the process will actively invoke the implementation of IEnumerator (iterator) MoveNext function, we go to implement this interfaceAnd then in the MoveNext function to determine whether the service side of the message returned, so that through yeild cooperation, so that the process is simplified. Also very easy to understand, simple and clear.Another hint: The iterator loop to
When you stop itself inside the process, the subsequent block of code continues to execute until the yield statement is encountered.Tested: Stopping the process means that the yield is stopped, so the statement after the yield is not executed after the process has been stopped.The code is as follows:1 usingUnityengine;2 usingSystem.Collections;3 4 Public classTest:monobehaviour {5 6 voidStart () {7Startcoroutine ("Method");8 }9 Ten IEnumerator Method () { OneStopcoroutine ("Method"); AD
method to return, and the return value of the UP method indicates whether the Pauseable method returns normally or pauses. Because the up method internally depends on whether the ispausing variable value in fiber and the stack frame of this function Statestack[istack] is NULL to determine if the pause is paused, and whether the function stack frame has been saved. If it is pausing__no_state, indicating that the function is paused, the function has not saved the stack frame, you need to use this
list waits, this will be done in a flash, because each task in the code above has been executed .P.shutdown (wait=True)#Time Efficiency3.124636650085449time efficiency of the process pool
Summarize:If the number of processes in the machine can withstand the more open, the faster the execution efficiency! 1. Lightweight task multi-process and process pool execution is not very efficient; Because the time to open the process when the multi-process is open And CPU switching time can b
This is a section of the code that analyzes the LUA coprocessor (collaborative program, Coroutine):
function foo (a)
print ("foo", a) return
Coroutine.yield (2*a)
end
CO = coroutine.create (function , b)
print ("Co-body1", A, b)
r = foo (a+1)
print ("Co-body2", R) Local
r, s = Coroutine.yie LD (A+B, a-b)
print ("Co-body3", R, s) return
B, "end" end
) print ("
1----")
print ("main", Corou Tine.resume (Co, 1,) print ("
2----") print ("
main", Coroutine
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.