1
votes

I study golang scheduler in linux. I think golang using multi-thread to implement goroutine , when some goroutine is blocked in I/O(just like reading a file), other thread go on processing another goroutine . But when there is lots of I/O,I don't think thread is enough, how golang deal with it ?

I read a article http://morsmachine.dk/netpoller , it says “Go gets around this problem by using the asynchronous interfaces that the OS provides, but blocking the goroutines that are performing I/O.” . Is it like the aio_read ? It is said that there is lots of bugs with the asynchronous interfaces . And I don’t find it in the source code or I just miss it.

As we know , I understand we can use epoll to do asynchronous io for pipes and socket, but epoll can’t be used to reading or writing of regular file. And nodejs use libeio to do this for regular file. I want to know how golang do it in runtime.

1
Currently, Go handles this be using threads for file reading. I've read that in Go 1.4 this issue will be addressed properly. - Not_a_Golfer
Node.js actually uses libuv now and this will use the appropriate OS kernel notification system e.g. epoll, kqueue, select, poll or on Windows by using an IO Completion Port. I would imagine Go does something similar. - Matt Harrison

1 Answers

2
votes

Go doesn't use anything special for file I/O yet. It just creates a new thread (so that there are always GOMAXPROCS threads available for goroutines) and blocks on the operation. I think there already was some discussion going on about using AIO on the mailing list, but there were many problems at that time. The golang-nuts mailing list is probably a better place for this kind of questions.