2

My new site (to read books) actually uses static content to serve the pages: I have the HTML file saved in a folder and, to serve the page, I read it and pass the content to a jinja2 template, to show all together. No database hits except for get the book ID to know the title.

This is working fine and fast, but it is obvious that I must "upload" every new book with the "Deploy" option from GAE SDK (from what I've read, there is no way to access the file system in GAE from outside, like with an FTP), which is not the optimally way.

So I'm thinking on save the HTML contents to the database but: will this increase the database hits a lot? I'm using NDB, so in theory, every user that reads a book will get the cached result from the NDB cache, once it was readed the first time. Is this right?

Will be better to pass the html to the database? In terms of size, it will be over 8k per html page. The pages also have image files, so, to avoid the initial problem of upload it every new book, again I must save the images also in the database, right?

An example page for a book will be like this

4

4 回答 4

5

Google app engine has a dedicated service for file uploads, it is called Blobstore.

You can write an administration page that let you upload file and publish them. You will need to use the database only to store meta data about each object: Book name, author, related image...

Here's some documentation

于 2013-06-03T11:41:17.017 回答
2

If you want a "poor man's" implementation, create a folder named 'books' in the top level of your application folder. Inside of that, create one folder for each book, and inside each one of those, create one folder for each chapter. This will give you a tree structure for your library.

Then, inside each book's folder, create an index.html file that acts as a cover page and table of contents. It should have links to each chapter. Inside each chapter's folder, create another index.html file that contains the HTML for that chapter. All the images for that chapter go alongside the index.html file inside that folder, and all the links are relative, i.e.: href="picture.jpeg"

Change your app.yaml to serve up the 'books' folder as a Static Directory:

handlers:
- url: /books
  static_dir: books

If you never have to change the contents of the books, you can publish each book just once and deploy it. The beauty of this is that no programming is required, beyond editing HTML and app.yaml.

于 2013-06-04T00:56:23.633 回答
1

Why not upload your content using Google Drive and save your content in NDB. Reads are not expensive and the NDB datastore is very fast.

You can use the blobstore for images. Look at Google High Performance Image Serving, which makes use of the blobstore and get_serving_url from the Image API.

于 2013-06-03T12:05:59.367 回答
1

If you structure your ndb entities right, the overhead will be very minimal.

Basically, just always do key-based reads.

Let's say you have:

def Template (ndb.model):
   data = ndb.TextProperty()

Then you can do reads like:

key = ndb.Key(Template, 'bookname.html')
data = key.get().data

ndb will automatically memcache these reads. So until memcache evicts them, they will be very fast and completely free.

The real thing to consider is size - ndb entities are limited to (IIRC) 1MB. If all your templates will be smaller than that, then you're good. If they're bigger, I'd suggest using the Blob Store. You'll still want to use ndb to store references to the Blob Store, though :)

于 2013-06-05T13:36:07.147 回答