- Managing Global Settings with OptionManager
- Collecting Logs Using DiagnosticManager
- Sharing Sessions Among Different Applications
- Using Single Sign-On from the VI SDK to CIM
- Downloading and Uploading Files Using HTTP Access
- Multithreading with the VI SDK
- Following Best Practices for Performance and Scalability
- Considering Internationalization
Following Best Practices for Performance and Scalability
This section is not intended to be a general guide for improving performance and scalability; instead, it focuses on how to get better performance and scalability from the VI SDK.
The general principles for performance and scalability still hold; for example, don't optimize your code unless you have to.
When designing a VI SDK application, consider the following:
Use VirtualCenter instead of individual hypervisors as a target server for the VI SDK. VirtualCenter has more functionalities than ESX. From a scalability point of view, your application can scale with VirtualCenter.
If your application tries to manage 100 hosts, for instance, you must have 100 connections if you're talking to individual hosts. When a virtual machine is moved from one host to the other, you have to track it down from host to host. If you use a VirtualCenter managing these ESXes, you can shift the burden to the VirtualCenter. One connection to VirtualCenter saves almost all the tedious work for you.
There is a limitation with VirtualCenter server in terms of the number of hypervisors and virtual machines it can manage.  Your application can always connect to multiple VirtualCenter servers to scale beyond one VirtualCenter coverage.
Use as few sessions as possible. The sessions take system resources and use locks on the server side. The slowdown ultimately affects all the VI SDK clients in that the calls to the server are slower to return. This is, of course, out of the control of a single client. Even if your client behaves perfectly well, it might still be affected by others.
If your application is deployed with many concurrent clients, the one-client, one-session approach doesn't scale, especially when your target is VirtualCenter. Instead, consider having your own backend server that connects to a server with a single session.
Avoid a big dataset in a single call. Most of the time, you should be fine. It can be a problem when it comes to retrieving performance data, which could be several megabytes of data returned. This puts the pressure on both the server and the client, where the data has to be marshaled to and unmarshaled from SOAP XML. If the client side uses the DOM parser, it also uses a lot of memory.
In general, specify as much criteria as possible to restrict your dataset as small as possible. In the performance statistics case, you should use the CSV format over the array for better performance.
Use batch processing methods when possible. Some operations can have batch processing in which multiple entities can be manipulated. For example, the ClusterComputeResource has two methods: moveHostInto_Task() and moveInto_Task(). The former moves one host into a cluster at a time, and the latter moves multiple hosts at a time. The latter works faster, in that it causes fewer rounds of communication.
There is a problem with batch processing methods in the VI SDK: they are not atomic. If something goes wrong, the VI SDK just stops there and returns. Whatever is or is not yet processed stays as it is. The VI SDK doesn't roll back the already processed one. So when faults happen, you need to take care of the half-baked cake by yourself. Or, just go with the one-call, one-entity scheme. This is a trade-off between performance and atomicity.
Design and implement your local cache. It's not worthwhile if it is a simple utility application. But for a big application that requires extensive interaction with VirtualCenter or ESX, it makes a lot of sense.
First, your application can have instant access of cached information. Second, it saves the number of calls to the server as well as the workload on the server. The same server can work faster and serve more clients.
Whenever you have a cache and care about freshness, you must consider how to sync it with the server. The VI SDK has a waitForUpdate() method that blocks the current thread and returns when updates come up on the server. Clearly, you shouldn't have multiple threads waiting for update, but one to keep the cache synchronized with the server. Be careful with the synchronization of multiple threads on the client application.
VI Java API 2.0 includes a caching framework that handles most of the burden for you. All you need to do is specify what properties to cache and monitor on what managed objects, and then retrieve the properties in the same way as from a hash table. It's multithread safe and can be used in large applications.