Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang error function arguments too large for new goroutine

Tags:

go

I am running a program with go 1.4 and I am trying to pass a large struct to a go function.

go ProcessImpression(network, &logImpression, campaign, actualSpent, partnerAccount, deviceId, otherParams)

I get this error:

runtime.newproc: function arguments too large for new goroutine

I have moved to pass by reference which helps but I am wondering if there is some way to pass large structs in a go function.

Thanks,

like image 237
Gary Avatar asked Jan 29 '15 22:01

Gary


People also ask

Are goroutines blocking?

When we send data into the channel using a GoRoutine, it will be blocked until the data is consumed by another GoRoutine. When we receive data from channel using a GoRoutine, it will be blocked until the data is available in the channel.

How to handle error in Golang?

The most common way to handle errors is to return the error type as the last return value of a function call and check for the nil condition using an if statement.

How to return error From function in Golang?

Error using Errorf() in Golang We can also handle Go errors using the Errorf() function. Unlike, New() , we can format the error message using Errorf() . This function is present inside the fmt package, so we can directly use this if we have imported the fmt package. Let's see an example.

How big is a Goroutine?

Some people learn that “a goroutine takes up around 2 kilobytes”, most likely referencing the Go 1.4 release notes, and even fewer learn that this represents its initial stack size.


2 Answers

No, none I know of.

I don't think you should be too aggressive tuning to avoid copying, but it appears from the source that this error is emitted when parameters exceed the usable stack space for a new goroutine, which should be kilobytes. The copying overhead is real at that point, especially if this isn't the only time these things are copied. Perhaps some struct either explicitly is larger than expected thanks to a large struct member (1kb array rather than a slice, say) or indirectly. If not, just using a pointer as you have makes sense, and if you're worried about creating garbage, recycle the structs pointed to using sync.Pool.

like image 133
twotwotwo Avatar answered Oct 05 '22 22:10

twotwotwo


I was able to fix this issue by changing the arguments from

func doStuff(prev, next User)

to

func doStuff(prev, next *User)

The answer from @twotwotwo in here is very helpful.

like image 22
Rohman HM Avatar answered Oct 05 '22 23:10

Rohman HM