from o2common.helper import o2logging\r
logger = o2logging.get_logger(__name__)\r
\r
+\r
+engine = create_engine(\r
+ config.get_postgres_uri(),\r
+ isolation_level="REPEATABLE READ",\r
+ pool_size=200, max_overflow=0,\r
+ pool_recycle=3600\r
+)\r
+\r
DEFAULT_SESSION_FACTORY = sessionmaker(\r
- bind=create_engine(\r
- config.get_postgres_uri(),\r
- isolation_level="REPEATABLE READ",\r
- )\r
+ autocommit=False, autoflush=False, bind=engine\r
)\r
\r
\r
class SqlAlchemyUnitOfWork(AbstractUnitOfWork):\r
+\r
def __init__(self, session_factory=DEFAULT_SESSION_FACTORY):\r
self.session_factory = session_factory\r
\r
with uow:
# get default engine if uow is by default
engine = uow.session.get_bind()
+
wait_for_db_ready(engine)
o2ims_orm.start_o2ims_mappers(engine)
o2dms_orm.start_o2dms_mappers(engine)
--- /dev/null
+# locust for load testing
+
+## Start procedure
+
+Here is the sample command to run one master worker with 7 sub worker
+
+```bash
+# main worker:
+locust -f ocloud.py -H http://128.224.115.34:30205 --master
+
+# worker_1:
+locust -f ocloud.py --worker
+#worker_2:
+locust -f ocloud.py --worker
+#worker_3:
+locust -f ocloud.py --worker
+#worker_4:
+locust -f ocloud.py --worker
+#worker_5:
+locust -f ocloud.py --worker
+#worker_6:
+locust -f ocloud.py --worker
+#worker_7:
+locust -f ocloud.py --worker
+```
+
+If you can use goreman to run [goreman](github.com/mattn/goreman), feel free to use it.
+
+```bash
+cat Procfile<<
+ocloud: locust -f ocloud.py -H http://128.224.115.34:30205 --master
+ocloud_1: locust -f ocloud.py --worker
+ocloud_2: locust -f ocloud.py --worker
+ocloud_3: locust -f ocloud.py --worker
+ocloud_4: locust -f ocloud.py --worker
+ocloud_5: locust -f ocloud.py --worker
+ocloud_6: locust -f ocloud.py --worker
+ocloud_7: locust -f ocloud.py --worker
+>>EOF
+```
+
+Run locust with 7 sub workers through goreman
+```bash
+goreman -f Procfile start
+```
\ No newline at end of file
--- /dev/null
+# Copyright (C) 2021 Wind River Systems, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from locust import HttpUser, task, constant
+
+
+class QuickstartUser(HttpUser):
+ wait_time = constant(0)
+
+ @task
+ def ocloud(self):
+ self.client.get("/o2ims_infrastructureInventory/v1/")
+
+ @task
+ def resource(self):
+ resp = self.client.get(
+ "/o2ims_infrastructureInventory/v1/resourcePools")
+ json_resp_dict = resp.json()
+ self.client.get(
+ "/o2ims_infrastructureInventory/v1/resourcePools/%s/resources" %
+ json_resp_dict[0]['resourcePoolId'])
+
+ def on_start(self):
+ pass