On the Go (a) server concurrency

Source: Internet
Author: User

There are a number of ways to server concurrency

1. Through multi-process or multi-threaded way, now this mode is basically no

2.epoll and IOCP callbacks in a way that doesn't fit people's habits

3. Using the co-process (lightweight threading, the cost of creating and destroying it is very small), the process is executed logically.

Which belong to Erlang and Golang are better at co-process concurrency.

Package Main

Import (
"FMT"
)

Func getresult (data []int, res chan int) {
var sum int
sum = 0
For _, V: = Range Data {
sum + = V
}
Res <-sum
}

Func Main () {

var res = make (chan int)
var data = []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Go GetResult (Data[:5], res)
Go GetResult (data[5:], RES)
Sum: = <-res
Sum + = <-res
Fmt. Println ("The answer result is", sum)
Close (RES)
}

On the Go (a) server concurrency

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.