Haivision / srtgo

Go bindings for SRT. Advantages of SRT technology for an easy to use programming language
Mozilla Public License 2.0
185 stars 52 forks source link

Optimize error handling & improve non-blocking performance #37

Closed gizahNL closed 3 years ago

gizahNL commented 3 years ago

This expands upon #35

For the read & write calls the error fetching is moved into one C call, reducing cgo calls (and additional performance costs of those).

non-blocking mode is improved by first trying to write/read and checking if we are returned an AGAIN error type, only then we start to poll and try again after the socket becomes readable/writable.

iSchluff commented 3 years ago

Calling read/write before epoll seems interesting. Does libsrt even ensure that read/write do not block if you didn't poll before?

gizahNL commented 3 years ago

Calling read/write before epoll seems interesting. Does libsrt even ensure that read/write do not block if you didn't poll before?

According to the SRT API Documentation it returns SRT_EASYNCRCV (reading) or SRT_EASYNCSND (writing) when calling functions that would block. So from what I'd expect it should be safe to try first before polling and trying again, in native C the overhead of polling would be more limited but from what I've gathered there is quite a overhead when calling into C from go, so the advise is to limit those calls.

jeoliva commented 3 years ago

There is some pending conflict after the latest PR merge.

gizahNL commented 3 years ago

I just rebased, should be good now :)

jeoliva commented 3 years ago

@gizahNL, one question (just curious). As you did with error management to reduce the number of cgo calls, do you think it would make sense to also move srt_epoll_uwait calls to the C function?

gizahNL commented 3 years ago

@gizahNL, one question (just curious). As you did with error management to reduce the number of cgo calls, do you think it would make sense to also move srt_epoll_uwait calls to the C function?

It's definitely possible, though I think there is a bigger gain in moving those calls into a central pollserver that does the polling for all sockets, as that would limit the amount of cgo calls that can block. (see my other WIP PR)