Blog Garden Homepage New Essay Contact Subscribe Management Essays-23 Articles-0 Comments-23 trackbacks-0
Age: 1 year
Follow: 1 +Follow
Most used link
- nodejs (9)
- Popular Science (7)
- libuv (5)
- v8 (3)
- Module (2)
- Multithreading (2)
- web app (1)
- mssql (1)
- mssql detailed explanation (1)
- phonegap (1)
- April 2018 (1)
- March 2018 (2)
- February 2018 (2)
- January 2018 (3)
- December 2017 (1)
- November 2017 (2)
- October 2017 (2)
- April 2017 (10)
- 1. Re: Detailed interpretation of Nodejs MSSQL
- @peiyu1988code has no problem. It is a step-by-step call example written in accordance with the official document. A very simple SQL statement, select top 1 * from table; but this error will occur when the number of columns in the table exceeds 120..... .
- --coder-- noodles
- 2. Re: Routine-Channel, the core of the Go language
- Collection Collection
- 3. Re: Detailed interpretation of Nodejs MSSQL
- @coder--The noodle call stack exceeds the threshold, which usually appears when the function is called in a loop. Please confirm your code. ...
- 4. Re: Detailed interpretation of Nodejs MSSQL
- Hello, first of all, I am very admired and happy to see your Chinese detailed explanation. I encountered a problem with mssql during development. Maybe the English reading ability is too poor and I haven't found a solution, so I would like to ask for some advice. The query of mssql executes select * from ......
- --coder-- noodles
- 5. Re: Facebook's mega-level image storage and the principle of millions-level image query per second
- Cow breaking
Read the leaderboard
- 1. Nodejs true. Multi-threaded processing(5287)
- 2. Nodejs intensive CPU solution (1455)
- 3. Facebook's mega-level image storage and the principle of millions-level image query per second (1248)
- 4. Detailed interpretation of Nodejs MSSQL(1226)
- 5. Web App adapts to iPhoneX (1213)
- 1. Nodejs true. Multi-threaded processing (3)
- 2. The operating principle of Nodejs-call (3)
- 3. The operating principle of Nodejs-Architecture (3)
- 4. Web App adapts to iPhoneX(3)
- 5. Detailed interpretation of Nodejs MSSQL (3)
- 1. Facebook's mega-level image storage and the principle of millions-level image query per second (13)
- 2. The operating principle of Nodejs-popular science (10)
- 3. The operating principle of Nodejs-function callback (7)
- 4. The operating principle of Nodejs-Architecture (6)
- 5. The operating principle of Nodejs-module loading (6)
The Go language provides support for concurrent programming through routines.
(1) Goroutine is a function of the Go language runtime, not a function provided by the operating system. Goroutine is not implemented by threads.
Example: start a routine
Go + function name can start a goroutine?
|1 2 3 4 5 6 7 8 9 10||
(2) A goroutine is a piece of code, a function entry, and a stack allocated for it on the heap. So it is very cheap, we can easily create tens of thousands of goroutines, but they are not scheduled for execution by the operating system.
(3) Except for threads blocked by system calls, the Go runtime library will start up to $GOMAXPROCS threads to run goroutines.
Example: Use GOMAXPROCS (set the number of CPUs)?
|1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32||
(4) The goroutine is cooperatively scheduled. If the goroutine will execute for a long time and is not synchronized by waiting to read or write the channel data, you need to actively call Gosched() to free the CPU.
Example: Gosched() gives up the CPU?
|1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18||
(5) Like all coroutines in other concurrent frameworks, the so-called "lock-free" advantage in goroutine is only valid in a single thread. If $GOMAXPROCS> 1 and communication between coroutines is required, the Go runtime library will be responsible for locking protection Data, this is also the reason why an example like sieve.go is slower with multiple CPUs and multiple threads.
(6) The requests to be processed by server-side programs such as Web are essentially parallel processing. Each request is basically independent, independent of each other, and almost no data interaction. This is not a concurrent programming model, but a concurrent programming framework is just Solving the complexity of its semantic expression is not to fundamentally improve the efficiency of processing. Maybe the English of concurrent connection and concurrent programming is concurrent. It is easy to produce "concurrent programming framework and coroutine can efficiently handle a large number of concurrent connections" misunderstanding.
(7) The Go language runtime encapsulates asynchronous IO, so it is possible to write servers that seem to have a lot of concurrent, but even if we adjust $GOMAXPROCS to make full use of multi-core CPU parallel processing, its efficiency is not as good as our use of IO event-driven design , Divide the appropriate proportion of the thread pool according to the transaction type. In terms of response time, collaborative scheduling is a flaw.
(8) The biggest value of goroutine is that it realizes the mapping and dynamic expansion of concurrent coroutines and actual parallel execution threads. With the continuous development and improvement of its runtime library, its performance will definitely get better and better, especially in CPU In the future with more and more cores, one day we will abandon the little performance difference for the sake of simplicity and maintainability of the code.
Routine communication: Channel
Communication between routines is through Channel; Channel is intra-process communication and does not support out-of-process communication.
|1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26||
What kind of scenarios use pipelines?
First of all, we know that Channel can communicate in routines, as in the following example:?
The above code roughly means: use the coroutine to output "Hello world" 10 times in parallel, but when you run the above code, you will find that there will be no output. This is because although the go keyword is used to create the coroutine, the main function has exited and the process has been closed before it is executed, so the coroutine that has been started will not be executed.
If you have C-related multi-threading experience, you can change the coroutine to a thread, and then call the join method of the thread to let the main thread wait for the child thread to finish executing before exiting. In the Go language, we can use the write blocking and read blocking of the pipeline to complete the behavior similar to thread join. The code is as follows:
|1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19||
Through the above code, we can complete the effect of outputting 10 lines of Hello world in parallel.
posted on 2018-04-10 19:37 peiyu1988 Reading (92) Comments (1) Edit collection
FeedBack: #1 Floor 19:40:48 2018-04-10 19:40 39479962018/4/10 mrcorrection FavoritedFavorite Support (0) against (0) Refresh comments refresh the page Top to post a comment registered user login, please login or register , visit the website home page. [Recommended] Over 500,000 VC++ source code: Large-scale configuration industrial control, power simulation CAD and GIS source code library!
[Registration] 2050 Conference-Blog Garden Programmers Reunion (5.25 Hangzhou Yunqi Town)
[Recruitment] We are serious about finding technical experts at a high price!
[Tencent Cloud] Buy domain name, get analysis + SSL certificate + build website
The latest IT news :
"Alipay" entered the HSK test questions of the Chinese Proficiency Test, foreigners went crazy on the spot
MediaTek's first quarter revenue of US$1.7 billion fell year-on-year but in line with expectations
Spotify plans to launch a new version of free music services to attract more new users
Zuckerberg explained why the founder
of Oculus VR was fired . WeChat and QQ will suspend the direct playback function of short video apps outside the chain
more news... Latest Knowledge Base articles :
written autodidact Getting Started
and programmers love
Learning to learn
Excellent people management technology trap
As a programmer, you in the end how important math
>> More Knowledge Base article .. . today in history:
2017-04-10 Nodejs true multithreading.
2017-04-10 Nodejs use Redis
Copyright 2018 peiyu1988 Powered by: blog garden templates provide: HJ blog