Socket.io client socket taking long to respond
I am using socket.io to send/receive messages between client/server. The server has a Redis instance that stores data and responds with the data within milliseconds.
Some of the sockets take very long to return the data (stringified large JSON object) although it is sent from the server side almost immediately. I am therefore looking for suggestion that address the following concerns:
- Is it normal for socket.io to take this long to emit a long string ?
- How can I know which method or socket is doing the emit that takes long ?
- Any further suggestions on how to improve performance?
Help really appreciated
UPDATE:
I tried using Webdis to provide the response to the client without having to go to the server to get the Redis results. However although the response appears in a console.log in about 1 second (which is the same as the DOMLoadedContent below), the websocket still takes about 20s and shows 0 bytes as shown below:
javascript node.js sockets websocket socket.io
add a comment |
I am using socket.io to send/receive messages between client/server. The server has a Redis instance that stores data and responds with the data within milliseconds.
Some of the sockets take very long to return the data (stringified large JSON object) although it is sent from the server side almost immediately. I am therefore looking for suggestion that address the following concerns:
- Is it normal for socket.io to take this long to emit a long string ?
- How can I know which method or socket is doing the emit that takes long ?
- Any further suggestions on how to improve performance?
Help really appreciated
UPDATE:
I tried using Webdis to provide the response to the client without having to go to the server to get the Redis results. However although the response appears in a console.log in about 1 second (which is the same as the DOMLoadedContent below), the websocket still takes about 20s and shows 0 bytes as shown below:
javascript node.js sockets websocket socket.io
How long is the string? You refer to it as a “long string”. Is it like megabytes or something?
– Nate
Dec 30 '18 at 17:26
@Nate The longest it about 19.5 MegaBytes
– Afshin Ghazi
Dec 30 '18 at 17:53
Hey @AfshinGhazi, any luck so far on the issue?
– ForgetfulFellow
Jan 1 at 23:32
@ForgetfulFellow no haven't resovled yet. I used Webdis to provide the Redis data quickly to the client instead of the server (which would then provide to the client). However I can't understand why the websocket takes about 20s to finish wheras a console.log of the data takes about 1s.
– Afshin Ghazi
Jan 3 at 6:13
add a comment |
I am using socket.io to send/receive messages between client/server. The server has a Redis instance that stores data and responds with the data within milliseconds.
Some of the sockets take very long to return the data (stringified large JSON object) although it is sent from the server side almost immediately. I am therefore looking for suggestion that address the following concerns:
- Is it normal for socket.io to take this long to emit a long string ?
- How can I know which method or socket is doing the emit that takes long ?
- Any further suggestions on how to improve performance?
Help really appreciated
UPDATE:
I tried using Webdis to provide the response to the client without having to go to the server to get the Redis results. However although the response appears in a console.log in about 1 second (which is the same as the DOMLoadedContent below), the websocket still takes about 20s and shows 0 bytes as shown below:
javascript node.js sockets websocket socket.io
I am using socket.io to send/receive messages between client/server. The server has a Redis instance that stores data and responds with the data within milliseconds.
Some of the sockets take very long to return the data (stringified large JSON object) although it is sent from the server side almost immediately. I am therefore looking for suggestion that address the following concerns:
- Is it normal for socket.io to take this long to emit a long string ?
- How can I know which method or socket is doing the emit that takes long ?
- Any further suggestions on how to improve performance?
Help really appreciated
UPDATE:
I tried using Webdis to provide the response to the client without having to go to the server to get the Redis results. However although the response appears in a console.log in about 1 second (which is the same as the DOMLoadedContent below), the websocket still takes about 20s and shows 0 bytes as shown below:
javascript node.js sockets websocket socket.io
javascript node.js sockets websocket socket.io
edited Jan 3 at 6:45
Afshin Ghazi
asked Dec 30 '18 at 17:25
Afshin GhaziAfshin Ghazi
4441417
4441417
How long is the string? You refer to it as a “long string”. Is it like megabytes or something?
– Nate
Dec 30 '18 at 17:26
@Nate The longest it about 19.5 MegaBytes
– Afshin Ghazi
Dec 30 '18 at 17:53
Hey @AfshinGhazi, any luck so far on the issue?
– ForgetfulFellow
Jan 1 at 23:32
@ForgetfulFellow no haven't resovled yet. I used Webdis to provide the Redis data quickly to the client instead of the server (which would then provide to the client). However I can't understand why the websocket takes about 20s to finish wheras a console.log of the data takes about 1s.
– Afshin Ghazi
Jan 3 at 6:13
add a comment |
How long is the string? You refer to it as a “long string”. Is it like megabytes or something?
– Nate
Dec 30 '18 at 17:26
@Nate The longest it about 19.5 MegaBytes
– Afshin Ghazi
Dec 30 '18 at 17:53
Hey @AfshinGhazi, any luck so far on the issue?
– ForgetfulFellow
Jan 1 at 23:32
@ForgetfulFellow no haven't resovled yet. I used Webdis to provide the Redis data quickly to the client instead of the server (which would then provide to the client). However I can't understand why the websocket takes about 20s to finish wheras a console.log of the data takes about 1s.
– Afshin Ghazi
Jan 3 at 6:13
How long is the string? You refer to it as a “long string”. Is it like megabytes or something?
– Nate
Dec 30 '18 at 17:26
How long is the string? You refer to it as a “long string”. Is it like megabytes or something?
– Nate
Dec 30 '18 at 17:26
@Nate The longest it about 19.5 MegaBytes
– Afshin Ghazi
Dec 30 '18 at 17:53
@Nate The longest it about 19.5 MegaBytes
– Afshin Ghazi
Dec 30 '18 at 17:53
Hey @AfshinGhazi, any luck so far on the issue?
– ForgetfulFellow
Jan 1 at 23:32
Hey @AfshinGhazi, any luck so far on the issue?
– ForgetfulFellow
Jan 1 at 23:32
@ForgetfulFellow no haven't resovled yet. I used Webdis to provide the Redis data quickly to the client instead of the server (which would then provide to the client). However I can't understand why the websocket takes about 20s to finish wheras a console.log of the data takes about 1s.
– Afshin Ghazi
Jan 3 at 6:13
@ForgetfulFellow no haven't resovled yet. I used Webdis to provide the Redis data quickly to the client instead of the server (which would then provide to the client). However I can't understand why the websocket takes about 20s to finish wheras a console.log of the data takes about 1s.
– Afshin Ghazi
Jan 3 at 6:13
add a comment |
1 Answer
1
active
oldest
votes
It seems like you've hit issues that others have seen as well with large file uploads using socket.io:
Node.JS, Socket.IO & large XML files: extreme performance loss?
One possible course of action is to try file streaming in socket.io:
https://gist.github.com/companje/eea17988257a10dcbf04
As for
How can I know which method or socket is doing the emit that takes
long ?
You can always pass in dateTime's into the client's data received from socket.io and then compute the time difference, printing out the methods that it called.
1
I’d also be curious of what is being sent that large. If it’s media (image, audio, video) then it would make more sense to send a URL over the socket, and have the browser download the file like normal not through a socket. This approach would reduce load on the socket server and also allow the browser to cache the large data, which is better for everyone.
– Nate
Dec 30 '18 at 18:16
@Nate The large data comes from an api call response
– Afshin Ghazi
Jan 2 at 7:32
@AfshinGhazi What’s the data type? Because if that’s all JSON data for building a UI, that sounds crazy!
– Nate
Jan 2 at 14:55
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979817%2fsocket-io-client-socket-taking-long-to-respond%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It seems like you've hit issues that others have seen as well with large file uploads using socket.io:
Node.JS, Socket.IO & large XML files: extreme performance loss?
One possible course of action is to try file streaming in socket.io:
https://gist.github.com/companje/eea17988257a10dcbf04
As for
How can I know which method or socket is doing the emit that takes
long ?
You can always pass in dateTime's into the client's data received from socket.io and then compute the time difference, printing out the methods that it called.
1
I’d also be curious of what is being sent that large. If it’s media (image, audio, video) then it would make more sense to send a URL over the socket, and have the browser download the file like normal not through a socket. This approach would reduce load on the socket server and also allow the browser to cache the large data, which is better for everyone.
– Nate
Dec 30 '18 at 18:16
@Nate The large data comes from an api call response
– Afshin Ghazi
Jan 2 at 7:32
@AfshinGhazi What’s the data type? Because if that’s all JSON data for building a UI, that sounds crazy!
– Nate
Jan 2 at 14:55
add a comment |
It seems like you've hit issues that others have seen as well with large file uploads using socket.io:
Node.JS, Socket.IO & large XML files: extreme performance loss?
One possible course of action is to try file streaming in socket.io:
https://gist.github.com/companje/eea17988257a10dcbf04
As for
How can I know which method or socket is doing the emit that takes
long ?
You can always pass in dateTime's into the client's data received from socket.io and then compute the time difference, printing out the methods that it called.
1
I’d also be curious of what is being sent that large. If it’s media (image, audio, video) then it would make more sense to send a URL over the socket, and have the browser download the file like normal not through a socket. This approach would reduce load on the socket server and also allow the browser to cache the large data, which is better for everyone.
– Nate
Dec 30 '18 at 18:16
@Nate The large data comes from an api call response
– Afshin Ghazi
Jan 2 at 7:32
@AfshinGhazi What’s the data type? Because if that’s all JSON data for building a UI, that sounds crazy!
– Nate
Jan 2 at 14:55
add a comment |
It seems like you've hit issues that others have seen as well with large file uploads using socket.io:
Node.JS, Socket.IO & large XML files: extreme performance loss?
One possible course of action is to try file streaming in socket.io:
https://gist.github.com/companje/eea17988257a10dcbf04
As for
How can I know which method or socket is doing the emit that takes
long ?
You can always pass in dateTime's into the client's data received from socket.io and then compute the time difference, printing out the methods that it called.
It seems like you've hit issues that others have seen as well with large file uploads using socket.io:
Node.JS, Socket.IO & large XML files: extreme performance loss?
One possible course of action is to try file streaming in socket.io:
https://gist.github.com/companje/eea17988257a10dcbf04
As for
How can I know which method or socket is doing the emit that takes
long ?
You can always pass in dateTime's into the client's data received from socket.io and then compute the time difference, printing out the methods that it called.
answered Dec 30 '18 at 18:07
ForgetfulFellowForgetfulFellow
1,3071327
1,3071327
1
I’d also be curious of what is being sent that large. If it’s media (image, audio, video) then it would make more sense to send a URL over the socket, and have the browser download the file like normal not through a socket. This approach would reduce load on the socket server and also allow the browser to cache the large data, which is better for everyone.
– Nate
Dec 30 '18 at 18:16
@Nate The large data comes from an api call response
– Afshin Ghazi
Jan 2 at 7:32
@AfshinGhazi What’s the data type? Because if that’s all JSON data for building a UI, that sounds crazy!
– Nate
Jan 2 at 14:55
add a comment |
1
I’d also be curious of what is being sent that large. If it’s media (image, audio, video) then it would make more sense to send a URL over the socket, and have the browser download the file like normal not through a socket. This approach would reduce load on the socket server and also allow the browser to cache the large data, which is better for everyone.
– Nate
Dec 30 '18 at 18:16
@Nate The large data comes from an api call response
– Afshin Ghazi
Jan 2 at 7:32
@AfshinGhazi What’s the data type? Because if that’s all JSON data for building a UI, that sounds crazy!
– Nate
Jan 2 at 14:55
1
1
I’d also be curious of what is being sent that large. If it’s media (image, audio, video) then it would make more sense to send a URL over the socket, and have the browser download the file like normal not through a socket. This approach would reduce load on the socket server and also allow the browser to cache the large data, which is better for everyone.
– Nate
Dec 30 '18 at 18:16
I’d also be curious of what is being sent that large. If it’s media (image, audio, video) then it would make more sense to send a URL over the socket, and have the browser download the file like normal not through a socket. This approach would reduce load on the socket server and also allow the browser to cache the large data, which is better for everyone.
– Nate
Dec 30 '18 at 18:16
@Nate The large data comes from an api call response
– Afshin Ghazi
Jan 2 at 7:32
@Nate The large data comes from an api call response
– Afshin Ghazi
Jan 2 at 7:32
@AfshinGhazi What’s the data type? Because if that’s all JSON data for building a UI, that sounds crazy!
– Nate
Jan 2 at 14:55
@AfshinGhazi What’s the data type? Because if that’s all JSON data for building a UI, that sounds crazy!
– Nate
Jan 2 at 14:55
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979817%2fsocket-io-client-socket-taking-long-to-respond%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How long is the string? You refer to it as a “long string”. Is it like megabytes or something?
– Nate
Dec 30 '18 at 17:26
@Nate The longest it about 19.5 MegaBytes
– Afshin Ghazi
Dec 30 '18 at 17:53
Hey @AfshinGhazi, any luck so far on the issue?
– ForgetfulFellow
Jan 1 at 23:32
@ForgetfulFellow no haven't resovled yet. I used Webdis to provide the Redis data quickly to the client instead of the server (which would then provide to the client). However I can't understand why the websocket takes about 20s to finish wheras a console.log of the data takes about 1s.
– Afshin Ghazi
Jan 3 at 6:13