Scalability and ZEO ################### .. include:: includes/zope2_notice.rst When a web application receives more requests than it can handle over a short period of time, it can become unresponsive. In the worst case, too many concurrent requests to a web application can cause the software which services the application to crash. This can be a problem for any kind of web-based app, not just those which are served by Zope. The obvious solution to this problem is to use more than one server. When one server becomes overloaded, the others can then hopefully continue to successfully serve requests. By adding additional servers to this kind of configuration, you can "scale" your web application as necessary to meet demand. Using multiple servers has obvious benefits, but it also poses serious challenges. For example, if you have five servers, then you must ensure that all five server installations are populated with the same information. This is not a very hard task if you have only a few static web pages, but for larger applications with large bodies of rapidly changing information, manually synchronizing the data which drives five separate server installations is almost impossible, even with the "out of the box" features that Zope provides. A "stock" Zope installation uses the Zope Object Database as its content store, using a "storage" which is named a "FileStorage". This storage type (there are others) keeps all of your Zope data in a single file on your computer's hard drive, typically named `Data.fs`. This configuration works well until you need to add an additional Zope server to your site to handle increased traffic to your web application. Two Zope servers cannot share this file. The file is "locked" by one Zope server and no other Zope server can access the file. Thus, in a "stock" Zope configuration, it is impossible to add Zope servers which read from the same database in order to "scale" your web application to meet demand. To solve this problem, Zope Corporation has created another kind of "storage", which operates using a client/server architecture, allowing many Zopes to share the same database information. This product is known as `Zope Enterprise Objects` or ZEO. ZEO is built into Zope, no additional software install is required. This chapter gives you a brief overview on installing ZEO, but there are many other options we don't cover. For more in-depth information, see the documentation that comes with the ZEO package. What is ZEO? ============ ZEO is a system that allows you to share a Zope Object Database between more than one Zope process. By using ZEO, you may run multiple instances of Zope on a single computer or on multiple computers. Thus, you may spread requests to your web application between Zope servers. You may add more computers as the number of requests grows, allowing your web application to scale. Furthermore, if one Zope server fails or crashes, other servers can still service requests while you fix the broken one. ZEO takes care of making sure each Zope installation uses consistent information from the same Zope Object Database. ZEO uses a client/server architecture. The Zope processes (shown on multiple computers in the diagram below) are the *ZEO Clients*. All of the clients connect to one, central *ZEO Storage Server*, as shown in the image below. .. figure:: Figures/11-1.png Simple ZEO illustration The terminology may be a bit confusing. Typically, you may think of Zope as a server, not a client. But when using ZEO, your Zope processes act as both servers (for web requests) and clients (for data from the ZEO server). ZEO clients and servers communicate using standard Internet protocols, so they can be in the same room or in different countries. ZEO, in fact, could distribute a Zope site to disparate geographic locations, given good network connectivity between the ZEO clients and the ZEO server. In this chapter we'll explore some interesting ways you can distribute your ZEO clients. When you should use ZEO ======================= Using a ZEO-based installation is advantageous for almost all users. Here are some of the reasons: - Zope is a high-performance system, and one Zope can handle millions of hits per day, but there are upper bounds on the capacity of a single Zope server. ZEO allows you to scale your site by adding more hardware on which you may place extra Zope servers to handle excess demand. - Your site is critical and requires 24/7 uptime. Using ZEO can help you add redundancy to your server configuration. - You want to distribute your site to disparate geographic locations in order to increase response time to remote sites. ZEO allows you to place Zope servers which use the same ZODB in separate geographic locations. - You want to "debug" an application which is currently served by a single Zope server from another Zope process. ZEO enables the developer to attach to a ZODB database while still continuing to serve requests from another ZEO client. Installing, configuring, and maintaining a ZEO-enabled Zope requires some system administration knowledge. Most Zope users will not need ZEO, or may not have the expertise necessary to maintain a distributed server system like ZEO. ZEO is fun, and can be very useful, but before jumping head-first and installing ZEO in your system you should weigh the extra administrative burden ZEO creates against the simplicity of running just a simple, stand-alone Zope. Installing and Running ZEO ========================== ZEO is part of Zope, all batteries are included. However, there are some prerequisites before you will be successfully able to use ZEO: - All of the Zope servers in a ZEO-enabled configuration must run the same version of Zope and ZEO. The easiest way to meet this prerequisite is to make sure all of your computers use the same Zope version. - All of your ZEO clients must have the same third party Products installed and they must be the same version. This is necessary, or your third-party objects may behave abnormally or not work at all. - If your Zope system requires access to external resources, like mail servers or relational databases, ensure that all of your ZEO clients have access to those resources. - Slow or intermittent network connections between clients and server degrade the performance of your ZEO clients. Your ZEO clients should have a good connection to their server. Installing ZEO is very easy. After you have gone through the steps necessary to build the Zope software it takes nothing more than running two scripts and tweaking the default configuration laid down in the ZEO client's `zope.conf` configuration file. First, you need to create a place where the ZEO server will live. It also contains the database file, so make sure you have enough space to cover your expected database size and at least double that so you can pack the ZODB:: $ python /path/to/Zope/bin/mkzeoinstance.py /path/to/zeostorage Make sure you use the same python interpreter that was used to build your Zope software. `/path/to/zeostorage` represents the location where you want the ZEO server to be. While the script runs you will see output telling you what it is doing. Once you have built the ZEO server's home this way you will notice that its layout is very similar to a Zope instance home. It has a configuration file named `zeo.conf` inside its etc-subdirectory which you should look at to get a notion of what can be configured, and you will need it to look up where the server will listen for ZEO requests when you configure your ZEO clients. The ZEO storage home also contains prefabricated start/stop scripts that work the same way as the Zope `zopectl` script, for ZEO it is called `zeoctl`. You should now have ZEO properly installed. Try it out by first starting the server. In a terminal window or DOS box type:: $ /path/to/zeostorage/bin/zeoctl start You can follow its log file by simply typing:: $ /path/to/zeostorage/bin/zeoctl logtail or by looking at the log file directly. Its location is configurable using the previously mentioned zeo.conf configuration file. After having set up the ZEO storage server that way you will want at least one ZEO client. You can use an existing Zope server (provided it meets the prerequisites mentioned earlier) or build a new instance home the same way you would if you set up a new Zope server without ZEO:: $ python /path/to/Zope/bin/mkzopeinstance Now visit the instance home you created and look for the `zope.conf` configuration file in its etc-directory. In order to use ZEO the client must be told to access the ZODB not from the file system but talk to a ZEO server instead. Look for the:: zodb_db main directive at the bottom. Underneath the default configuration you will notice an example ZEO client configuration. Comment out the complete zodb_db main stanza containing the `filestorage` directive and uncomment the example zodb_db main configuration that contains the:: zeoclient directive. If you have not tweaked your zeo.conf file all you need to do at this moment is to ensure that the `server` argument in the `zeoclient` directive shows the same value as the `address` argument in the `zeo` directive inside your ZEO server's zeo.conf-file. Now you are ready to test the ZEO client. Fire it up by running:: $ /path/to/zeoclient/bin/zopectl start and check the log file manually or by running:: $ /path/to/zeoclient/bin/zopectl logtail Now visit the Zope Managment Interface (ZMI) of your ZEO client in a web browser and go to the *Control Panel*. Click on *Database Managment*. Here, you see that Zope is connected to a *ZEO Storage* and that its state is *connected*. Running ZEO on one computer is a great way to familiarize yourself with ZEO and how it works. Running a single ZEO client does not however, improve the speed of your site, and in fact, it may slow it down just a little. To really get the speed benefits that ZEO provides, you need to run multiple ZEO clients. This can easily be achieved by creating more ZEO client instances as described above. The instances can be on the same server machine or distributed over several machines. How to Distribute Load ====================== Imagine you have a ZEO server named *zooServer* and three ZEO clients named *zeoclient1*, *zeoclient2*, and *zeoclient3*. The three ZEO clients are connected to the ZEO server and each client is verified to work properly. Now you have three computers that serve content to your users. The next problem is how to actually spread the incoming web requests evenly among the three ZEO clients. Your users only know about *www.zopezoo.org*, not *zeoclient1*, *zeoclient2* or *zeoclient3*. It would be a hassle to tell only some users to use *zeoclient1*, and others to use *zeoclient3*, and it wouldn't be very good use of your computing resources. You want to automate, or at least make very easy, the process of evenly distributing requests to your various ZEO clients. There are a number of solutions to this problem, some easy, some advanced, and some expensive. The next section goes over the more common ways of spreading web requests around various computers using different kinds of technology, some of them based on freely-available or commercial software, and some of them based on special hardware. User Chooses a Mirror +++++++++++++++++++++ The easiest way to distribute requests across many web servers is to pick from a list of *mirrored sites*, each of which is a ZEO client. Using this method requires no extra software or hardware, it just requires the maintenance of a list of mirror servers. By presenting your users with a menu of mirrors, they can use to choose which server to use. Note that this method of distributing requests is passive (you have no active control over which clients are used) and voluntary (your users need to make a voluntary choice to use another ZEO client). If your users do not use a mirror, then the requests will go to your ZEO client that serves *www.zopezoo.org*. If you do not have any administrative control over your mirrors, then this can be a pretty easy solution. If your mirrors go off-line, your users can always choose to come back to the master site which you *do* have administrative control over and choose a different mirror. On a global level, this method improves performance. Your users can choose to use a server that is geographically closer to them, which probably results in faster access. For example, if your main server was in Portland, Oregon on the west coast of the USA and you had users in London, England, they could choose your London mirror and their request would not have to go half-way across the world and back. To use this method, create a property in your root folder of type *lines* named "mirror". On each line of this property, put the URL to your various ZEO clients, as shown in the figure below. .. figure:: Figures/11-2.png Figure of property with URLs to mirrors Now, add some simple TAL code to your site to display a list of your mirrors::

Please choose from the following mirrors: Or, in a Script (Python)::: ## Script (Python) "generate_mirror" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=a, b ##title= ## print "

Please choose from the following mirrors: