Re: GraphicsMagick may collapse when binding into a server

Bob Friesenhahn <[email protected]> Tue, 21 May 2013 08:54:41 -0500 (CDT)
Newsgroups gmane.comp.video.graphicsmagick.bugs
Message-ID <[email protected]>
On Tue, 21 May 2013, Feng Liyuan wrote:

> Hi,
> I'm running my code on Linux(opensuse) with the latest GraphicsMagick.
> 
> My test code is provided as attach.
> 
> It contains a Makefile after you unzip this.
> 
> If you've installed golang, you can run ` make runserver ` to start the test server and then run ` make runpressure ` to do
> the stress test
> In this test, I opened 10 goroutines to request the server concurrently and the server went down.

I will take a look, but it might not be until this weekend.

In the mean time, perhaps you can do some investigation for me.  I am 
not very familiar with the Go language.  In the concurrency section of 
the Tour of Go, I see mention of Goroutines and it describes it as a 
"lightweight thread managed by the Go runtime".  The FAQ at 
"http://golang.org/doc/faq#goroutines" suggests that goroutines are 
not the same as "threads".

GraphicsMagick uses locking mechanisms from POSIX threads (pthreads). 
If goroutines are not compatible with POSIX threads then the locking 
mechanisms used in GraphicsMagick won't work reliably.  When OpenMP is 
enabled, GraphicsMagick also uses OpenMP's locking mechanisms between 
OpenMP worker threads.

I am getting the impression that goroutines use POSIX threads to gain 
concurrent access to OS system calls but that goroutines themselves 
are light-weight threads where there can be many more goroutines 
active than POSIX threads.  If this is the case then this would cause 
a problem.

There is substantial evidence of this in the article at 
"http://lwn.net/Articles/361454/".

It seems that GraphicsMagick semaphores would need to be 
re-implemented for Go so that they will usefully block goroutines and 
not just POSIX threads.  Alternatively, maybe there is some pragma 
which can be used to tell the Go implementation to use a POSIX thread 
per goroutine when invoking GraphicsMagick functions similar to what 
is done with OS calls.

Bob
-- 
Bob Friesenhahn
[email protected], http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/

------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may