用于实现模拟的python库,构建在crossbar.io和django上。
simpl-modelservice的Python项目详细描述
简单模型服务
用于实现模拟的python库,构建在crossbar.io和django上。
安装
django 2.2
$ pip install simpl-modelservice
django 1.11
$ pip install "simpl-modelservice<0.8.0"
设置开发环境
$ git clone git@github.com:simplworld/simpl-modelservice.git
$ cd simpl-modelservice
$ mkvirtualenv simpl-modelservice
$ pip install -r dev-requirements.txt
$ pip install -e .
运行测试
$ python runtests.py
开发版本控制
安装bumpversion
:
$ pip install bumpversion
然后,要发布新版本,请使用以下命令增加版本号:
$ bumpversion patch
然后推至回购:
$ git push && git push --tags
查看当前WAMP订阅和注册
将浏览器指向http://localhost:8080/monitor并打开javascript控制台
如何将ModelService作为两个独立的进程运行
有时将crossbar和您自己的模型代码作为单独的进程运行是很有用的。默认情况下,run_modelservice
运行配置为启动子进程的crossbar。您可以通过执行以下3个简单步骤来更改此设置:
通过运行
./manage.py run_modelservice --print-config
,获取当前正在使用的crossbar配置的副本。这将打印生成的配置文件,然后正常运行。只需在通常的crossbar日志消息之前剪切并粘贴一个大型json blob配置。编辑配置以删除保存到文件中的整个
{"type": "guest", ...}
节。把每一块分开跑。如果我们直接将配置保存到当前的
config.json
中,这看起来像:./manage.py run_modelservice --config=./config.json --loglevel info --settings=simpl-calc.settings
对于crossbar服务,然后:
HOSTNAME=localhost PORT=8080 ./manage.py run_guest --settings=simpl-calc.settings
对于modelservice本身。
分析
写作任务
分析任务在modelservice/profiles
中定义。
探查器将对不同数量的工作进程运行以profile_
开头的任何方法一次或多次。
请记住,与单元测试不同,概要文件任务不是孤立的。
配置文件用户
您可以让工人作为特定用户发布和调用wamp。通过使用.call()
或.publish()
方法,它将以与该工作进程关联的用户的身份调用或发布。要了解如何运行与用户关联的工作线程,请参见Running profile users。
测量
modelservice.utils.instruments
包含用于测量执行时间的类。查看模块的docstrings以获取详细信息。
收集结果
您可以通过调用.publish_stat()
方法来收集任务的结果:
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}')
fmt
字符串将接收名为stats
的instruments.StatAggregator
实例。此对象将从运行任务的所有工作线程收集值,并提供以下属性:
.min
:最低收集值.max
:最高收集值.total
:收集值的总和.count
:收集值的数目
此外,来自^{.mean
,.stdev
,等等)。
匿名运行探查器
- 运行
simpl-games-api
及其modelservice - 从任何模型中,通过
run_modelservice
或run_guest
运行其modelservice
- 从同一个模型目录中,调用
profile.sh
。您可以使用profile.sh -h
作为选项列表。
要在登录到aws实例时运行任何模型目录,请调用aws_profile.sh
。您可以使用aws_profile.sh -h
作为选项列表。
运行配置文件用户
通过使用-u
选项传递带有电子邮件的文件,您可以让profiler将worker派生为特定用户。
假设您有一个名为myusers.txt
的文件,其中包含以下内容:
s1@mysim.edu s2@mysim.edu s3@mysim.edu
然后您可以拨打电话:
$ profile.sh -u myusers.txt
它将产生3个工作人员,每个工作人员设置为.call
和.publish
作为其中一个用户。
要在登录到aws实例时从任何模型目录运行,请调用:
$ aws_profile.sh -u myusers.txt
profile.sh
和aws_profile.sh
都调用profile
管理命令。
管理ModelService AWS探查器实例
django设置
PROFILER_AWS_KEY
:aws iam访问密钥PROFILER_AWS_SEC
:屁股关联IAM密钥
管理命令
PROFILER_AWS_KEY
:aws iam访问密钥PROFILER_AWS_SEC
:屁股关联IAM密钥
管理命令
aws profiler实例的管理是通过aws_profiler
管理命令执行的。
状态
:# ./manage.py aws_profiler --status
i-0733d74785931f857: stopped -- type: c5.18xlarge -- ip address: 18.216.171.181
开始
:# ./manage.py aws_profiler --start
i-0733d74785931f857: pending -- type: c5.18xlarge -- ip address: 18.216.171.181
停止
:# ./manage.py aws_profiler --stop
i-0733d74785931f857: stopping -- type: c5.18xlarge -- ip address: 18.216.171.181
版权所有©2018沃顿商学院宾夕法尼亚大学
此程序是免费软件;您可以重新分发它和/或 根据GNU通用公共许可条款修改 由自由软件基金会出版;或者是第2版 或(由您选择)任何更高版本。
这个程序的发布是希望它能有用, 但没有任何保证;甚至没有 适销性或适合某一特定目的的适销性。见 GNU通用公共许可证了解更多详细信息。