Doc SoC
Doc SoC Researcher (software architecture and service-oriented computing).

Process-Oriented Service Design with Discrete Event Simulation

(Updated: )
Reading time: 6 minutes
Process-Oriented Service Design with Discrete Event Simulation

The post on “Event-Driven Service Design” proposes continuous refinement steps to derive process flows and API designs from event-command chains. Here, we show how to convert such process flows to executable simulation models (as a variation and extension of story-driven service design).

The post merely explains the essentials required to run the tool demo steps. It also asks you to answer some review and evaluation questions (optional).

Prerequisites: The instructions below assume that you have MDSL Tools Version 5.4.6 installed (Eclipse IDE or command line interface). The discrete event simulation software JaamSim is required to run the generated models.

Step 1: Obtain or Create MDSL Flow

Step 1a: Perform Event Storming and Convert into MDSL Flow

Note: This first sub-step is an optional activity; feel free to skip it.

Perform Steps 1 to 4 of “Event-Driven Service Design: Five Steps from Event Storming to OpenAPI and Camel Flow”, starting with an event storming output (an online whiteboard in miro is used for the event storming, but intermediate results are provided so that you can skip steps as you like). In the sibling post, an MDSL integration/application flow is created. Open the MDSL file created in the sibling post in the MDSL Tools and review it (note: when using the Eclipse plugin, you have to create a simple project first and then add the file to it).

If you have skipped the previous sub-step, use the listing provided in Step 1b below.

Context: Microservice Domain Specific Language (MDSL) is a domain-specific language for platform-independent API and process design. It also supports informal flow specifications. In the MDSL language reference, the process modeling concepts are explained under “Orchestration Flows”; the page also explains some of the usage scenarios for such flows.

Step 1b: Improve MDSL Flow

Add a start event and a first flow step to the MDSL from Step 1a so that the loop does not go back to the first event (the modeling tools used in later steps appreciate such a dedicated start event):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
API description ResearchPublicationDemo version "1.0"
overview "Step 5 of https://ozimmer.ch/practices/2022/01/13/EventDrivenServiceDesignDemo.html"

event type Start_Researching
event type Paper_Submitted_for_Review
event type Paper_Will_Be_Revised
event type Acceptance_Decision_Made
event type Feedback_Sent
event type Proceedings_Available
event type Paper_Available_Online
command type Write_Paper
command type Review_Paper
command type Review_Feedback
command type Accept_Paper
command type Reject_Paper
command type Publish_Authors_Copy

flow Write_Paper type APPLICATION_FLOW
  event Start_Researching triggers command Write_Paper
  command Write_Paper emits event Paper_Submitted_for_Review
  event Paper_Submitted_for_Review triggers command Review_Paper
  command Review_Feedback emits event Paper_Will_Be_Revised
  event Paper_Will_Be_Revised triggers command Write_Paper
  command Review_Paper emits event Acceptance_Decision_Made
  event Acceptance_Decision_Made triggers command Accept_Paper x Reject_Paper
  command Reject_Paper emits event Feedback_Sent
  event Feedback_Sent triggers command Review_Feedback
  command Accept_Paper emits event Proceedings_Available
  event Proceedings_Available triggers command Publish_Authors_Copy
  command Publish_Authors_Copy emits event Paper_Available_Online

If you have skipped Step 1a, please load the above MDSL snippet into a .mdsl file now. Call the file PSOAD.mdsl (or choose another name). This file has to appear in an Eclipse project in the MDSL Tools.

Step 1c: View MDSL Flow as BPMN Process

Turn the MDSL from Step 1b into BPMN via SketchMiner, either as a quick fix or via the “MDSL->Generate BPMN via SketchMiner” menu option (which requires you to copy-paste the generated output from the src-gen folder into the tool).

Initial Flow

Clicking on this link renders the flow in your Web browser locally; the required JavaScript is downloaded from the SketchMiner Website, but the flow does not leave your computer.

Step 2: Convert MDSL Flow To JaamSim Configuration

A Freemarker template for JaamSim is available to map the MDSL from Step 1 into a process simulation model configuration.1 Here is an excerpt from it:

1
2
3
4
5
6
7
8
9
10
11
12
13
# MDSL to JaamSim Converter Version V2
[...]
RecordEdits
<#list genModel.orchestrationFlows as oflow>
<#assign servers=oflow.jaamSimHelper().servers>
[...]
Define SimEntity { ${oflow.name}SimEntity } 
[...]
<#list servers as server>
${server.name} NextComponent { ${server.nextComponent} } 
${server.name} WaitQueue { ${server.waitQueue} } 
</#list>
[...]

Apply the template by selecting “MDSL” and then “Generate Text File with Freemarker Generation”. The corresponding MDSL CLI command is (please adjust the folder and file names according to your local environment, leading relative paths ./ or .\ might be required to locate command, template and inout file):

mdsl -g text -t JaamSimProcessModelV2.cfg.ftl -i PSOAD.mdsl -f PSOAD-jaamsim.cfg

The simulation model elements are configured toward the top of the generated JaamSim input file:

1
2
3
4
5
6
7
8
9
10
11
12
RecordEdits

# ** Configuration of JaamSim simulation of flow Write_Paper **

Define SimEntity { Write_PaperSimEntity } 
Define EntityGenerator { Start_ResearchingEntityGenerator } 
Define Queue { Start_Researching Paper_Submitted_for_Review Paper_Will_Be_Revised Accept_PaperChoiceQueue Reject_PaperChoiceQueue Feedback_Sent Proceedings_Available DeadLetterQueue }
Define Queue { Write_PaperGuardQueue }
Define Server { Start_ResearchingAggregationInput Paper_Will_Be_RevisedAggregationInput Write_PaperServer Review_Paper Review_Feedback Accept_Paper Reject_Paper Publish_Authors_Copy }
Define Statistics { Paper_Available_Online }
Define Branch { Acceptance_Decision_Made }
Define EntitySink { Write_PaperEntitySink }

The full JaamSim configuration is available here.

If you have not installed JaamSim already, please do so now. Start the tool with:

jaamSim2021-05.jar PSOAD-jaamsim.cfg

If the configuration file is found, you should see something like this:

Initial Flow as JaamSim Configuration

Review the configuration in the tool; for instance, try to find the smulation model elements that correspond to the start event and the choice in the MDSL that we started with in Step 1.

Step 3: Run Process Simulation in JaamSim

Hit the run button in the JaamSim UI (there is an icon for it at the upper left). Inspect some of the model elements; after some time, activate “Real Time” (click on the field of that name that appear to the right to of the run button); pause as you wish. Watch entities being generated and transported through the flow:

  • How does the Branch decide where to route incoming object entities? Hint: inspect its “Choice” attribute in the “Input Editor”.
  • How many entities are generated? Hint: inspect the “Output Viewer - Simulation” of/for the process element Start_ResearchingEntityGenerator. The section “LinkedDevice” lists added, processed and in-progess entities.
  • How many entities arrive at the end of the flow? Hint: review server Publish_Authors_CopyCommand? How many are processed by the Write_Paper Server? Is there a difference and if so, why?

Refer to the Users Guide of JaamSim (“Help” menu and then “User Manual”) for further instructions on what more to do with the model and how to enhance it with simulation artifacts (input values, statistic distributions, attribute and state assignments, etc.).

Step 4: Improve Process Flow Design in MDSL

Let’s refine the process with additional control flow elements now.

In the MDSL tool, apply a quick fix transformation “Inject a parallel split (with join)” to the last command Paper_Available_Online to add a parallel split followed by a join at the end. Change the event and command names like this (e.g., via menu option “Rename Element”):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
event type Collaborators_Informed
event type Paper_Read_And_Cited
event type This_Research_Done

command type Inform_Collaborators
command type Advertise_On_Social_Media
command type MoveOnToNextPaper

[...]

event Paper_Available_Online triggers command Inform_Collaborators + Advertise_On_Social_Media
command Inform_Collaborators emits event Collaborators_Informed
command Advertise_On_Social_Media emits event Paper_Read_And_Cited
event Collaborators_Informed + Paper_Read_And_Cited triggers command MoveOnToNextPaper
command MoveOnToNextPaper emits event This_Research_Done

Also, add a termination event after the last command MoveOnToNextPaper to ensure the simulation ends with statistics gathering and an event sink (as shown in the above snippet). You can do this manually or use another quick fix “Add domain event production step(s) for command(s)” (followed by a renaming). The new version of the MDSL flow specification is available for download here.

The MDSL tools support many more analysis and design transformations, documented online at “MDSL Transformations – Goal- and Service-Oriented Analysis and Design”.

Step 5: Generate Enhanced JaamSim Configuration and Simulate Again

We have modified the input model, so it is time to run the transformation again. See Step 2 for instructions.

A matching generated JaamSim configuration can be found here.

You can also run the modified simulation and compare the original and the modified flow; see Step 3 for instructions.

Optional Step: Convert JaamSim Configuration to MDSL Flow and Endpoint Type

Optional step: Run the JaamSimToMDSL tool (available upon request) to derive API endpoint types and data types from the JaamSim model created in the previous steps.

Note that the output is not 100% identical to the flow we started with in Step 1; the MDSL-to-JaamSim generation in Steps 3 and 5 adds some model elements (guard servers, aggregation queues) because of certain properties and constraints in the JaamSim domain/metamodel (for instance, a server can only wait for entities on one queue).

Review Questions (optional)

Please answer the following questions:

  • Did the transformation(s) work as expected? Is their MDSL input clear, does the JaamSim output match it?
  • Have you been able to trace the simulation model elements (for instance, servers, queues, entity generators and sinks, branches, combines) back to the event storming capture from Step 1 of “Event-Driven Service Design: Five Steps from Event Storming to OpenAPI and Camel Flow”?
  • How much time did it take you to run through the steps? How much time would you estimate the manual creation of the generated model to take?
  • Which strengths, weaknesses, opportunities and threats for the proposed model mapping and its implementation do you see?
  • Would you use such model generator in practice? If not, what is missing?

Thank you! Contact me if you would like to provide feedback about the proposed approach or have questions about it.

– Olaf (a.k.a. socadk)

Acknowledgements.

MDSL is a interface description language whose tools benefitted from continued research and development in two projects funded by the Hasler-Foundation (2020 and 2021 to present). Both Context Mapper and MDSL Tools could be validated and hardened in an innovation project funded by Innosuisse (2021).

The MDSL to JaamSim mapping described in this post is joint work with Katharina Luban, Giuliano Bernard and Mirko Stocker from the University of Applied Sciences of Eastern Switzerland (OST).

Notes.

  1. JaamSim is “a free and open source discrete-event simulation software which includes a drag-and-drop user interface, interactive 3D graphics, input and output processing, and model development tools and editors”.