-
Notifications
You must be signed in to change notification settings - Fork 62
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
Add queueLength() #38
base: main
Are you sure you want to change the base?
Conversation
size_t queueLength() { //added by ewowi | ||
return _messageQueue.length(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a great idea for these reasons:
- Traversal is O(N), not O(1) like with std::list on c++ >= 11
- No mutex protection to block concurrent access
The internal structure (LinkedList
) should be changed IMO because it is not efficient.
In our community maintained fork (https://github.com/mathieucarbou/ESPAsyncWebServer), which is far more evolved than this fork, we have implemented it like this:
size_t AsyncWebSocketClient::queueLen() const {
#ifdef ESP32
std::lock_guard<std::mutex> lock(_lock);
#endif
return _messageQueue.size();
}
_messageQueue
being a std::list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a few comments ;-)
I would need to see more of your code... This is something related to the recent split to move implementation code in cpp files, but I don't understand why I don't saw it in the many projects I have. |
I created a branch in my repo which moves from the esp home to your repo. https://github.com/MoonModules/StarLight/actions/runs/11113157238/job/30876843828 this is the branch: https://github.com/MoonModules/StarLight/tree/mc-eaws-test Let me know if you need more info, thx for looking into this, Oh and including AsyncWebSocket.h indeed made no difference, and moving the vars out of the class also resulted in the same errors |
This is not right:
=>
You are relying on an inexisting copy constructor. Sae error above for Psychic (side note; I am one of PsychicHttp dev also) |
Hey thanks for your help! That makes sense if ws and server is defined outside a class, but within a class I thought this was the way to do it. But maybe just not possible to define it inside a class? (although esp home version 'accepted' it - but making copies ...) I now did it like this: Diff is here: MoonModules/StarLight@06423f8 I then had new errors, mainly related to Error log here: https://github.com/MoonModules/StarLight/actions/runs/11120233580/job/30896848815 And yeah I am investigating for a while which ws server is the best to use, see also some remarks / comments I have in my platformio.ini. Tried also PsychicHttp but never finished that POC. So if you work on both, which one to choose ? ;-) |
Choose the one you prefer! I am a heavy contributor / collaborator of Psychic: at the moment, we are preparing v2 which will be an API rework and won't be compatible with v1. A lot of perf issues and bugs are fixed. Psychic is not yet on par with ESPAsyncWebServer in terms of features m, and this is partly due to the limitations of the esp-idf API used behind. Also, it does not have years of history behind it... In terms of flag usage and memory footprint, ESPAsyncWebServer is better than Psychic and also better than Arduino Webserver. But it does not support https. For your issue, it is possible that you need to change a little your code if you are doing more advanced things like using the client API because we had to change the internal structure used to store clients for better perfs. So yes use references, always avoid copies. Most of perf issues often lies in the user code or how a library is used ;-) |
Also I am more concerned about this const issue which might be related to that: https://github.com/mathieucarbou/ESPAsyncWebServer/blob/main/src/AsyncWebSocket.h#L354 Can you please open a discussion in the right projet so that we stop hijacking ESPhome 's PR ? Also maybe try to fix the warnings: there are so many 😅 Thanks! |
@ewowi : you can upgrade to 3.3.7 : it includes the fix to be able to iterate over clients in a non-const way to call send methods. This limitation was there since previous forks. |
To know how full the client queue is - and do only 'lossless' things if the queue is not too full