Speed-up of Mojolicious/Mojo on CGI

78 views
Skip to first unread message

515

unread,
Jan 3, 2011, 2:09:37 AM1/3/11
to mojol...@googlegroups.com
I think always loading Mojo::Client is too heavy in the environment
like CGI.  And, this module is not used at all when not used.

Therefore, I suggest to lazy load Mojo::Client.  Startup time has
decreased about 20% by this improvement in my environment.  Of course,
in the environment doesn't use Mojo::Client at all.

The patch is here.

--- Mojo.pm    Mon Jan 03 09:16:27 2011
+++ Mojo.pm    Mon Jan 03 14:00:07 2011
@@ -9 +8,0 @@
-use Mojo::Client;
@@ -15 +14,8 @@
-__PACKAGE__->attr(client => sub { Mojo::Client->singleton });
+__PACKAGE__->attr(
+    client => sub {
+        require Mojo::Client;
+        my $client = Mojo::Client->singleton;
+        # Client logger
+        $client->log(shift->log);
+    }
+);
@@ -38,3 +43,0 @@
-
-    # Client logger
-    $self->client->log($self->log);

And thanks to changing about issue of charset.

Sebastian Riedel

unread,
Jan 3, 2011, 11:28:58 AM1/3/11
to mojol...@googlegroups.com
> I think always loading Mojo::Client is too heavy in the environment
> like CGI. And, this module is not used at all when not used.
>
> Therefore, I suggest to lazy load Mojo::Client. Startup time has
> decreased about 20% by this improvement in my environment. Of course,
> in the environment doesn't use Mojo::Client at all.

The downside would be that it makes preloading for copy-on-write in all serious (persistent) environments harder.
Is micro optimizing for CGI really worth it?

--
Sebastian Riedel
http://blog.kraih.com
http://mojolicious.org
http://twitter.com/kraih

Charlie Brady

unread,
Jan 3, 2011, 1:48:59 PM1/3/11
to mojol...@googlegroups.com

On Mon, 3 Jan 2011, Sebastian Riedel wrote:

> > I think always loading Mojo::Client is too heavy in the environment
> > like CGI. And, this module is not used at all when not used.
> >
> > Therefore, I suggest to lazy load Mojo::Client. Startup time has
> > decreased about 20% by this improvement in my environment. Of course,
> > in the environment doesn't use Mojo::Client at all.
>
> The downside would be that it makes preloading for copy-on-write in all
> serious (persistent) environments harder.

I would think not a log harder. You know in ->start() whether the
environment is CGI or not.

> Is micro optimizing for CGI really worth it?

If 20% doesn't matter for CGI, then maybe preloading for copy-on-write
doesn't matter for other environments? Maybe performance tuning should
be left to those doing deployment, so you should make it possible
(without patching).

---
Charlie

Sebastian Riedel

unread,
Jan 3, 2011, 2:30:55 PM1/3/11
to mojol...@googlegroups.com
>> The downside would be that it makes preloading for copy-on-write in all
>> serious (persistent) environments harder.
>
> I would think not a log harder. You know in ->start() whether the
> environment is CGI or not.

And now you've created multiple mostly untested startup scenarios... a maintainability mess.
And thats only the beginning, if we make the client lazy loading why not continue with websockets or the multipart parser?
Without thinking further this might seem like a simple decision, but there are always consequences to strategic decisions like this one.
In the end everything is a tradeoff.

>> Is micro optimizing for CGI really worth it?
>
> If 20% doesn't matter for CGI, then maybe preloading for copy-on-write
> doesn't matter for other environments? Maybe performance tuning should
> be left to those doing deployment, so you should make it possible
> (without patching).

Memory consumption has nothing to do with performance in persistent environments, it's about scalability.
And those 20% are for a Hello World application, a micro benchmark without any relation to the real world.

Conclusion: This change might not result in any performance improvements for real world applications but will for sure have a serious impact on maintainability.

Charlie Brady

unread,
Jan 3, 2011, 3:14:05 PM1/3/11
to mojol...@googlegroups.com

On Mon, 3 Jan 2011, Sebastian Riedel wrote:

> Memory consumption has nothing to do with performance in persistent
> environments, it's about scalability. And those 20% are for a Hello
> World application, a micro benchmark without any relation to the real
> world.
>
> Conclusion: This change might not result in any performance improvements
> for real world applications but will for sure have a serious impact on
> maintainability.

OK, sounds good thinking.

---
Charlie

515

unread,
Jan 4, 2011, 3:16:15 AM1/4/11
to mojol...@googlegroups.com
I understand.  First I take back the patch.

And then, I object.  CGI is used seriously.  20% improved is micro
sample. That's right.  But over 10% improved satisficing sample.

Indeed, lazy load is not maintainable.  Well then, can not stop
loading completely?

Mojo::Client loaded from these packages: Mojo, ojo,
Mojolicious::Command::Get, Mojolicious::Command::Version, Test::Mojo.
But, only Mojo reused by other packages.

Mojo > Mojolicious > Mojolicious::Controller...  Mojo::Client instance
inherit or delegate like this.  But, Mojo::CLient is actually used
only once: set Mojo::Log instance at Mojo->new.

If, I suggest functions of Mojo::Client provide as Mojolicious
plugins.  Of course, 'Mojo' applications (including Mojo::HelloWorld)
will use Mojo::Client directly.

But then, Mojolicious is loading all basic plugins always currently...

I think the above.  I think functions of Mojo::Client need not to be a
basic function of Mojolicious/Mojo.  Please let me hear your thoughts.


Sorry, I can not read/write English well...

Reply all
Reply to author
Forward
0 new messages