Hi there,
I have been thinking (well - it's not always a good idea ;) some
different schemes to deploy a large scale Symfony2 application in a
cloud environment and spreading application's components across the
network in different hosts. Gearman (www.gearman.org) is very good
tool to delegate simple tasks to worker processes. I do really like
the way dependency injection, service definition and references are
done in Symfony2. After some free-run coding, I have gone through some
steps that I'd like to share - in the end I also have some question.
In my first trial, I created a gearman bundle that published itself as
gearman service inside the symfony application. For example, a
registration e-mail message sending could easily be done inside my
Symfony2 application (inside a proper Controller) with:
$this->get('gearman')->doBackground('send_registration_email',
array('recipient' => '[email protected]'));
Well, pretty good start as I could easily delegate a time consuming e-
mail sending process to another host or hosts. However, the
registration e-mail message could not include any personal data in
this way or I should have built them in Controller and dispatch all
details for the gearman task.
I ended up to make a registration service that initially validates the
user submitted registration data, saves it to the database and then
does all further tasks in background. The registration service could
return control to the calling Controller right after the submitted
data is saved to the database, thus the user's browser will also get a
response as soon as possible. Registration service could have service
references to gearman service (to fork the process to background) as
well as doctrine or other services (to lookup and save data).
Well, this second option is better than first. However, now I somehow
need to write a completely different component to run the
"finalize_registration" job, delegated to the gearman server.
This is where I am somehow stuck. I do not know what would be the best
way to run the finalize_registration job, write all the code building
up the registration e-mail message, dispatching it to the smtp server
and so on. I have considered three different options:
1) Build a symfony2 console command that does all tasks and tie the
command with a gearman worker process. In this way, whenever gearmand
receives a task "finalize_registration", it feeds it to the Symfony2
console via command line. However, this is pretty hard to maintain:
when the amount of different tasks grow up, I need to start a worker
for each of the task type and carefully plan which server hosts each
of the task. Also, console commands are rather slow as the service
container and other similar things are built for one run and then
destroyed.
2) Expose background tasks as regular routes that can be called via
HTTP, for example www.example.com/tasks/finalize_registration. I would
then tie a gearman worker with curl or wget, this could make an
automatic HTTP call to the task uri. The benefit is to have all
service containers ready, as well as the whole environment available
easily - the finalize_registration task can easily refer to other
services and the configuration can be the same in whole application.
For balancing across the hosts, I can do it very easily. However, I do
not see this very elegant solution and HTTP query has some overhead in
itself also.
3) Build a symfony2 console command containing some implementation of
http://php.net/manual/en/class.gearmanworker.php, with some
intelligence deciding what tasks could be run... Well pretty good, but
I still find some unnecessary overhead from the service container and
I am not sure that this is good way to use console.
At this point, I'd be happy to receive some comments and questions -
maybe someone else has also been how to scale a Symfony2 application
easily?
Happy New Year!
Ville
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en