Woohoo, I got Elastic Beanstalk to work! The “Express & EB” sticky note has been removed! Actually I got Elastic Beanstalk to work on about Tuesday, and today I’ve been learning more about getting Express to do stuff.
The first thing to do was a URL to find geeks with a particular partial name. For example, http://eb.drfriendless.com/findgeeks/Fri will give you up to 10 geeks whose names start with “Fri”. And http://eb.drfriendless.com/findgeeks/boy will give you up to 10 geeks whose names start with “boy”. Because there are none, it will instead give you up to 10 geeks with “boy” somewhere in their name. This is how autocomplete fields work, but I didn’t write the autocomplete field yet so I can’t show you what the plan is.
Update: here is the working autocomplete field:
The real problem though is the height of the blue peaks in the top graph. The particular offender there is the lambda which takes information about a user’s collection that I got from BGG, and writes it to the database. It’s in two parts:
- Make sure that all the games in the user’s collection are in the Extended Stats database. Sometimes for a new user, there are a lot that aren’t.
- For each game in the user’s collection, update our information about it.
For some reason – either a faint memory or a hallucination – I had the idea that the first one was the slow one, so I moved that into Elastic Beanstalk. Elastic Beanstalk has the advantages over Lambda that:
- A task taking longer doesn’t cost me more, and doesn’t time out.
- It can be cheaper, if I use it for enough tasks.
- There’s no cold start time – if a Lambda hasn’t been used in a while it can take a few seconds to start up, particularly if it has to talk to the database.
- A Lambda costs some fixed (but tiny) amount every time it’s invoked, so it’s worse if it’s invoked a lot, e.g. for autocompletes.
The disadvantages are:
- Unlike Lambda, I pay for Elastic Beanstalk even if it doesn’t do anything.
- I have to do all this hoohah about setting up Elastic Beanstalk and Express.
I planned for the site to be serverless (i.e. no server machines, not even virtual ones), but I don’t think that’s quite cheap enough yet for my use case and my budget.
As to Part 2 mentioned above, I realised I had some quite poor code in that, that I’d copied across from the old system, and probably wasn’t appropriate for a system where resources cost me money. So I rewrote that as well.
Speaking of performance hits, this is a graph of the database usage. When the green line is at the bottom, the database is as good as dead. This is because I’m cheap and paid for a cheap database.
Note that every 3 days, when I do the collection and plays updates, the green line dives into the ocean. If I can improve my database usage, I can stop it doing that. Look forward to updates on that!