WebSockets Integration #627
victorgarcia98
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Motivation
In order to support more reactive ways to do flexibility (FCR, aFRR, congestion management), which require faster response times, it would be interesting to support WebSockets in FlexMeasures core.
What are WebSockets?
from Mozilla:
In essence, WebSockets clients establish the connection with a WebSockets server through a HTTP handshake. Once the connection is established, a TCP is open between the two peers which is used for the actual communication of the messages.
Benefits of WebSockets
In summary, the main benefits of websockets are: (1) bidirectional communication, (2) less resourceful than REST, (3) Broadcast (5)
(1) Bidirectional communications
We don't have to pull from the client to the server to 'asking for a new event'.
This is ideal for several applications:
Benefits: responsiveness and less resourceful (we don't need constant pulling).
Drawbacks: requires a complex architecture to handle the events.
(2) Less Resourceful
It turns out that websockets have less overhead because the first connection is established through http and the following messages are send trough tcp (less headers).
(3) Broadcast
Inline with the bidirectional communication, we can broadcast messages to the whole pool of users or to a part of them. This feature would be very interesting to control pools of energy assets, thanks to which, we'll be able to send control signals to the whole portfolios at once.
Modules
There are a lot of python package that implement the websocket protocol but many appear to be unmaintained. Among all of them, I've tried so far the following two:
(list last updated on 05/04/2023)
Flask-Sock - 185 ⭐
In bullet-points:
Integration
I manage to integrate this into a flexmeasures plugin and It works, but It's a little bit slow.
file:
flexmeasures_s2/__init__.py
file:
flexmeasures_s2/events/event.py
Testing Client:
Websockets - 4k ⭐
In bulletpoints:
threading
andasync
modesThere are some features we would like to have and that are not directly covered by websockets protocol but that are covered in the documentation:
Actually, there's a whole topic on Authentication, so we can take some things from there.
Integration into FlexMeasures
With all that, I have identified the following implementation decisions that we need to address, feel free to add your ideas and concerns:
/<plugin-name>/<topic>
flexmeasures run
.Beta Was this translation helpful? Give feedback.
All reactions