Reading large file and sending it through a websocket leads to OutofMemoryError exception

1,114 views
Skip to first unread message

Vishal

unread,
Jul 31, 2012, 2:01:28 PM7/31/12
to autob...@googlegroups.com
Hi,

I am reading a large file of 25 MiB and sending it over the websocket. Just after a few seconds I get OutofMemoryError exception. Below is my code for reference

byte[] chunk = new byte[CHUNK_SIZE];
int read;
while ((read = fis.read(chunk)) != -1) {
  data.sendBinaryMessage(chunk);
  // Can't reuse chunk as it's used by socket
  chunk = new byte[CHUNK_SIZE];
}

I suspect the file read is faster than socket write. Is there any design pattern I can follow to overcome this situation.

Thanks
Vishal

Tobias Oberstein

unread,
Aug 1, 2012, 7:33:25 AM8/1/12
to autob...@googlegroups.com, Vishal
Hi Vishal,

the correct way of doing such things would be

http://autobahn.ws/python/tutorials/producerconsumer

Producer/consumer pattern and frame-based/streaming APIs are currently
only available in AutobahnPython Client + Server.

Probably this does not help you out of the box, but it points into the
right direction.

Cheers,
Tobias

Vishal

unread,
Aug 1, 2012, 10:14:50 AM8/1/12
to autob...@googlegroups.com, Vishal
Thanks Tobias and I really appreciate your work on Autobahn.

patrickbrown

unread,
Aug 4, 2012, 7:36:48 AM8/4/12
to autob...@googlegroups.com
Vishal,
Is it possible you are loosing the network connection and the data is piling up on the client side.
Pat, 

Vishal

unread,
Aug 4, 2012, 2:32:00 PM8/4/12
to autob...@googlegroups.com
Connection is intact, the problem is that the read is faster than write! For now I am creating a buffer of 4 MB to read chunks, server response creates a new space for next chunk.
Reply all
Reply to author
Forward
0 new messages