[MUSIC PLAYING]
FEMI TAIWO: A caching system basically
makes use of technology that stores
part of your code, or your content, in memory.
An example of where this could be used
is for a newspaper website or a news magazine website.
The home page may not change for every couple of minutes,
yet it can have a hundred, 500, a thousand,
thousands of users coming to that home page
within that time.
It makes no sense, or it's suboptimal,
to have to-- for every time a user comes to the home page--
to have to go to your database to pull what's the latest
news, where's the picture, where's
the content, who is the author.
What you can do instead is store that in your cache.
And once there's an update of that content
you just need to update the cache.
Every user who comes to the site at that point in time gets
served content from that cache.
And there are several tools that you
can use to enable caching on your servers.
The first I'd recommend for those of us
who use Apache is memcached.
Memcached is fantastic because it runs extremely fast.
You see on line four I'm [INAUDIBLE] an instance
of the memcached class.
And if you're using Google App Engine like I usually do,
you don't need to have line eight, which
is a part that connects to the memcached server.
That already happens instantly, automatically,
on Google App Engine.
Or if you're not using Google App Engine,
you need to run that line there.
Let's assume this is a fictitious days of week site--
days of the week website.
And what I'm doing here on line ten
is checking if it's already memcached the days of the week.
And if I don't get the results as seen on line 11,
I then run my series of logic, pooled information,
process the data from the database,
to get the days of the week.
And after I do that I start in memcached.
And then I can now display the results
of that code in my browser.
Now how do I set up memcached?
It's simple.
If you're using Google App Engine,
there's no need to install it.
It's already there.
If you're using a VPS, a private server, a cloud, wherever,
right, then you should go to memcached.org
to follow the instructions on how to download and install
memcached.
The third, what I find is the most important thing,
is testing, testing with virtual users.
Testing to simulate what would happen if a thousand users were
accessing your website or app at the same time,
10,000 users accessing your app at the same time.
What would be the experience like if you
had 100,000 users accessing the application at the same time?
What would happen?
And where are the bottlenecks in your application?
When you have just 10 users, or a hundred users,
it may not be so obvious where the constraints or where
the limits or the bottlenecks are.
Since it's going to be a little difficult to sort of have
a thousand people in one room testing your app,
what you can do is to simulate a thousand
users on your app at the same time
by using tools specifically created for testing web apps.
An example of that I recommend is JMeter.
JMeter is an open source application
that enables you to test out your applications.
You can set it up to test with a thousand
users, a hundred thousand people if that's what you want.
There's really no limits to what JMeter have
to do to test your web app.
And you can then profile it to see
exactly how the app performs on those different amounts
of traffic.
I have mentioned three key things
that you can do to help ensure that your app skills.
The first was key mechanism, the second was caching mechanisms
and the third is testing your system.
So check out the links in your description
to access even more content on how
you can help your app to scale and sample code
that we wrote during this session.
[MUSIC PLAYING]