XmlHttpRequest from web worker

1,598 views
Skip to first unread message

Anton Podviaznikov

unread,
Jul 22, 2011, 10:08:53 AM7/22/11
to Chromium HTML5
Hi,

Is there any limitation for using XmlHttpRequest from web workers?

I need the possibility to upload part of the file (so I have sliced
blob).

The code for worker is below.
var content=event.data.content,
xhr=new XMLHttpRequest();

xhr.open('PUT',resource,false);//request is synchronous. false as
last parameters was set

xhr.onload=function(e){
postMessage('Loaded');
};
xhr.upload.onprogress=function(e){
if(e.lengthComputable){
postMessage({loaded:e.loaded,total:e.total});
}
};
xhr.send(content);

The problem here with variable content. It's Blob. Probably I need to
convert it first to binary string, then pass to worker and xhr.send.
Am I right?

What types of data can be send via xhr.send(); Where I can find
documentation?

Thank you for help?

Best regards,
Anton Podviaznikov

Anton Podviaznikov

unread,
Jul 22, 2011, 10:08:53 AM7/22/11
to Chromium HTML5

Eric Bidelman

unread,
Jul 22, 2011, 5:08:08 PM7/22/11
to Anton Podviaznikov, Chromium HTML5
There is good info on the supported formats for send():

The type of data you can send to/from a work is limited.
Passing a Blob isn't really possible b/c it is not serializable type.
My suggestion would be to read the file/blob as an arrayBuffer
or binary string. Once you have bytes in the worker, you could
reconstructed a typed array or blob from the serialized arrayBuffer.


Eric

--
You received this message because you are subscribed to the Google Groups "Chromium HTML5" group.
To post to this group, send email to chromiu...@chromium.org.
To unsubscribe from this group, send email to chromium-html...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-html5/?hl=en.




--
Eric Bidelman | Senior Developer Programs Engineer | e.bid...@google.com 

Anton Podviaznikov

unread,
Jul 23, 2011, 3:45:56 PM7/23/11
to Chromium HTML5
Hi,

Thank you for answer.
It worked great when passed binary string to worker and than
reconstruct blob(array buffer don't work as I understand because of
mentioned bugs).

I have one more question about workers:

I want to upload some big file(let say 50 MB) on server. So I sliced
it on parts (each 10 MB) and send separately. This scenario is working
well.

Does it make sense to use web workers here: create new worker for each
request that will upload part of the file.


Any way to speed up upload process (ideas/suggestion)? What is the
best number of parts on which I should slice file in my case (for each
part browser will send new request to server, so is there any
"desired" number of requests)?

Thank you in advance for any help.

Best regards,
Anton Podviaznikov


On Jul 22, 11:08 pm, Eric Bidelman <ericbidel...@chromium.org> wrote:
> There is good info on the supported formats for send():http://www.html5rocks.com/en/tutorials/file/xhr2/
>
> The type of data you can send to/from a work is limited.
> Passing a Blob isn't really possible b/c it is not serializable type.
> My suggestion would be to read the file/blob as an arrayBuffer
> or binary string. Once you have bytes in the worker, you could
> reconstructed a typed array or blob from the serialized arrayBuffer.
>
> Star this bug:http://code.google.com/p/chromium/issues/detail?id=73313
>
> Eric
>
> On Fri, Jul 22, 2011 at 7:08 AM, Anton Podviaznikov
> <podviazni...@gmail.com>wrote:
> > To post to this group, send email to chromium-ht...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-html5+unsubscr...@chromium.org.
> > For more options, visit this group at
> >http://groups.google.com/a/chromium.org/group/chromium-html5/?hl=en.
>
> --
> Eric Bidelman | Senior Developer Programs Engineer | e.bidel...@google.com

Eric Bidelman

unread,
Jul 27, 2011, 8:19:56 PM7/27/11
to Anton Podviaznikov, Chromium HTML5
On Sat, Jul 23, 2011 at 12:45 PM, Anton Podviaznikov <podvia...@gmail.com> wrote:
Hi,

Thank you for answer.
It worked great when passed binary string to worker and than
reconstruct blob(array buffer don't work as I understand because of
mentioned bugs).

I have one more question about workers:

I want to upload some big file(let say 50 MB) on server. So I sliced
it on parts (each 10 MB) and send separately. This scenario is working
well.

Does it make sense to use web workers here: create new worker for each
request that will upload part of the file.

XHR is already async. I'm not really sure you'd gain much by spawning a separate worker for each upload chunk. Depending on the chunk size, the overhead of creating each worker and passing it a binary string might not be worth it.

I'd do some experimentation. Your UI might be a bit speedier using Workers.
 


Any way to speed up upload process (ideas/suggestion)? What is the
best number of parts on which I should slice file in my case (for each
part browser will send new request to server, so is there any
"desired" number of requests)?

That really depends on what your server can handle.
 
To post to this group, send email to chromiu...@chromium.org.
To unsubscribe from this group, send email to chromium-html...@chromium.org.



--
Eric Bidelman | Senior Developer Programs Engineer | e.bid...@google.com 

Anton Podviaznikov

unread,
Jul 28, 2011, 4:28:15 PM7/28/11
to Chromium HTML5
Thanks.

I did some small tests and got no benefits of using web workers for
file upload.

P.S. But of course maybe more tests can show some small difference.

One more time thanks for the help!

On Jul 28, 2:19 am, Eric Bidelman <ericbidel...@chromium.org> wrote:
> On Sat, Jul 23, 2011 at 12:45 PM, Anton Podviaznikov <podviazni...@gmail.com

nigilan

unread,
Jun 19, 2012, 8:02:12 AM6/19/12
to chromiu...@chromium.org
Hi, I am experiencing the same prob. XHR and Webworkers, is there any improvement? can we implement? pls help
Reply all
Reply to author
Forward
0 new messages