Package: simpl-modelservice
Simpl ModelservicePython Library to implement Simulations, built on Crossbar.io and Django.InstallationDjango 2.2$pipinstallsimpl-modelserviceDjango 1.11$pipinstall"simpl-modelservice<0.8.0"Setup development environment$ git clone git@github.com:simplworld/simpl-modelservice.git
$ cd simpl-modelservice
$ mkvirtualenv simpl-modelservice
$ pip install -r dev-requirements.txt
$ pip install -e .Run tests$ python runtests.pyDevelopment versioningInstallbumpversion:$ pip install bumpversionThen, to release a new version, increment the version number with:$ bumpversion patchThen push to the repo:$ git push && git push --tagsView current WAMP subscriptions and registrationsPoint your browser tohttp://localhost:8080/monitorand open your javascript consoleHow to run a modelservice as two separate processesIt's sometimes useful to runcrossbarand your own model code as separate processes. By default,run_modelserviceruns crossbar configured to kick off the sub-processrun_guest.  You can change this by doing these 3 simple steps:Get a copy of the currently in use crossbar configuration by running./manage.py run_modelservice --print-config.  This will print the generated configuration file and then run normally.  Simply cut-n-paste the configuration which will be a large JSON blob just before the usual Crossbar log messages.Edit the configuration to remove the entire{"type": "guest", ...}stanza, saved to a file.Run each piece separately.  If we saved our configuration intoconfig.jsonin the current directly this would look like:./manage.py run_modelservice --config=./config.json --loglevel info --settings=simpl-calc.settingsfor the crossbar service and then:HOSTNAME=localhost PORT=8080 ./manage.py run_guest --settings=simpl-calc.settingsfor the modelservice itself.Environment variablesGUEST_LOGLEVELadjust guest process logging, defaults to infoCROSSBAR_LOGLEVELadjust crossbar process logging, defaults to infoProfilingWriting tasksThe profiler will run any method that starts withprofile_one or more times against a different number of workers.Keep in mind that, unlike unit tests, profile tasks are not isolated.MeasuringThemodelservice.utils.instrumentscontains classes for measuring execution times. Check the module's docstrings for details.Collecting resultsYou can collect the result of the task by calling the.publish_stat()method:async def profile_random(self):
        with Timer() as timer:
            some_value = random.random()
        self.publish_stat('<unique stat name>', timer.elapsed, fmt='Average result was {stats.mean:.3f}')Thefmtstring will receive aninstruments.StatAggregatorinstance calledstats.
This object will collect the value from all workers that ran the task and will provide the following properties:.min: The lowest collected value.max: The highest collected value.total: The sum of the collected values.count: The number of collected valuesAdditionally, functions from thestatisticsmoduleare aliased as properties (ie:.mean,.stdev, etc.).Running the profiler anonymouslyRun thesimpl-games-apiserver.From a model service directory, run its server.From the same model service directory, callprofile.sh. You can useprofile.sh -hfor a list of options.Some example anonymous profiling tasks are defined inmodelservice/profiles. These tasks are run
unless you use the-moption to specify a different module path.To run from a model service directory when logged into an AWS instance,
callaws_profile.sh. You can useaws_profile.sh -hfor a list of options.Running the profiler with usersYou can have workers that publish and call on WAMP as specific users. Using the.call()or.publish()methods,
it can call or publish as the user associated with that worker.You have the profiler spawn workers as specific users by passing a file with their emails using the-uoption.You will also need to use the-moption to specify your task's module path (e.gmy_task_module_path).Assuming you have a file calledmyusers.txtwith the following content:s1@mysim.edu
s2@mysim.edu
s3@mysim.eduYou can then call:$profile.sh-mmy_task_module_path-umyusers.txtThis will spawn 3 workers, each one set up to.calland.publishas one of those users.To run from a model service directory when logged into an AWS instance, call:$aws_profile.sh-mmy_task_module_path-umyusers.txtBothprofile.shandaws_profile.shinvoke theprofilemanagement command.Copyright © 2018 The Wharton School,  The University of PennsylvaniaThis program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.