Are RS beans 'single-threaded'?

7 views
Skip to first unread message

Magnus Alvestad

unread,
Aug 29, 2010, 1:17:28 PM8/29/10
to Akka User List
I have a REST method that looks like this:

@GET
@Path("/slower")
@Produces(Array("application/xml"))
def slower() = {
log.info("Got slower call")
var a = 0
for (b <- 1 until 100000000) a += b
<ok>{a}</ok>
}

It takes appx 3 seconds to run. So after 3 seconds I get a response.
If I call it rapidly three times (say, from three tabs in my browser),
it takes nine seconds, which is what I'd expect. However, I would
expect the two subsequent calls to start (print the log.info line) and
run in parallel with the first one. That doesn't happen. Each one
completes and returns its reponse to the browser before the next one
starts. Even though they seem to run in different threads according to
the log messages!

Apologies if this is a Jersey question, I'm thinking it may have
something to do with the integration.

-Magnus

Viktor Klang

unread,
Aug 29, 2010, 1:37:30 PM8/29/10
to akka...@googlegroups.com
Hi Magnus,

I'm missing some crucial details:

What does the surrounding code look like (defs are not top-level constructs)
What version of Akka are you running?
How are you running Akka (Container or Microkernel)?


BRs


--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.




--
Viktor Klang,
Code Connoisseur
Work:   www.akkasource.com
Code:   github.com/viktorklang
Follow: twitter.com/viktorklang
Read:   klangism.tumblr.com

Magnus Alvestad

unread,
Aug 29, 2010, 3:34:27 PM8/29/10
to Akka User List
Thanks for your help, here's a more complete example. This is the
service:

package com.test

import javax.ws.rs.{GET, POST, Path, Produces, PathParam}
import se.scalablesolutions.akka.util.Logging

@Path("/slow")
class SlowService extends Logging {
@GET
@Path("/slower")
@Produces(Array("application/xml"))
def slower(@PathParam("session") session: String) = {
log.info("Got slower call")
var a = 0
for (b <- 1 until 100000000) a += b
<ok>{a}</ok>
}
}

I'm deploying it in akka 0.10. Here's my configuration file:

akka {
boot = ["com.test.Boot"]

rest {
resource_packages = ["com.test"]
port = 10998
}
remote {
server {
port = 10999
}
}
}

Let me know if there's more you need to know!

-Magnus

On 29 Aug, 19:37, Viktor Klang <viktor.kl...@gmail.com> wrote:
> Hi Magnus,
>
> I'm missing some crucial details:
>
> What does the surrounding code look like (defs are not top-level constructs)
> What version of Akka are you running?
> How are you running Akka (Container or Microkernel)?
>
> BRs
>
> On Sun, Aug 29, 2010 at 7:17 PM, Magnus Alvestad
> <magnus.alves...@gmail.com>wrote:
> > akka-user+...@googlegroups.com<akka-user%2Bunsubscribe@googlegroups .com>
> > .

Viktor Klang

unread,
Aug 29, 2010, 5:02:26 PM8/29/10
to akka...@googlegroups.com
Hey Magnus,

I'll try to have a look at this in the morning.

Stay tuned.

To unsubscribe from this group, send email to akka-user+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

Viktor Klang

unread,
Aug 30, 2010, 8:22:34 AM8/30/10
to akka...@googlegroups.com
Hey Magnus,

I've poked around this and have involved some of my friends: the Jersey lead and the former grizzly lead to try to make sense on what's going on.

I have confirmed that there are more than 1 grizzly worker, so the synchronization is not because of only one worker, but has to be done either by Grizzly or Jersey.

I'll shout as soon as I hear something,

Cheers,

Magnus Alvestad

unread,
Aug 30, 2010, 5:24:01 PM8/30/10
to Akka User List
Great, let me know if there is anything I should do; test it in s
container, with different versions etc. Or I can try to write a proper
test that exhibits the problem.

-Magnus

On Aug 30, 2:22 pm, Viktor Klang <viktor.kl...@gmail.com> wrote:
> Hey Magnus,
>
> I've poked around this and have involved some of my friends: the Jersey lead
> and the former grizzly lead to try to make sense on what's going on.
>
> I have confirmed that there are more than 1 grizzly worker, so the
> synchronization is not because of only one worker, but has to be done either
> by Grizzly or Jersey.
>
> I'll shout as soon as I hear something,
>
> Cheers,
>

Viktor Klang

unread,
Aug 31, 2010, 3:14:08 AM8/31/10
to akka...@googlegroups.com
On Mon, Aug 30, 2010 at 11:24 PM, Magnus Alvestad <magnus....@gmail.com> wrote:
Great, let me know if there is anything I should do; test it in s
container, with different versions etc. Or I can try to write a proper
test that exhibits the problem.

I have already succeeded in reproducing. Trying to pinpoint the cause :-)
 
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

Viktor Klang

unread,
Sep 3, 2010, 5:51:56 AM9/3/10
to akka...@googlegroups.com
Finally nailed the problem,

now fixed in master.

a clean-lib and an update is needed

Please note that the use of QueuedThreadPool for Jetty is not recommended,
took me quite some time to find out that ExecutorThreadPool solved the issue.

Big thanks to JF Arcand and Paul Sandoz for the input on this.

Cheers,

Christer Sandberg

unread,
Sep 3, 2010, 9:28:58 AM9/3/10
to akka...@googlegroups.com
Hi!

Is this related to Akka or should one use an ExecutorThreadPool in
other use cases as well?
I'm embedding Jetty with Jersey right now, so it would be interesting
to hear more about this.

Thanks,
Christer

Viktor Klang

unread,
Sep 3, 2010, 9:34:19 AM9/3/10
to akka...@googlegroups.com
On Fri, Sep 3, 2010 at 3:28 PM, Christer Sandberg <chr...@gmail.com> wrote:
Hi!

Is this related to Akka or should one use an ExecutorThreadPool in
other use cases as well?
I'm embedding Jetty with Jersey right now, so it would be interesting
to hear more about this.

No, this is just Jetty related. :-)
 

Christer Sandberg

unread,
Sep 3, 2010, 9:37:31 AM9/3/10
to akka...@googlegroups.com
Great timing! I'll change my code as well then ;)

Viktor Klang

unread,
Sep 3, 2010, 9:39:15 AM9/3/10
to akka...@googlegroups.com
On Fri, Sep 3, 2010 at 3:37 PM, Christer Sandberg <chr...@gmail.com> wrote:
Great timing! I'll change my code as well then ;)

Hehe, yeah, unless you want serialized services ;-)
 

Magnus Alvestad

unread,
Sep 6, 2010, 2:31:44 PM9/6/10
to Akka User List
I'm getting an exception. This is what my akka.conf looks like:

akka {
boot = ["com.norwegianpirates.Boot"]

rest {
resource_packages = ["com.norwegianpirates"]
port = 11998
}
remote {
server {
port = 11999
}
}
}

and on startup I'm getting this exception. Let me know if you need any
more info:

[main] [INFO] [2010-09-06 18:23:11,304] s.s.a.k.Kernel$$anon$1: Remote
Actors Service initialized
[main] [INFO] [2010-09-06 18:23:11,306] s.s.a.k.Kernel$$anon$1:
Creating /deploy class-loader
[main] [INFO] [2010-09-06 18:23:11,307] s.s.a.k.Kernel$$anon$1:
Attempting to start Akka REST service (Jersey)
Exception in thread "main" java.util.NoSuchElementException: None.get
at scala.None$.get(Option.scala:185)
at scala.None$.get(Option.scala:183)
at se.scalablesolutions.akka.kernel.EmbeddedAppServer
$class.onLoad(EmbeddedAppServer.scala:38)
at se.scalablesolutions.akka.kernel.Kernel$$anon$1.se
$scalablesolutions$akka$actor$BootableActorLoaderService$$super
$onLoad(Kernel.scala:27)
at se.scalablesolutions.akka.actor.BootableActorLoaderService
$class.onLoad(BootableActorLoaderService.scala:89)
at se.scalablesolutions.akka.kernel.Kernel$$anon$1.se
$scalablesolutions$akka$remote$BootableRemoteActorService$$super
$onLoad(Kernel.scala:27)
at se.scalablesolutions.akka.remote.BootableRemoteActorService
$class.onLoad(BootableRemoteActorService.scala:35)
at se.scalablesolutions.akka.kernel.Kernel$$anon$1.se
$scalablesolutions$akka$camel$CamelService$$super$onLoad(Kernel.scala:
27)
at se.scalablesolutions.akka.camel.CamelService
$class.onLoad(CamelService.scala:40)
at se.scalablesolutions.akka.kernel.Kernel$$anon
$1.onLoad(Kernel.scala:27)
at
se.scalablesolutions.akka.servlet.AkkaLoader.boot(AkkaLoader.scala:27)
at se.scalablesolutions.akka.kernel.Kernel$.boot(Kernel.scala:
26)
at se.scalablesolutions.akka.kernel.Main$.main(Kernel.scala:
14)
at se.scalablesolutions.akka.kernel.Main.main(Kernel.scala)

-Magnus

On 3 Sep, 11:51, Viktor Klang <viktor.kl...@gmail.com> wrote:
> Finally nailed the problem,
>
> now fixed in master.
>
> a clean-lib and an update is needed
>
> Please note that the use of QueuedThreadPool for Jetty is not recommended,
> took me quite some time to find out that ExecutorThreadPool solved the
> issue.
>
> Big thanks to JF Arcand and Paul Sandoz for the input on this.
>
> Cheers,
>

Jonas Bonér

unread,
Sep 6, 2010, 2:55:13 PM9/6/10
to akka...@googlegroups.com
Bad error reporting.

This is caused by not specifying AKKA_HOME by either:
export AKKA_HOME variable
-Dakka.home=...

Fixing error reporting.

> To unsubscribe from this group, send email to akka-user+...@googlegroups.com.


> For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.
>
>

--
Jonas Bonér

work: http://akkasource.org
code: http://github.com/jboner
blog:  http://jonasboner.com
twtr:  @jboner

Magnus Alvestad

unread,
Sep 6, 2010, 3:30:23 PM9/6/10
to Akka User List
Yeah, that fixed that problem. Seems to work now.

However, I've noticed a small change. Previously a file in /deploy/
root was available by HTTP on the REST port. That seems to no longer
be the case. Can I restore that behaviour, alternatively how can I add
static content to my app?

-Magnus

On 6 Sep, 20:55, Jonas Bonér <jo...@jonasboner.com> wrote:
> Bad error reporting.
>
> This is caused by not specifying AKKA_HOME by either:
> export AKKA_HOME variable
> -Dakka.home=...
>
> Fixing error reporting.
>
> ...
>
> les mer »

Viktor Klang

unread,
Sep 6, 2010, 4:08:30 PM9/6/10
to akka...@googlegroups.com, Akka User List
Magnus,

You can configure that in your microkernel.xml

Cheers!

Viktor Klang
Code Connoisseur
www.akkasource.com

Magnus Alvestad

unread,
Sep 6, 2010, 7:15:15 PM9/6/10
to Akka User List
Thanks. My app is running again now! :)

However, I still seem to have the original problem. Do I need to do
any additional configuration? I'm getting this in my log:

INF [20100906-23:10:39.461] Atmosphere: Using
se.scalablesolutions.akka.comet.AkkaBroadcaster with a Thread Pool
size of : 1

and the staggered calls themself look like this:

[pool-5-thread-13] [INFO] [2010-09-06 23:11:02,502] c.n.StatusService:
Got slower call
[pool-5-thread-30] [INFO] [2010-09-06 23:11:04,914] c.n.StatusService:
Got slower call
[pool-5-thread-6] [INFO] [2010-09-06 23:11:07,332] c.n.StatusService:
Got slower call
[pool-5-thread-11] [INFO] [2010-09-06 23:11:09,693] c.n.StatusService:
Got slower call

-Magnus

On 6 Sep, 22:08, Viktor Klang <viktor.kl...@gmail.com> wrote:
> Magnus,
>
> You can configure that in your microkernel.xml
>
> Cheers!
>
> Viktor Klang
> Code Connoisseurwww.akkasource.com
>
> ...
>
> les mer »

Viktor Klang

unread,
Sep 7, 2010, 9:01:33 AM9/7/10
to akka...@googlegroups.com
Hey Magnus,

are you using Akka master or 0.10?
What does your akka.conf look like?

To unsubscribe from this group, send email to akka-user+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

Magnus Alvestad

unread,
Sep 7, 2010, 1:59:50 PM9/7/10
to Akka User List
I'm using master (1.0-SNAPSHOT). This is my akka.conf:

akka {
boot = ["com.norwegianpirates.Boot"]

rest {
resource_packages = ["com.norwegianpirates"]
hostname = "10.249.2.51"
port = 11998
}
remote {
server {
port = 11999
}
}
}

-Magnus

On 7 Sep, 15:01, Viktor Klang <viktor.kl...@gmail.com> wrote:
> Hey Magnus,
>
> are you using Akka master or 0.10?
> What does your akka.conf look like?
>
> On Tue, Sep 7, 2010 at 1:15 AM, Magnus Alvestad
> <magnus.alves...@gmail.com>wrote:
> ...
>
> les mer »

Viktor Klang

unread,
Sep 7, 2010, 3:20:24 PM9/7/10
to akka...@googlegroups.com
On Tue, Sep 7, 2010 at 7:59 PM, Magnus Alvestad <magnus....@gmail.com> wrote:
I'm using master (1.0-SNAPSHOT). This is my akka.conf:

akka {
 boot = ["com.norwegianpirates.Boot"]

 rest {
   resource_packages = ["com.norwegianpirates"]
   hostname = "10.249.2.51"
   port = 11998
 }
 remote {
   server {
     port = 11999
   }
 }
}

Ah, but what does your akka-reference.conf look like?

I need to see your settings :-)

 
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

Magnus Alvestad

unread,
Sep 7, 2010, 3:36:48 PM9/7/10
to Akka User List
Here you go:

####################
# Akka Config File #
####################

# This file has all the default settings, so all these could be
removed with no visible effect.
# Modify as needed.

akka {
version = "1.0-SNAPSHOT" # Akka version, checked against the runtime
version of Akka.

time-unit = "seconds" # Default timeout time unit for all timeout
properties throughout the config

# These boot classes are loaded (and created) automatically when the
Akka Microkernel boots up
# Can be used to bootstrap your application(s)
# Should be the FQN (Fully Qualified Name) of the boot class
which needs to have a default constructor
boot = ["sample.camel.Boot",
"sample.rest.java.Boot",
"sample.rest.scala.Boot",
"sample.security.Boot"]

actor {
timeout = 5 # Default timeout for Future
based invocations
# - Actor: !! && !!!
# - UntypedActor:
sendRequestReply && sendRequestReplyFuture
# - TypedActor: methods
with non-void return type
serialize-messages = off # Does a deep clone of (non-
primitive) messages to ensure immutability
throughput = 5 # Default throughput for all
ExecutorBasedEventDrivenDispatcher, set to 1 for complete fairness

default-dispatcher {
type = "GlobalExecutorBasedEventDriven" # Must be one of the
following, all "Global*" are non-configurable
# - Hawt
# -
ExecutorBasedEventDriven
# -
ExecutorBasedEventDrivenWorkStealing
# -
ReactorBasedThreadPoolEventDriven
# -
ReactorBasedSingleThreadEventDriven
# - GlobalHawt
# -
GlobalExecutorBasedEventDriven
# -
GlobalReactorBasedSingleThreadEventDriven
# -
GlobalReactorBasedThreadPoolEventDriven
keep-alive-ms = 60000 # Keep alive time for threads
core-pool-size-factor = 1.0 # No of core threads ...
ceil(available processors * factor)
max-pool-size-factor = 4.0 # Max no of threads ...
ceil(available processors * factor)
executor-bounds = -1 # Makes the Executor bounded,
-1 is unbounded
allow-core-timeout = on # Allow core threads to time
out
rejection-policy = "caller-runs" # abort, caller-runs, discard-
oldest, discard
throughput = 5 # Throughput for
ExecutorBasedEventDrivenDispatcher, set to 1 for complete fairness
aggregate = off # Aggregate on/off for
HawtDispatchers
mailbox-capacity = -1 # If negative (or zero) then an
unbounded mailbox is used (default)
# If positive then a bounded
mailbox is used and the capacity is set using the property
# NOTE: setting a mailbox to
'blocking' can be a bit dangerous,
# could lead to deadlock,
use with care
}
}

stm {
fair = on # Should global transactions be fair or
non-fair (non fair yield better performance)
max-retries = 1000
timeout = 5 # Default timeout for blocking
transactions and transaction set (in unit defined by
# the time-unit property)
write-skew = true
blocking-allowed = false
interruptible = false
speculative = true
quick-release = true
propagation = "requires"
trace-level = "none"
hooks = true
jta-aware = off # Option 'on' means that if there JTA
Transaction Manager available then the STM will
# begin (or join), commit or
rollback the JTA transaction. Default is 'off'.
}

jta {
provider = "from-jndi" # Options: - "from-jndi" (means that Akka
will try to detect a TransactionManager in the JNDI)
# - "atomikos" (means that Akka
will use the Atomikos based JTA impl in 'akka-jta',
# e.g. you need the akka-jta
JARs on classpath).
timeout = 60
}

rest {
service = on
hostname = "localhost"
port = 9998
#cometSupport = "org.atmosphere.container.Jetty7CometSupport" #
Disregard autodetection, for valid values: http://doc.akkasource.org/comet
filters =
["se.scalablesolutions.akka.security.AkkaSecurityFilterFactory"] #
List with all jersey filters to use
resource_packages = ["sample.rest.scala",
"sample.rest.java",
"sample.security"] # List with all resource
packages for your Jersey services
authenticator = "sample.security.BasicAuthenticationService" # The
authentication service to use. Need to be overridden (sample now)

comet-dispatcher {
#type = "Hawt" # Uncomment if you want to use a different
dispatcher than the default one for Comet
}
# maxInactiveActivity = 60000 # Atmosphere CometSupport
maxInactiveActivity

# Uncomment if you are using the KerberosAuthenticationActor
# kerberos {
# servicePrincipal = "HTTP/loca...@EXAMPLE.COM"
# keyTabLocation = "URL to keytab"
# kerberosDebug = "true"
# realm = "EXAMPLE.COM"
# }
}

remote {
compression-scheme = "zlib" # Options: "zlib" (lzf to come), leave
out for no compression
zlib-compression-level = 6 # Options: 0-9 (1 being fastest and 9
being the most compressed), default is 6

ssl {
service = off # NOTE: This feature is not deemed production
ready and is not possible to turn on yet

# You can either use java command-line options or use the
settings below

#key-store-type = "pkcs12" # Same as -
Djavax.net.ssl.keyStoreType=pkcs12
#key-store = "yourcertificate.p12" # Same as -
Djavax.net.ssl.keyStore=yourcertificate.p12
#key-store-pass = "$PASS" # Same as -
Djavax.net.ssl.keyStorePassword=$PASS

#trust-store-type = "jks" # Same as -
Djavax.net.ssl.trustStoreType=jks
#trust-store = "your.keystore" # Same as -
Djavax.net.ssl.trustStore=your.keystore
#trust-store-pass = "$PASS" # Same as -
Djavax.net.ssl.trustStorePassword=$PASS

debug = off # This can be useful for debugging. If on, very
verbose debug, same as -Djavax.net.debug=ssl
}

server {
service = on
hostname = "localhost" # The hostname or IP that clients should
connect to
port = 9999 # The port clients should connect to
connection-timeout = 1
}

client {
reconnect-delay = 5
read-timeout = 10
reconnection-time-window = 600 # Maximum time window that a
client should try to reconnect for
}

cluster {
service = on
name =
"default" # The
name of the cluster
serializer = "se.scalablesolutions.akka.serialization.Serializer
$Java$" # FQN of the serializer class
}
}

storage {
cassandra {
hostname = "127.0.0.1" # IP address or hostname of one of
the Cassandra cluster's seeds
port = 9160 # Port to Cassandra
consistency-level = "QUORUM" # Options: ZERO, ONE, QUORUM,
DCQUORUM, DCQUORUMSYNC, ALL, ANY
}

mongodb {
hostname = "127.0.0.1" # IP address or hostname of the
MongoDB DB instance
port = 27017 # Port to MongoDB
dbname = "mydb"
}

redis {
hostname = "127.0.0.1" # IP address or hostname of the
Redis instance
port = 6379 # Port to Redis
}
}
}


On 7 Sep, 21:20, Viktor Klang <viktor.kl...@gmail.com> wrote:
> On Tue, Sep 7, 2010 at 7:59 PM, Magnus Alvestad
> <magnus.alves...@gmail.com>wrote:
> ...
>
> les mer »

Viktor Klang

unread,
Sep 7, 2010, 5:32:44 PM9/7/10
to akka...@googlegroups.com
I'm going to have a look at this asap,

this is real strange, I hate intermittent stuff like this.

Thanks for keeping an eye out,

Cheers,

> ...
>
> les mer »

--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

Reply all
Reply to author
Forward
0 new messages