I have a collection of DB workers behind a router, and I would like them to share a scala-redis connection pool. My inclination is to have the supervisor own the pool and provide it to the constructor of the workers, but this violates the actor-sharing-state principal. I am wondering what the recommended approach would be?
//What I would like to do in essence:class RedisActor extends Actor {@volatileval pool = new RedisClientPool(...)override def onStart() {val props = Props(new RedisWorker(pool) // <----------- Not ok?).withRouter(...)actorOf(props)}}
--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/agxSpdtg2IsJ.
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.
Hi Nathan!
On Thu, May 3, 2012 at 8:47 PM, Nathan Stults <plasti...@gmail.com> wrote:
I have a collection of DB workers behind a router, and I would like them to share a scala-redis connection pool. My inclination is to have the supervisor own the pool and provide it to the constructor of the workers, but this violates the actor-sharing-state principal. I am wondering what the recommended approach would be?Using a connection pool to a database is a solution, not a problem.What's the problem you're trying to solve?Cheers,√
//What I would like to do in essence:class RedisActor extends Actor {@volatileval pool = new RedisClientPool(...)override def onStart() {val props = Props(new RedisWorker(pool) // <----------- Not ok?).withRouter(...)actorOf(props)}}
--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/agxSpdtg2IsJ.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.
Good question - I don't have a particular problem, I was just trying to keep a bound on the number of client connections created by my app. I will have a number of actors, and each actor will have a number of workers, and I was hoping to not have an ungodly number of individual connections open to the DB.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/P7G48g63OSAJ.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
Represent the DB as an Actor and send messages to it?
Best regards,
giovanni
--
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.
Thanks, Victor, for your reply.
What do you mean for "creating a Router"?
You should consider the potential race condition.If you have a single DB Actor then sequencing is guaranteed. Actor A says "Update record 12, set b = 10" and then says "Update record 12, set b = 14" then eventually b = 14. With a router, those two requests will go to arbitrary back-end routers. There is no longer a guaranteed ordering.
--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/Ifwzyg4pXZAJ.
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.
Not sure what the mechanics of a move are, but if the “pool” variable was marked as transient it seems like it should work OK. A new DBPool would just get instantiated after the move.
Or is the issue that the move could invalidate the original actor with futures still pending?
Would it make sense to use Futures w/some appropriate executor to allow use of the driver provided connection pools?class DB extends Actor {@volatileprivate val pool = new DBPool(...)def receive = {case cmd : SomeCommand => exec(...) pipeTo sender...}def exec[T](body : DBClient => T) : T = {implicit val execCtx = getDispatcherFromConfig("my-configured-dispatcher") <--- is this possible?
Future { pool.withClient { client => body(client) } }}}
It should allow any kind of appropriate threading model. Or is this just another form of leaking actor state?
On Friday, May 4, 2012 1:34:47 AM UTC-7, Giovanni wrote:On Fri, May 4, 2012 at 3:11 AM, √iktor Ҡlang <viktor...@gmail.com> wrote:Represent the DB as an Actor and send messages to it?
I used a similar approach. However, in order to scale up my application in the future, instead of using a single actor for representing the DB, I used a master DB actor, which creates a router with a configurable number of DB actors.
Each DB actor will open a connection to the DB and will process the messages coming from the master DB actor through the router.
Is this a good solution? Or are there any problems with this approach?
Best regards,
giovanni
--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/Ifwzyg4pXZAJ.
so were there any conclusions here? i think the original question is a good one.it seems mostly pointless to have a single actor "representing a database" that maintains a pool of connections when message processed sequentially?
especially if each message is processed synchronously due to not using futures ("What would happen if the Actor was moved to another node at runtime?").
so one solution discussed was: create a (round robin) router "representing a database" which spawns a number of routees, each maintaining a connection pool of 1 to the database. (using a connection pool library just to get the idle connection/test connection stuff for free).
any other/better solutions?
--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/NpHpzCPKGrYJ.
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.
so one solution discussed was: create a (round robin) router "representing a database" which spawns a number of routees, each maintaining a connection pool of 1 to the database. (using a connection pool library just to get the idle connection/test connection stuff for free).
On Sun, May 6, 2012 at 6:44 PM, Jason Mason <jason....@gmail.com> wrote:so were there any conclusions here? i think the original question is a good one.it seems mostly pointless to have a single actor "representing a database" that maintains a pool of connections when message processed sequentially?I didn't say that he couldn't spawn a child for every connection.especially if each message is processed synchronously due to not using futures ("What would happen if the Actor was moved to another node at runtime?").This would be fine as long as the DB-actor always was moved if a child is moved, so children always stay at the same node as the DB-actor.so one solution discussed was: create a (round robin) router "representing a database" which spawns a number of routees, each maintaining a connection pool of 1 to the database. (using a connection pool library just to get the idle connection/test connection stuff for free).That's worse than my solution since in my solution the DB actor can supervise the connection-actors, but in the router approach someone else has to be the parent(supervisor).
Cheers,√any other/better solutions?--To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/NpHpzCPKGrYJ.
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
Akka Tech Lead
On Sun, May 6, 2012 at 6:44 PM, Jason Mason wrote:so were there any conclusions here? i think the original question is a good one.it seems mostly pointless to have a single actor "representing a database" that maintains a pool of connections when message processed sequentially?I didn't say that he couldn't spawn a child for every connection.especially if each message is processed synchronously due to not using futures ("What would happen if the Actor was moved to another node at runtime?").This would be fine as long as the DB-actor always was moved if a child is moved, so children always stay at the same node as the DB-actor.so one solution discussed was: create a (round robin) router "representing a database" which spawns a number of routees, each maintaining a connection pool of 1 to the database. (using a connection pool library just to get the idle connection/test connection stuff for free).That's worse than my solution since in my solution the DB actor can supervise the connection-actors, but in the router approach someone else has to be the parent(supervisor).
Roland Kuhn
Typesafe – The software stack for applications that scale.
twitter: @rolandkuhn