OpenStack Performance tuning

So,  you’ve managed to deploy OpenStack in a production environment, and now you would like to make sure that your precious investment in hardware doesn’t get ruined by poor performance tuning. You might want to consider reading this post.

You have to remember first that OpenStack is a Cloud Computing Enabler framework, i.e. none of the computations/file transfers done by your VMs are processed by OpenStack services. OpenStack relies on Linux native technologies such as libvirt, qemu, KVM, network namespaces and so on to implement various features. So your target for performance tuning are NOT ONLY OpenStack services, they could be Linux native services as well.

Performance tuning for OpenStack services

To do that, consider the following enhancements:

  • One thing that is mostly forgotten after deploying a production environment is disabling verbose and debugging logging. You probably spent sometime deploying your environment and getting it to where it is. And probably during this cycle you had to enable debugging in some services and verbose logging on others. Remember to go back and disable all of these. File IOPS will forsure reduce performance. You can do that by setting those options to false in nova.conf, neutron.conf, cinder.conf and keystone.conf
verbose=false
debug=false
  • OpenStack supporting services: Don’t forget that mariadb/mysql and rabbitmq/amqp are still your environment’s backbone. Slowness in any of the supporting services will directly result in every service within openstack using it being slow. Keep close attention to your mysql bufferes and rabbitmq caches. A good feature in mysql/mariadb is slow query log.  The long_query_time variable has to be set to a value that , if exceeded, will have the query logged to the slow query log. This is good to know if you have database slowness.
    .
  • Is keystone accessing the database for every single transaction? Keystone sits at the heart of all of the services as it’s the auth service. Too many users accessing the environment and generating lots of tokens may choke your mysql database performance. Make sure that keystone is configured to store its tokens in memcached instead.
    .
  • How large is your nova database ? Did you know that OpenStack keeps a record for every instance you create ? I am sure you knew that, but did you know that it also keeps a record after you delete that instance ? Check out this tool to clean up the nova database  https://gist.github.com/mousavian/d68bcd903207366c1bfd
    .
  • Do you have any backends in cinder.conf that you’r not using ? Have you configured multiple of these but only are using one? consider cleaning this out. A short look in cinder logs will show it’s complaining about the unused backend
    .
  • What’s your store for glance images ? Is it a filesystem_store_datadir  sitting on the controller node ? If you don’t have the option to change this one to a network based storage, ensure it sits on a different LUN/HDD/SDD than the OS and Openstack services on the controller. Glance is not only used for providing images during a VM’s boot, those images get cached eventually at the compute hosts so it’s not going to be a big deal for performance. But it is also used for users taking snapshots of their ephemeral VMs. Don’t leave the environment prone to slowness as users take snapshots of their VMs
    .
  • Adding to the previous question, it’s always better to keep the APIs for OpenStack services on a network other than the data network, i.e. the network where glance transfers images, CEPH transfers its RBDs and such.
    .
  • Are you using CEPH ? Is your OSDs replication traffic and RBDs traffic going on the same network ? consider splitting this out to two different networks

This is not all.  But it covers to some extent the common architecture and implementation issues that can affect performance. There are plenty of tutorials out there that discuss how to optimize libvirt, qemu/kvm, Apache , network stack, CEPH. These are all your targets if you want to optimize the actual performance of VMs and volumes. 

 

 

 

 

Private External Networks in Neutron

You might find yourself in a position where you need to restrict access by tenants to specific external networks. In Openstack there’s the notion that external networks are accessible by all tenants and anyone can attach their private router to it. This might not be the case if you want to only allow specific users to access a specific external networks.

There is no way to directly configure this in neutron. I.e. Any external network that you have in your deployment basically can have tenants attach their routers to it and make it their default gateway. In order to work around this, let’s look into how neutron saves router and ports in the neutron database schema , a router is defined as follows

 

MariaDB [neutron]> desc routers$$
+——————+————–+——+—–+———+——-+
| Field | Type | Null | Key | Default | Extra |
+——————+————–+——+—–+———+——-+
| project_id | varchar(255) | YES | MUL | NULL | |
| id | varchar(36) | NO | PRI | NULL | |
| name | varchar(255) | YES | | NULL | |
| status | varchar(16) | YES | | NULL | |
| admin_state_up | tinyint(1) | YES | | NULL | |
| gw_port_id | varchar(36) | YES | MUL | NULL | |
| enable_snat | tinyint(1) | NO | | 1 | |
| standard_attr_id | bigint(20) | NO | UNI | NULL | |
| flavor_id | varchar(36) | YES | MUL | NULL | |
+——————+————–+——+—–+———+——-+

each router has an id, name, project ID where it’s created under. You will notice also the field gateway_port_id. This is the port that connects the tenant router to its default gateway. i.e. your external network

Each router has a unique port for gateway. Tenant routers do not share a common port. Let’s look how a port looks like in the database schema

MariaDB [neutron]> desc ports$$
+——————+————–+——+—–+———+——-+
| Field | Type | Null | Key | Default | Extra |
+——————+————–+——+—–+———+——-+
| project_id | varchar(255) | YES | MUL | NULL | |
| id | varchar(36) | NO | PRI | NULL | |
| name | varchar(255) | YES | | NULL | |
| network_id | varchar(36) | NO | MUL | NULL | |
| mac_address | varchar(32) | NO | | NULL | |
| admin_state_up | tinyint(1) | NO | | NULL | |
| status | varchar(16) | NO | | NULL | |
| device_id | varchar(255) | NO | MUL | NULL | |
| device_owner | varchar(255) | NO | | NULL | |
| standard_attr_id | bigint(20) | NO | UNI | NULL | |
| ip_allocation | varchar(16) | YES | | NULL | |
+——————+————–+——+—–+———+——-+

As you can see , a port has an id and a network_id where it’s attached to. Note that in the ports table, network_id refer to both external and “tenant” networks.

If we know our external network ids, we can tell what ports are attached to them, and possibly enable/disable future attachments. To know our external network ids, it’s easy to run

(neutron) net-external-list

This will show you the IDs for the external networks and then with a simple query you can select from the ports table what ports are attached to your external network

select id from ports where network_id=$NETWORK_ID’ $$

This returns a list of the ports currently connected to your external network.

If you want to disable tenants from attaching anything (routers or floating IPs) to this external network, you can acheive this by using a BEFORE TRIGGER in mysql

DELIMITER $$

create trigger ports_insert before insert on ports for each row begin IF (new.network_id = ‘$NETWORK_ID’) then set new.id = NULL ; END IF ; END $$

 

This trigger basically changes the insert statement that neutron writes to the database when a tenant attaches a router to your external network. It sets the ID of the new port to NULL, which is invalid for this field as seen from the above description of the ports table. This effectively disables any routers/floating ips to be attached to the external network you choose. But remember , you’r also included in that, you can’t attach anything to this external network even as admin. You can always tweak the trigger to check project_id field and only restrict access to specific projects

 

 

 

 

 

 

 

 

 

 

 

 

Busy Cinder volumes & Ceph

If you run into an issue where a Cinder volume you attached to a VM can not be deleted even after detaching it from the VM, and when you look into the logs you find something like

ERROR cinder.volume.manager ....... Unable to delete busy volume.

or

WARNING cinder.volume.drivers.rbd ......... ImageBusy error raised while deleting rbd volume. This may have been caused by a connection from a client that has crashed and, if so, may be resolved by retrying the delete after 30 seconds has elapsed.

There are multiple scenarios that might cause these errors, among which are:

  • Scenario 1: First error message mentioned above, You mighthave created a snapshot of the volume, whether inside cinder or directly from ceph rbd command line. Ceph will not allow you to delete a volume that has snapshots attached to it. The snapshots on the volume can be listed by
    • rbd snap ls POOLNAME/VOLUMEid
    • And then the snapshots can be purged by (only if the snapshots were created outside cinder) :
    • rbd snap purge POOLNAME/VOLUMEid

      If you have the volume snapshots created inside cinder , it’s definitely better to clear them from inside cinder instead.

  • Scenario 2: The other scenario is that libvirt on one of the compute nodes is still attached to that volume (the second error message above). This could happen if the VM did not terminate correctly or the detachment didn’t actually happen. To verify that , you will need to list the watchers of the rbd using
    • rbd status POOLNAME/VOLUMEid
    • This will show you the IP of the watcher (the compute node in this case) and the cookie used for the connection

One possibility of this scenario is that a VM did not fully release the volume, i.e detach. To release it, you will have to restart the VM making sure that qemu process has no reference to the volume ID. You might have read that you need reboot the compute node, to release the detachment,  but you don’t have to do that if you can just restart the VM with ensuring no attachment to the volume in the qemu process.

Hope that helps !

 

Ceph RBD snapshots for an attached volume

You might find yourself in a scenario where you need to backup a CEPH volume attached to an Openstack Instance. CEPH snapshots come automatically to mind as the “state-in-time” solution. Once you take a CEPH snapshot, you can export it and backup the volume either as a physical file or at the file system level, possibly by mounting it.

Openstack allows you to use cinder to initiate the volume snapshots. The other option is to initiate CEPH snapshots yourself using the “rbd snap create” command. In either cases, taking a CEPH snapshot allows you to get the volume in-time state which you can later export using “rbd  export”. The one drawback with snapshotting a volume attached to a running VM is that the snapshot happens without the VM knowing about it. This inheritely might cause file system consistency issues in the backup snapshot and can cause the VM to freeze as the volume becomes briefly unavailable during the snapshot taking.

The solution to the VM freezing issue is to instruct libvirt to enable RBD caching. This can be achieved by adding the following line under the libvirt section in nova.conf on the compute node.

disk_cachemodes=”network=writeback”

You will need to restart nova services on the compute host, after that RBD caching will be enabled for nova on the compute host and will prevent the VM from freezing after the snapshot is taken. You can find more on RBD caching configuration options in:

https://www.sebastien-han.fr/blog/2013/08/22/configure-rbd-caching-on-nova/