Re: [go-nuts] Re: Go app using 1 thread when GOMAXPROCS is 4 on Windows 7 in VirtualBox

2017-02-27 Thread Jesper Louis Andersen
On Mon, Feb 27, 2017 at 8:51 PM Mark  wrote:

> It was my own fault:-(
>

On the other hand, it was great that you found it! Your intuition was right
as well: something was amiss. Science happens whenever something is figured
out :)

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Go app using 1 thread when GOMAXPROCS is 4 on Windows 7 in VirtualBox

2017-02-27 Thread Mark
It was my own fault:-(
I'm now almost maxing out the CPUs. Basically, I'd created some goroutines 
to do work but forgot to call 'go' at one stage of my pipeline so that 
blocked.

On Monday, February 27, 2017 at 7:20:48 PM UTC, Guillermo Estrada wrote:
>
> Yeah it probably is, even while creating a lot of Goroutines, if your code 
> spends too much time allocating memory and such, it won't be reflected in 
> the CPU usage.
> Anyway, for what it's worth you can always check all that at runtime if 
> you run into doubts again.
>
> https://golang.org/pkg/runtime/
>
> runtime.NumCPU()
> will report the logical CPU count and
> runtime.GOMAXPROCS(n int) int
> will set the MAX number of threads at runtime.
>
>
> On Monday, February 27, 2017 at 1:13:33 PM UTC-6, Mark wrote:
>>
>> Yes, in VirtualBox on this machine I have Processors set to 4 and the 
>> Execution Cap set to 100% (i.e., no limit). I've also tried it on a real 
>> Windows 7 machine which has 2 cores & that only uses 1 thread and I've 
>> tried it on another VirtualBox, again it only uses 1 thread.
>>
>> I've now tried the du4 example from "The Go Programming Language" book. 
>> My code is based on this example, but whereas du4 briefly peaks at 70-80% 
>> CPU my own code never exceeds 50%. So I guess the problem is with my code:-(
>>
>> On Monday, February 27, 2017 at 6:59:11 PM UTC, Guillermo Estrada wrote:
>>>
>>> Are you sure your virtual machine has 4 cores assigned? You might have 4 
>>> cores, but when you create the VM you can assign any number of cores to it 
>>> (1 being default IIRC).
>>>
>>> On Monday, February 27, 2017 at 12:39:31 PM UTC-6, Mark wrote:

 I just tried this on an old Windows 7-32bit machine which reports 
 GOMAXPROCS of 2 but only one is ever used.

 On Monday, February 27, 2017 at 5:32:17 PM UTC, Mark wrote:
>
> I have a Go app that only uses 1 thread when GOMAXPROCS is 4 on 
> Windows 7-64bit inside VirtualBox even though I can have up to 20 
> goroutines. Is this a known problem? And is there a solution that can 
> force 
> Go to use all 4 CPUs? (The underlying hardware is a 64-bit i7.)
> Thanks.
>


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Go app using 1 thread when GOMAXPROCS is 4 on Windows 7 in VirtualBox

2017-02-27 Thread Mark
Yes, in VirtualBox on this machine I have Processors set to 4 and the 
Execution Cap set to 100% (i.e., no limit). I've also tried it on a real 
Windows 7 machine which has 2 cores & that only uses 1 thread and I've 
tried it on another VirtualBox, again it only uses 1 thread.

I've now tried the du4 example from "The Go Programming Language" book. My 
code is based on this example, but whereas du4 briefly peaks at 70-80% CPU 
my own code never exceeds 50%. So I guess the problem is with my code:-(

On Monday, February 27, 2017 at 6:59:11 PM UTC, Guillermo Estrada wrote:
>
> Are you sure your virtual machine has 4 cores assigned? You might have 4 
> cores, but when you create the VM you can assign any number of cores to it 
> (1 being default IIRC).
>
> On Monday, February 27, 2017 at 12:39:31 PM UTC-6, Mark wrote:
>>
>> I just tried this on an old Windows 7-32bit machine which reports 
>> GOMAXPROCS of 2 but only one is ever used.
>>
>> On Monday, February 27, 2017 at 5:32:17 PM UTC, Mark wrote:
>>>
>>> I have a Go app that only uses 1 thread when GOMAXPROCS is 4 on Windows 
>>> 7-64bit inside VirtualBox even though I can have up to 20 goroutines. Is 
>>> this a known problem? And is there a solution that can force Go to use all 
>>> 4 CPUs? (The underlying hardware is a 64-bit i7.)
>>> Thanks.
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Go app using 1 thread when GOMAXPROCS is 4 on Windows 7 in VirtualBox

2017-02-27 Thread Guillermo Estrada
Yeah it probably is, even while creating a lot of Goroutines, if your code 
spends too much time allocating memory and such, it won't be reflected in 
the CPU usage.
Anyway, for what it's worth you can always check all that at runtime if you 
run into doubts again.

https://golang.org/pkg/runtime/

runtime.NumCPU()
will report the logical CPU count and
runtime.GOMAXPROCS(n int) int
will set the MAX number of threads at runtime.


On Monday, February 27, 2017 at 1:13:33 PM UTC-6, Mark wrote:
>
> Yes, in VirtualBox on this machine I have Processors set to 4 and the 
> Execution Cap set to 100% (i.e., no limit). I've also tried it on a real 
> Windows 7 machine which has 2 cores & that only uses 1 thread and I've 
> tried it on another VirtualBox, again it only uses 1 thread.
>
> I've now tried the du4 example from "The Go Programming Language" book. My 
> code is based on this example, but whereas du4 briefly peaks at 70-80% CPU 
> my own code never exceeds 50%. So I guess the problem is with my code:-(
>
> On Monday, February 27, 2017 at 6:59:11 PM UTC, Guillermo Estrada wrote:
>>
>> Are you sure your virtual machine has 4 cores assigned? You might have 4 
>> cores, but when you create the VM you can assign any number of cores to it 
>> (1 being default IIRC).
>>
>> On Monday, February 27, 2017 at 12:39:31 PM UTC-6, Mark wrote:
>>>
>>> I just tried this on an old Windows 7-32bit machine which reports 
>>> GOMAXPROCS of 2 but only one is ever used.
>>>
>>> On Monday, February 27, 2017 at 5:32:17 PM UTC, Mark wrote:

 I have a Go app that only uses 1 thread when GOMAXPROCS is 4 on Windows 
 7-64bit inside VirtualBox even though I can have up to 20 goroutines. Is 
 this a known problem? And is there a solution that can force Go to use all 
 4 CPUs? (The underlying hardware is a 64-bit i7.)
 Thanks.

>>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Go app using 1 thread when GOMAXPROCS is 4 on Windows 7 in VirtualBox

2017-02-27 Thread Jesper Louis Andersen
Also, to plug a possible hole: what is the parallelism[0] of your solution?

It might be that the coded solution is built such that only one goroutine
can run at any time. Thus, the critical path (the span) through the program
can only ever utilize a single core out of the 4 possible. You also need
enough work to actually fill a single core up and saturate it. If you have
lots of communication to other systems, and you spend most of your time
waiting for some proxy-task to complete, it would make sense that your
program never gets above the utilization of a single CPU core.

One common problem is if you have lots of channels which are unbuffered.
Hence, a sender has to wait for a receiver to be ready. If you are unlucky,
this could essentially tie your program up in a way such that only a single
processor core can run at the same time. Adding some buffers will help, but
make sure that your system can handle the inherent asynchronicity when
doing so.



[0] https://en.wikipedia.org/wiki/Analysis_of_parallel_algorithms

On Mon, Feb 27, 2017 at 7:59 PM Guillermo Estrada 
wrote:

> Are you sure your virtual machine has 4 cores assigned? You might have 4
> cores, but when you create the VM you can assign any number of cores to it
> (1 being default IIRC).
>
>
> On Monday, February 27, 2017 at 12:39:31 PM UTC-6, Mark wrote:
>
> I just tried this on an old Windows 7-32bit machine which reports
> GOMAXPROCS of 2 but only one is ever used.
>
> On Monday, February 27, 2017 at 5:32:17 PM UTC, Mark wrote:
>
> I have a Go app that only uses 1 thread when GOMAXPROCS is 4 on Windows
> 7-64bit inside VirtualBox even though I can have up to 20 goroutines. Is
> this a known problem? And is there a solution that can force Go to use all
> 4 CPUs? (The underlying hardware is a 64-bit i7.)
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Go app using 1 thread when GOMAXPROCS is 4 on Windows 7 in VirtualBox

2017-02-27 Thread Guillermo Estrada
Are you sure your virtual machine has 4 cores assigned? You might have 4 
cores, but when you create the VM you can assign any number of cores to it 
(1 being default IIRC).

On Monday, February 27, 2017 at 12:39:31 PM UTC-6, Mark wrote:
>
> I just tried this on an old Windows 7-32bit machine which reports 
> GOMAXPROCS of 2 but only one is ever used.
>
> On Monday, February 27, 2017 at 5:32:17 PM UTC, Mark wrote:
>>
>> I have a Go app that only uses 1 thread when GOMAXPROCS is 4 on Windows 
>> 7-64bit inside VirtualBox even though I can have up to 20 goroutines. Is 
>> this a known problem? And is there a solution that can force Go to use all 
>> 4 CPUs? (The underlying hardware is a 64-bit i7.)
>> Thanks.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.