Chapter 9, The Memory Cache App Engine's memory cache service (aka "memcache"), and its Python and Java APIs. Aggressive caching is essential for high-performance web functions. Chapter 10, Fetching URLs and Web Resources How to access different resources on the Internet via HTTP using the URL Fetch service. This chapter covers the Python and Java interfaces, together with implementations of normal URL fetching libraries. It also describes the asynchronous URL Fetch interface, which as of this writing is exclusive to Python. Chapter eleven, Sending and Receiving Mail and Instant Messages How to use App Engine providers to send e-mail and prompt messages to XMPP-compatible companies . This chapter covers receiving e mail and XMPP chat messages relayed by App Engine using request handlers. It additionally discusses creating and processing messages using tools in the API. Chapter 12, Bulk Data Operations and Remote Access How to carry out giant upkeep operations on your reside software utilizing scripts working in your pc. Tools included with the SDK make it simple to back up, restore, load, and retrieve data in your app's datastore. You can even write your own tools using the distant access API for data transformations and other jobs. You also can run an interactive Python command shell that uses the distant API to manipulate a stay Python or Java app. Chapter thirteen, Task Queues and Scheduled Tasks How to carry out work outside of user requests utilizing task queues. Task queues perform duties in parallel by working your code on a quantity of application servers.
Tasks can be executed on a daily schedule with no person interplay. Chapter 14, The Django Web Application Framework How to use the Django web application framework with the Python runtime surroundings. Chapter 15, Deploying and Managing Applications How to addContent and run your app on App Engine, tips on how to replace and take a look at an software utilizing app versions, and the way to manage and examine the operating utility. This chapter additionally introduces other upkeep features of the Administrator Console, including billing. We conclude with a list of places to go for assist and further studying. To start the event internet server, ensure the project is selected, then click on the Run button. To open the home web page of the working app in a browser, click the Browse button. The Logs button displays messages logged by the app within the improvement server. The Edit button opens the project's information in your default text editor. In the Mac OS X model, that is especially helpful with textual content editors that can open a directory's worth of information, such as TextMate or Emacs. Before you probably can deploy a project, you should register an application ID with App Engine and edit the application's configuration file with the registered ID. The Dashboard button opens a browser window with the App Engine Administration Console for the deployed app. We'll have a glance at the configuration file, the registration course of, and the Administration Console later on this chapter. The complete App Engine Python SDK, including the command-line tools, resides within the Launcher's application listing. In the Windows version, the installer provides the suitable listing to the command path, so you probably can run these instruments from a Command Prompt. With the links on this listing, you'll be able to type just the name of a command at a Terminal prompt to run it. If you didn't create the symlinks, you can do so later by choosing the Make Symlinks... You can set command-line flags for the event server inside the Launcher. To do so, select the applying, then go to the Edit menu and select Application Settings.... Add the specified command-line options to the "Extra Flags" field, then click Update.
The Mac OS X version of the Launcher installs Google's software program replace facility to verify for brand new variations of the App Engine SDK. When a model new version is released, this feature notifies you and provides to improve. Immediately after you upgrade, you'll discover the symlinks stop working. To fix the symlinks, reopen the Launcher app and observe the prompts. The upgrade can't do this automatically as a result of it wants your permission to create new symlinks. Developer Tools Google provides free instruments for growing App Engine purposes in Java or Python. You can obtain the software improvement kit in your chosen language and your computer's working system from Google's website. Java users can get the Java SDK in the type of a plug-in for the Eclipse built-in growth surroundings. Python customers utilizing Windows or Mac OS X can get the Python SDK in the type of a GUI utility. Both SDKs are additionally obtainable as ZIP archives of command-line tools, for using instantly or integrating into your improvement setting or build system. Each SDK features a development internet server that runs your application on your native pc and simulates the runtime environment, the datastore, and the companies. The growth server routinely detects changes in your supply files and reloads them as needed, so you can maintain the server operating while you develop the application. If you're utilizing Eclipse, you probably can run the Java development server in the interactive debugger, and might set breakpoints in your utility code.
You also can use Eclipse for Python app growth utilizing PyDev, an Eclipse extension that includes an interactive Python debugger. You can flip this characteristic off for testing whether or not queries have applicable indexes within the configuration. The development web server features a built-in web application for inspecting the contents of the datastore. You can also create new datastore entities utilizing this interface for testing purposes. Each SDK also features a tool for interacting with the appliance operating on App Engine. Primarily, you utilize this device to addContent your application code to App Engine. You can even use this tool to download log data out of your live software, or manage the live application's indexes. Queries and Indexes A datastore query returns zero or extra entities of a single kind. It can also return just the keys of entities that may be returned for a query. A query can filter based on circumstances that should be met by the values of an entity's properties, and can return entities ordered by property values. In a typical relational database, queries are deliberate and executed in actual time in opposition to the data tables, that are saved as they have been designed by the developer. The developer also can inform the database to provide and keep indexes on certain columns to speed up certain queries. With App Engine, every query has a corresponding index maintained by the datastore.
Of course, this requires that App Engine know ahead of time which queries the application is going to perform. App Engine provides a set of indexes for easy queries by default, based mostly on which properties exist on entities of a kind. For more complicated queries, an app must include index specifications in its configuration. The App Engine SDK helps produce this configuration file by watching which queries are performed as you check your utility with the provided development web server on your computer. When you upload your app, the datastore is aware of to make indexes for each query the app performed throughout testing. When your software creates new entities and updates current ones, the datastore updates every corresponding index. This makes queries very fast on the expense of entity updates . In truth, the efficiency of an index-backed query isn't affected by the number of entities in the datastore, only the scale of the result set. It's price listening to indexes, as they take up area and increase the time it takes to replace entities. Using Django Unit Tests and Fixtures The Django App Engine Helper includes help for unit checks utilizing Django's unit check runner and the App Engine development server. The unit check runner runs exams inside the event server's surroundings, so exams can access the simulated companies, together with the simulated datastore. The take a look at runner helps exams outlined with the usual Python libraries unittest or doctest, or different check frameworks with take a look at runner customizations. Django provides its own class for defining unittest test instances, called django.test.TestCase, which adds several Django-specific features. For unittest checks, the runner appears in files in the Django utility listing (e.g., bookstore/) named fashions.py and checks.py for classes that inherit from unittest.TestCase or django.take a look at.TestCase.
Each method of a check case class whose name begins with check is a separate take a look at. For each test, the runner initializes the test environment, instantiates the TestCase class, and calls the strategy for the check. If the category defines a setUp() technique, it calls it before each check. If the class defines a tear Down() technique, it calls it after every take a look at. You can use setUp() and tearDown() to create and clear up check knowledge and preparation for each take a look at in a test case. The TestCase class supplies strategies that trigger the take a look at to report failure if the circumstances examined aren't met. Self.assertEqual() takes two arguments, and causes the test to fail if the arguments usually are not equal. Self.assert_() takes one argument, and fails the test if the argument is a false value . Self.assertRaises() takes an exception class, a callable object, and arguments for the callable object, calls the callable, then fails the take a look at if the callable does not raise the given exception. Each of those methods takes an optional message argument that is printed within the test report if the test fails. __init__.py A file that tells Python that code recordsdata in this listing can be imported as modules . Manage.py A command-line utility you will use to build and handle this project, with many options. Settings.py Configuration for this project, in the form of a Python source file. Urls.py Mappings of URL paths to Python code, as a Python supply file. If you're following together with a Django tutorial or guide, the subsequent step is usually to start out the Django improvement server utilizing the handle.py command. If you probably did so now, you'd be running the Django server, but it might know nothing of App Engine. To run the project within the App Engine growth server, we should join the Django project to the App Engine runtime setting using a request handler script and configuration in the app.yaml file. Entities, Keys, and Properties The App Engine datastore is best understood as an object database. An entity has a key that uniquely identifies the thing throughout the complete system. If you might have a key, you probably can fetch the entity for the necessary thing quickly.
Keys may be stored as information in entities, such as to create a reference from one entity to another. A key has several parts, a few of which we'll discuss right here and some of which we'll cowl later. One part of the secret's the application's ID, which ensures that nothing else about the vital thing can collide with the entities of some other utility. It also ensures that no different app can entry your app's data, and that your app can not entry information for other apps. You won't see the app ID talked about within the datastore API; this is automated. An entity's sort categorizes the entity for the needs of queries, and for guaranteeing the distinctiveness of the the rest of the key. For example, a purchasing cart software may represent every buyer order with an entity of the sort "Order." The application specifies the kind when it creates the entity. This could be an arbitrary string specified by the app, or it may be generated mechanically by the datastore. The API calls an entity ID given by the app a key name, and an entity ID generated by the datastore an ID. This applies to all elements of its key, together with the type and the key name or ID. Each worth is of one of a number of supported information sorts, corresponding to a string, an integer, a date-time, or a null worth.
We'll look at property value varieties in detail later in this chapter. A property can have multiple values, and each value may be of a unique kind. As you will notice in "Multivalued Properties" on web page 113, multivalued properties have unusual conduct, however are quite useful for modeling some sorts of information, and surprisingly environment friendly. Static Files and Resource Files Most net applications have a set of recordsdata which would possibly be served verbatim to all users, and don't change as the appliance is used. To velocity up the delivery of these recordsdata and enhance web page rendering time, App Engine makes use of dedicated servers for static content. Using dedicated servers also means the app servers don't have to spend assets on requests for static information. Both the deployment process and the frontend must be informed which of the application's recordsdata are static information. The deployment course of delivers static information to the dedicated servers. The frontend remembers which URL paths check with static files, so it can route requests for those paths to the suitable servers. The static file configuration also can embrace a advice for a cache expiration interval.
App Engine returns the cache instructions to the shopper in the HTTP header together with the file. If the shopper chooses to heed the recommendation, it'll retain the file for up to that amount of time, and use its local copy instead of asking for it again. This reduces the amount of bandwidth used, but on the expense of browsers retaining old copies of information which will have changed. To save area and cut back the quantity of information involved when setting up new app situations, static files usually are not pushed to the applying servers. This means application code can not entry the contents of static information using the filesystem. Application code can entry these information by studying them from the filesystem. How Indexes Are Updated As we noticed in Chapter 5, datastore queries are powered by indexes. The datastore updates these indexes as entities change, so results for queries can be determined with out inspecting the entity properties directly. This includes an index of keys, an index for every kind and property, and customized indexes described by your app's configuration files that fulfill complicated queries. When an entity is created, up to date, or deleted, every relevant index is updated and sorted so subsequent queries match the new state of the data. The datastore updates indexes after adjustments have been dedicated, in the course of the apply section. Updates of indexes are themselves performed in parallel, so the number of indexes to update doesn't essentially have an result on how fast the replace occurs.
As with entities, the datastore retains a number of variations of index data, labeled with timestamps. When you carry out a question, the datastore notes the present time, then uses the index information that is most current up to that time. However, until the query has an ancestor filter, the datastore has no approach to know which entity groups are concerned in the result set and so can not await adjustments in progress to be utilized. This implies that, for a brief period during an update, a question could return results that don't match the query standards. While one other course of is updating an entity, the query might even see the old model of its index but return the brand new version of the entity. And since adjustments to entities and adjustments to indexes are utilized in parallel, it is possible for a question to see the model new version of its index however return the old model of the entity. Figure 6-3 illustrates one risk of what nontransactional reads and queries might even see whereas adjustments are being applied. The ConfigureRemoteApi() function sets up the distant API access. It takes as arguments the appliance ID, the remote API handler URL path, and a callable that returns a tuple containing the email handle and password to make use of when connecting. In this example, we outline a operate that prompts for the e-mail handle and password, and move the perform to ConfigureRemoteApi(). The function also accepts an optional fourth argument specifying an alternate domain name for the connection. By default, it makes use of app-id.appspot.com, where app-id is the application ID within the first argument. The MaybeInvokeAuthentication() function sends an empty request to confirm that the email handle and password are appropriate, and raises an exception if they don't seem to be. This is inevitably slower than operating throughout the reside software. It also consumes utility sources like net requests do, including bandwidth and request counts, which aren't usually consumed by service calls in the stay app. On the plus aspect, since your code runs in your native pc, it isn't constrained by the App Engine runtime sandbox or the 30-second request deadline. You can run lengthy jobs and interactive applications on your pc with out restriction, utilizing any Python modules you like—at the expense of consuming app assets to marshal service calls over HTTP. In real life, it's potential for an entity that does not match a model to exist within the datastore. When you modify a mannequin class—and you'll change model courses within the lifetime of your application—you are making a change to your application code, not the datastore.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.