Performance problems when sending small files through Java Sockets

Harvtronix

I am building a web server application that sends files of varying size from a server to a client upon request using the HTTP 1.1 protocol and chunked Transfer-Encoding.

I am using Java Sockets/ServerSockets to handle the connections. I am sending data to the client using the output stream obtained from socket.getOutputStream(). Note: I am not wrapping the socket's output stream in a BufferedOutputStream.

(I am using chrome debugger to analyze resource timings)

The problem that I am seeing is that a file of size 1285 bytes (plus headers and chunk encoding) takes well over 50ms for chrome to receive its first byte for the request. (Chrome reports a TTFB of ~50ms), followed by a quick remainder of the transfer (1-2ms) (total transfer time ~52ms)

But if I increase the size of the file to 1286 bytes, the TTFB dramatically decreases down to ~1ms. (total transfer time ~3ms)

I have tried force flushing the OutputStream at varying points along the way, including after the request headers, after chunks, and even attempting multiple flush calls at each point just for fun.

My question: Why is the transfer time so much longer for a small file as compared to any file above or equal to 1286 bytes? And what can I do to fix this performance issue?

My theory: Something in the underlying socket implementation is ignoring the Java request to flush the underlying socket's buffer, in spite of the Java calls to flush().

Khanna111

Disabling Nagle's algorithm would resolve this issue.

http://www.boundary.com/blog/2012/05/know-a-delay-nagles-algorithm-and-you/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Sending data through UDP sockets

From Dev

Problems with java sockets

From Dev

Problems with java sockets

From Dev

How are sockets sending data through packets in erlang?

From Dev

sending and recieving data through sockets in the same activity

From Dev

Sending various types of data through sockets in Python

From Dev

Sending and receiving data through sockets and ports

From Dev

sending and recieving data through sockets in the same activity

From Dev

Sending objects via java sockets

From Dev

Java sockets not sending/receiving messages

From Dev

Why isn't my Client sending data to server through sockets when I re-run the program?

From Dev

Problems with sending array through ajax

From Dev

Sending files with sockets c# client/server

From Dev

Sending large JSON files via sockets

From Dev

Download image through sockets java

From Dev

Sending ByteArray using Java Sockets (Android programming)

From Dev

Java sending and receiving file over sockets

From Dev

Sending a file with Java Sockets, losing data

From Dev

Java Sockets sending multiple objects to the same server

From Dev

Java Sockets - Sending data from client to server

From Dev

Laravel problems when sending email

From Dev

Laravel problems when sending email

From Dev

Is there a way to determine which OutputStream is currently sending through to my sockets inputstream?

From Dev

Is there a way to determine which OutputStream is currently sending through to my sockets inputstream?

From Dev

Memory problems when compressing and transferring a large number of small files (1TB in total)

From Dev

Performance problems when plotting spectrogram

From Dev

I observed a Java process running at root level through top command on my application server, will it lead to performance problems?

From Dev

Sending files from client to server using sockets in C

From Dev

Sending an object through a socket in java

Related Related

  1. 1

    Sending data through UDP sockets

  2. 2

    Problems with java sockets

  3. 3

    Problems with java sockets

  4. 4

    How are sockets sending data through packets in erlang?

  5. 5

    sending and recieving data through sockets in the same activity

  6. 6

    Sending various types of data through sockets in Python

  7. 7

    Sending and receiving data through sockets and ports

  8. 8

    sending and recieving data through sockets in the same activity

  9. 9

    Sending objects via java sockets

  10. 10

    Java sockets not sending/receiving messages

  11. 11

    Why isn't my Client sending data to server through sockets when I re-run the program?

  12. 12

    Problems with sending array through ajax

  13. 13

    Sending files with sockets c# client/server

  14. 14

    Sending large JSON files via sockets

  15. 15

    Download image through sockets java

  16. 16

    Sending ByteArray using Java Sockets (Android programming)

  17. 17

    Java sending and receiving file over sockets

  18. 18

    Sending a file with Java Sockets, losing data

  19. 19

    Java Sockets sending multiple objects to the same server

  20. 20

    Java Sockets - Sending data from client to server

  21. 21

    Laravel problems when sending email

  22. 22

    Laravel problems when sending email

  23. 23

    Is there a way to determine which OutputStream is currently sending through to my sockets inputstream?

  24. 24

    Is there a way to determine which OutputStream is currently sending through to my sockets inputstream?

  25. 25

    Memory problems when compressing and transferring a large number of small files (1TB in total)

  26. 26

    Performance problems when plotting spectrogram

  27. 27

    I observed a Java process running at root level through top command on my application server, will it lead to performance problems?

  28. 28

    Sending files from client to server using sockets in C

  29. 29

    Sending an object through a socket in java

HotTag

Archive