-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory Management #598
Comments
Hello @8databit, thank you for your concerns! Where did you saw throttling? There should not be any! Do you know other projects which may have a throttle setting? Right now I am not sure how to implement this without breaking everything ;) Greetings |
Hey, Call me Joyie, Well i maybe read the code wrong but ur adding a queue which holds the bytebuffers if im corrrect. This queue has a limitation of how many buffers it holds, so this is some sort of throttle.
Sinse it doen't put the buffer in the queue when there is no queue space available, i thought this was a throttle on the server sided reading. Although this isn't per socket-connection and the code is kinda unclear to me, bit of a puzzle hahaha. I have been struggling on this for a while myself actually using TCP. I'd like to mention that the receive and read buffer of the socket also allocates ram. The thing i would do is just only make a feature that just doesn't read the buffer of the socket when the limitation is overflown and just outputs onmessage(). What happens after then is up to the user of this project. Create a file, or keep it in a list/queue? Files should be written in parts yeah ^^ although i think this protocol should not be implemented in this project. It's for the user of this project to determine when the server is expecting a file or sending a file. And no i unfortunately do not know any projects implementing this method. |
Hello Joyie, well I always considered this part just as a performance booster to reduce the need allocate new bytebuffer and reuse it out of the queue. For me your suggestion is not really intuitive. A user excepts a onMessage call to contain a complete received message. The websocket protocol does not define what it should or should no be used to! It is up to the application to choose and I can not enforce a specific usage! Help is always welcome! That's the spirit of an open source project! Greetings |
Heyy marci! Thanks for ur reply. I get what you mean, I was just giving an example ^^. Your right it should be implemented with care. I have taken a look inside the files again and maybe it's an idea to look at:
of the RFC 6455 docs. This might be a solution, or not lmao need u to verify this. translateSingleFrame(); inside Draft_6455.
If we came till this point we were able to fetch the payloadsize and are about to allocate space. What if we just simply add a limit here. It sends a close frame (10.7. @ Docs of 6455 with status code 1009 if it crosses the limit:
This just simply closes the connection, be sure to force close the connection if it takes to long to close with the Close Frame. The client could either reconnect after a random amount of seconds (0-5 based on the docs) if it has received a message for closure with this error code. This should be seen more as a security feature than something for performance, if i connect to some server randomly and send a large amount of data i can just fill up the ByteBuffer list of Draft_6455 because it will keep looking for a Complete Frame. If i have 10 connections and i keep sending data nothing is done by the server while i'm sending them.
I would also add a limit to the byteBufferList.
This could be implemented as an additional feature, not as a standard thing, based on your reply. |
Hello Joyie, I think https://tools.ietf.org/html/rfc6455#section-10.4 is a better solution. The point you mention received all the bytes out of the socket already! Yes, it is also necessary to check the length at the bytebufferlist (for fragmented frames). I am not sure when I get the time to implement anything in this direction! Feel free to try it out on your own! |
Hello Joyie, I implemented your recommended changes. To set a lower limit then Integer.MAX_VALUE, call the constructor for Draft_6455 with your specific limit in bytes. Greetings |
Hello @8databit, did you have a the time to take a look at this? Greetings |
any update? |
Hey,
I'm kinda worried about the following thing. Let's say a user sends a 20MB message of any type, I think as how it is now it will store the final 20MB in the RAM memory, logical to me, using a ByteBuffer. This, i think, can cause an issue when multiple clients are sending big amounts of data. Is there a way to limit the size of a message incoming at the server, being more precise: being stored temporary in the memory? What if the size is bigger than 1GB? Is this even allowed by most browsers?
I saw you already did some throttling.
Also, just curious. Why the size of 16384 bytes for the rec-buffer of the socket? Is there a logical explanation? Great work ;)
Expected Behavior
Throttle setting
Possible Solution
Throttle setting
Context
Probably will give issues when this isn't properly managed. If already implemented which class should i be in and which line ~ area.
The text was updated successfully, but these errors were encountered: