large PUTs, setting Mojo::Asset::File->tmpdir dynamically

103 views
Skip to first unread message

Brian Duggan

unread,
Nov 9, 2011, 3:51:50 PM11/9/11
to mojol...@googlegroups.com
Hi All,

I have an application to which multiple very large files
are PUT simultaneously, so I'd like to set the tmpdir used
by Mojo::Asset::File dynamically based on the request
headers. What's the best way to do this?

I tried an after_build_tx hook which modifies $tx
to use an object which inherits from Mojo::Message::Request
and has content which inherits from Mojo::Content::Single
and then sometimes sets MOJO_TMPDIR in parse() before
calling SUPER::parse(), but this doesn't seem like a
good solution. (Mostly since this technique stopped working in
recent releases for reasons that I haven't yet figured out.)

Maybe there's a simpler way to handle this with a callback
for the content, or "subscribing" to read events for the
incoming message/request/content?

thanks
Brian

Sebastian Riedel

unread,
Nov 9, 2011, 4:25:24 PM11/9/11
to mojol...@googlegroups.com
Maybe there's a simpler way to handle this with a callback
for the content, or "subscribing" to read events for the
incoming message/request/content?

I've just added an experimental event that should make this trivial.


Brian Duggan

unread,
Nov 9, 2011, 5:47:23 PM11/9/11
to mojol...@googlegroups.com
On Wednesday, November 9, Sebastian Riedel wrote:
> > Maybe there's a simpler way to handle this with a callback
> > for the content, or "subscribing" to read events for the
> > incoming message/request/content?
>
> I've just added an experimental event that should make this trivial.
>
> https://github.com/kraih/mojo/commit/871d0f550cdebd2724b8f176749db85cbdcf3518

Thanks!

One minor change request (to be able to set tmpdir before adding a chunk) :

diff --git a/lib/Mojo/Asset/Memory.pm b/lib/Mojo/Asset/Memory.pm
index 864c755..29eff6d 100644
--- a/lib/Mojo/Asset/Memory.pm
+++ b/lib/Mojo/Asset/Memory.pm
@@ -20,8 +20,9 @@ sub add_chunk {
my ($self, $chunk) = @_;
$self->{content} .= $chunk if defined $chunk;
return $self unless $self->size > $self->max_memory_size;
- my $file = Mojo::Asset::File->new->add_chunk($self->slurp);
+ my $file = Mojo::Asset::File->new;
$self->emit(upgrade => $file);
+ $file->add_chunk($self->slurp);
return $file;
}

Sebastian Riedel

unread,
Nov 9, 2011, 6:04:19 PM11/9/11
to mojol...@googlegroups.com
One minor change request (to be able to set tmpdir before adding a chunk) ...

Oh, of course. :)

Brian Duggan

unread,
Nov 10, 2011, 10:15:25 AM11/10/11
to mojol...@googlegroups.com
On Wednesday, November 9, Sebastian Riedel wrote:
> > One minor change request (to be able to set tmpdir before adding a chunk) ...
>
> Oh, of course. :)
>
> https://github.com/kraih/mojo/commit/84bc09df465a225cc1fc7912929dfde3c06e19c3

Great, this works. Except sometimes it doesn't :

https://gist.github.com/1355027
https://gist.github.com/1355071

Brian

Brian Duggan

unread,
Nov 10, 2011, 1:23:24 PM11/10/11
to mojol...@googlegroups.com
On Thursday, November 10, Brian Duggan wrote:
> Great, this works. Except sometimes it doesn't :
>
> https://gist.github.com/1355027
> https://gist.github.com/1355071

Looks like the latest changes in github fix
both of these.

Thanks a lot!
Brian

sri

unread,
Nov 10, 2011, 3:17:13 PM11/10/11
to Mojolicious
> Looks like the latest changes in github fix
> both of these.

It works now because i've slightly changed the way we handle
MOJO_MAX_MEMORY_SIZE, but i strongly advice against using globals if
there are more fine grained controls available.

hook after_build_tx => sub { shift->req->content->asset-
>max_memory_size(2) };

--
sebastian
Reply all
Reply to author
Forward
0 new messages