Skip to content
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

Storing all messages between actors to csv files #3155

Merged
merged 57 commits into from
May 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
a400580
Saving actor messages to csv file
dimaopen Mar 4, 2021
8b659d4
IterationStartsMessage and IterationEndsMessage via event stream in o…
dimaopen Mar 4, 2021
91c2790
Add saving beam actor transitions
dimaopen Mar 9, 2021
ff034bf
triggerId in most of the messages
dimaopen Mar 11, 2021
462e3d9
Introduced publishMessageFromTo so that messages with sender/receiver…
dimaopen Mar 17, 2021
e45b4a8
Fixed wrong number of args in the extractor
dimaopen Mar 18, 2021
8588e41
More triggerId in beam message classes
dimaopen Mar 23, 2021
e1df9e9
Increased image limit size for plant uml (puml)
dimaopen Mar 23, 2021
5b294e2
Fixed wrong number of args in the extractor
dimaopen Mar 25, 2021
df16de3
Created Logging Ask pattern for publishing sender, receiver, payload
dimaopen Mar 25, 2021
8a41213
Using Logging Ask pattern where possible. Not storing the temp sender…
dimaopen Mar 26, 2021
8c3eb5f
Added trigger ids to messages at specs
dimaopen Mar 29, 2021
0d4c547
Merge remote-tracking branch 'origin/develop' into do/#3104-actor-mes…
dimaopen Mar 29, 2021
bc1f667
Merge remote-tracking branch 'origin/develop' into do/#3104-actor-mes…
dimaopen Mar 29, 2021
7157db6
Adding contextBecome in order to handle messages when context.become …
dimaopen Mar 29, 2021
64684d5
PhyssymXmlToOsmConverter.scala fmt
dimaopen Mar 29, 2021
5497665
Revert back the conf files.
dimaopen Mar 29, 2021
eba0168
Created VisualizingApp for producing message sequences
dimaopen Mar 30, 2021
302e58b
Exit code 1 in case of wrong args
dimaopen Mar 30, 2021
f86ce4f
Merge remote-tracking branch 'origin/develop' into do/#3104-actor-mes…
dimaopen Mar 30, 2021
0d68b89
Added triggerId to more message classes. Fixed not sending triggerId …
dimaopen Mar 31, 2021
45bafe2
Cleaning the test data just in case it is presented.
dimaopen Mar 31, 2021
e1bc914
Merge remote-tracking branch 'origin/develop' into do/#3104-actor-mes…
dimaopen Mar 31, 2021
35ff2c6
Using the correct triggerId for RoutingRequest
dimaopen Apr 6, 2021
c54f30d
Generate negative triggerId in case of missed one, extracting trigger…
dimaopen Apr 7, 2021
7fbacd7
More triggerId fields added
dimaopen Apr 7, 2021
6456972
Merge remote-tracking branch 'origin/develop' into do/#3104-actor-mes…
dimaopen Apr 7, 2021
5543f9c
fmt after merge from develop
dimaopen Apr 7, 2021
be4c8e5
Merge branch 'develop' into do/#3104-actor-messages-logging
JustinPihony Apr 20, 2021
039c3b1
Updated rst docs regarding to how to capture protocols.
dimaopen Apr 29, 2021
50a755a
Added Actor as state diagram (state diagram where nodes are Actors)
dimaopen Apr 30, 2021
1f0eaa3
Publishing messages that answered on ask pattern
dimaopen Apr 30, 2021
f42c5b0
Added state entries to puml to allow long names and clearly state tha…
dimaopen Apr 30, 2021
d5f5cfa
Added SingleActorAsState diagram
dimaopen Apr 30, 2021
d2e4ebb
Added Agent State diagram
dimaopen Apr 30, 2021
d10adf7
Added tick info to the Sequence diagram
dimaopen May 3, 2021
c1e13c2
Parsing tick even if is written as double by pandas or other tools.
dimaopen May 3, 2021
66d8df6
Extracting tick out of payload when it's possible
dimaopen May 3, 2021
7365d95
Documentation of how to capture beam messages improved. Simplified code.
dimaopen May 4, 2021
c946b62
Removed unneeded file
dimaopen May 4, 2021
edfc950
Put pushing the event to the bus before the actual handling of the ev…
dimaopen May 5, 2021
854920d
Added the commented person sequence diagram as a picture.
dimaopen May 5, 2021
b7e6207
MessageLogger is created for a single iteration; waiting until it sav…
dimaopen May 6, 2021
72f7d8d
Not starting the MessageLogger in case the debug flag is not set.
dimaopen May 6, 2021
27b8170
Merge remote-tracking branch 'origin/develop' into do/#3104-actor-mes…
dimaopen May 6, 2021
4dd6514
Improve readability
dimaopen May 7, 2021
f5bc956
Simplified
dimaopen May 7, 2021
2b123fe
Implemented some notes from peer review
dimaopen May 7, 2021
df6626d
Replaced all the arbitrary constants for triggerId with -1 to indicat…
dimaopen May 7, 2021
cba2934
Actors extend directly LoggingMessageActor
dimaopen May 7, 2021
ddcdfc1
replaced akka config parameter akka.actor.debug.receive with beam.deb…
dimaopen May 7, 2021
e1624bf
Slightly simplified the code
dimaopen May 20, 2021
603a017
Throwing errors in case of not parsable number.
dimaopen May 20, 2021
cdd30d0
Typo fix
dimaopen May 24, 2021
5917efc
Type fix 2
dimaopen May 24, 2021
06852bf
Peer review fix
dimaopen May 25, 2021
b7e353d
Added validating that the output path is a directory when a directory…
dimaopen May 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/uml/dia-sequence-person.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/uml/dia-sequence-ridehail-agent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/uml/dia-state-person.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Contents:
about
users
developers
messages
grafana
agents
behaviors
Expand Down
132 changes: 132 additions & 0 deletions docs/messages.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@

.. _beam-messages:

Auto Capturing Beam Messages
============================

Capturing most messages that BEAM Actors generate
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

BEAM uses triggerId to trace down all the actor interactions starting from TriggerWithId Event that is sent by the Scheduler. When developing a new message type, extend it from HasTriggerId trait in order to trace these messages.
In order to enable saving messages to csv files one needs to add the following property to beam.conf file::

beam.debug.messageLogging=true

The files are saved in the iteration directories, ie $RUN_OUTPUT_DIR$/ITERS/it.0/0.actor_messages_0.csv.gz. There may be multiple of these files per iteration. For the scenario sf-light-1k about 400Mb of gzipped data generated.

Generated csv files
^^^^^^^^^^^^^^^^^^^

The files contains the following columns

+ type: one of the following types (transition, event, message)
+ sender_parent
+ sender_name
+ receiver_parent
+ receiver_name
+ payload: message content or previous state in case of type = transition
+ state: FSM data or next state in case of type = transition
+ tick: current tick
+ triggerId: the triggerId which started the message sequence (if available)

How to visualize them
^^^^^^^^^^^^^^^^^^^^^

VisualizingApp can convert these files to different diagrams. It creates `PlantUML`_ files that can be easily converted to pictures. You can run it with gradle with the following command::

$ ./gradlew :execute -PmainClass=beam.utils.protocolvis.VisualizingApp -PappArgs=["'--input', 'output/sf-light/sf-light_2021-05-03_10-50-55_cxc/ITERS/it.0', '--output', 'docs/uml/sequence1.puml', '--diagram-type', 'Sequence', '--force', '--person-id', '010900-2012001379980-0-560057'"]

Parameters
----------

+----------------+------------------------------------------------------------------+
| parameter | values |
+================+==================================================================+
| *input* | directory or file where to read message files |
+----------------+------------------------------------------------------------------+
| *output* | the output file |
+----------------+------------------------------------------------------------------+
| *diagram-type* | Sequence | ActorAsState | AgentState | SingleActorAsState |
+----------------+------------------------------------------------------------------+
| *force* | allows to overwrite the output without prompt |
+----------------+------------------------------------------------------------------+
| *person-id* | the person id which the message sequence should be generated for |
+----------------+------------------------------------------------------------------+

.. note:: For Sequence diagram it's always better to provide either a single limited size file as an *input* or a *person-id* for limiting the number of interactions in order to avoid creating a huge file.

Diagram types
-------------

Sequence
~~~~~~~~

Sequence diagrams display every line from the beam message csv files. Because of that one always needs to limit the number of messages processed. It can be done by providing a small file that is filtered down to interesting messages. And also it can be done via providing person-id as a parameter to VisualizingApp.

This is an example of a sequence diagram for a person.

.. image:: _static/uml/dia-sequence-person.png

This is an example of a sequence diagram for a ridehail agent. It is produced by filtering the ridehail agent messages with pandas and saving them ot a csv with the following script.

.. code-block:: python

msg = pd.read_csv(f"../output/sf-light/{dir}/ITERS/it.0/0.actor_messages_0.csv.gz")

agent_id = 'rideHailAgent-020700-2013000080675-0-5008509'

trigger_ids = msg[(msg['sender_name'] == agent_id) | (msg['receiver_name'] == agent_id)]['triggerId'].unique()
trigger_ids = [id for id in trigger_ids if id >= 0]

allAgents = msg[
(
(msg['sender_name'] == agent_id)
| (msg['receiver_name'] == agent_id)
| (msg['triggerId'].isin(trigger_ids))
)
]
allAgents[(
~((allAgents['sender_name'].str.startswith('rideHailAgent-') & (allAgents['sender_name'] != agent_id))
| (allAgents['receiver_name'].str.startswith('rideHailAgent-') & (allAgents['receiver_name'] != agent_id))
)
)
].to_csv("../docs/uml/ride-hail-agent.csv")

.. image:: _static/uml/dia-sequence-ridehail-agent.png

Actor Message State Diagram
~~~~~~~~~~~~~~~~~~~~~~~~~~~

It's not a real state diagram. It has actors as nodes and messages as edges between nodes.
This diagram is generated with setting parameter *--diagram-type=ActorAsState*. The picture of this diagram is pretty big and messy. It makes sense to filter the messages by providing --person-id parameter.

Single Actor Message State Diagram
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It's diagram is similar to the previous one. But it uses only messages that go to/from a single actor (i.e. RideHailManager). This diagram is generated with setting parameter *--diagram-type=SingleActorAsState*. The *--output* parameter must point to a folder because the VisualizingApp generates multiple puml files (one for each actor).

This is an example of Actor Message state diagram for ChargingNetworkManager actor.

.. image:: _static/uml/dia-message-state-charging-network-manager.png


Agent State Diagram
~~~~~~~~~~~~~~~~~~~

This diagram is generated with setting parameter *--diagram-type=AgentState*. It's a real state diagram which shows agent states and transitions between them. The *--output* parameter must point to a folder because the VisualizingApp generates multiple puml files (one for each agent). This is an example state diagram

.. image:: _static/uml/dia-state-person.png

Converting puml files to pictures
---------------------------------

Converting puml files to pictures can be done in `a number of ways`_. The easiest way would be running the following command for multiple files::

$ java -jar docs/uml/plantuml.1.2017.18.jar -DPLANTUML_LIMIT_SIZE=16000 -o <PICTURE_OUTPUT_DIR> ./*

For a single file::

$ java -jar docs/uml/plantuml.1.2017.18.jar -DPLANTUML_LIMIT_SIZE=16000 single_file.puml

.. _PlantUML: https://plantuml.com/
.. _a number of ways: https://plantuml.com/en/running
8 changes: 6 additions & 2 deletions docs/outputs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Classname: ModeChosenAnalysisObject
+-------------------+--------------------------------------------+
| walk_transit | Walk to transit chosen as travel mode |
+-------------------+--------------------------------------------+
| bike_transit | bike to transit chosen as travel mode |
+-------------------+--------------------------------------------+


File: /referenceModeChoice.csv
Expand All @@ -49,6 +51,8 @@ Classname: ModeChosenAnalysisObject
+-------------------+--------------------------------------------+
| walk_transit | Walk to transit chosen as travel mode |
+-------------------+--------------------------------------------+
| bike_transit | bike to transit chosen as travel mode |
+-------------------+--------------------------------------------+

File: /realizedMode.csv
-----------------------
Expand Down Expand Up @@ -613,8 +617,8 @@ Classname: BiasNormalizedErrorGraphDataOutput
| mean bias | Mean bias value |
+--------------------------------+--------------------------------+

File: /ITERS/it.0/0.rideHailFleet.csv.gz
----------------------------------------
File: /ITERS/it.0/0.rideHailFleetFromInitializer.csv.gz
-------------------------------------------------------

Classname: RideHailFleetInitialize

Expand Down
20 changes: 20 additions & 0 deletions docs/uml/dia-message-state-charging-network-manager.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@startuml
state "Person" as Person
state "scheduler" as scheduler
state "ChargingNetworkManager" as ChargingNetworkManager
state "ParkingNetworkManager" as ParkingNetworkManager
state "BeamMobsim.iteration" as BeamMobsim_iteration
Person --> ChargingNetworkManager: ChargingPlugRequest(449)
scheduler --> ChargingNetworkManager: ChargingTimeOutTrigger(435)
scheduler --> ChargingNetworkManager: IllegalTriggerGoToError(1)
BeamMobsim_iteration --> ChargingNetworkManager: Finish(1)
ChargingNetworkManager --> scheduler: CompletionNotice(796)
scheduler --> ChargingNetworkManager: InitializeTrigger(1)
Person --> ChargingNetworkManager: ChargingUnplugRequest(13)
ChargingNetworkManager --> Person: EndingRefuelSession(13)
ChargingNetworkManager --> scheduler: ScheduleTrigger(238)
ChargingNetworkManager --> BeamMobsim_iteration: Terminated(1)
scheduler --> ChargingNetworkManager: PlanEnergyDispatchTrigger(360)
ChargingNetworkManager --> Person: StartingRefuelSession(449)
ChargingNetworkManager --> ParkingNetworkManager: ReleaseParkingStall(449)
@enduml
Loading