Creating a ceilometer alarm requires 4 DB operations:
api/controllers/v2/alarms.py
1. Every time Is_over_quota needs to query all the alarms of the User/project
2. Determine if alarm name already exists in DB, and you need to query all alarms of the User/project
# Make sure alarms is unique by name per project.
Alarms = List (Conn.get_alarms (Name=data.name,
PROJECT=DATA.PROJECT_ID))
3. Add Alarm Line
Alarm = conn.create_alarm (alarm_in)
4. Add a Alarm history
Self._record_creation (conn, change, alarm.alarm_id, now)
Optimization considerations:
1. Is_over_quota, you can create a global compute data structure and lock the multi-API workers, which gets the initialization value from the DB when the service starts.
2. Determine if alarm name already exists in the DB, and name as the table's key value, you do not need to get all alarms of user/project first.
Ceilometer db operation and optimization during alarm creation