I did some testing on one of my production servers.
The scenario: Insert a new visitor tracking info (ip, city, state, country, lat, lng, user-agent, etc)
(To insert a new entry, you need to make sure the IP
hasn't had a visit in the last 24 hours), so it also has a select
query.
(note: table size is in millions, and the instance is micro
, just to see what the worst case is)
Here are the numbers I got:
|--------------|----------|----------|
| Queue Driver | TTFB | Blocking |
|--------------|----------|----------|
| Sync | 2.130sec | YES |
| Database | 0.430sec | NO |
| AWS SQS | 0.855sec | NO |
|--------------|----------|----------|
- Obviously,
sync
is the worst option, as the user has to sit there for 2.3 seconds, before he even starts receiving any data.
database
has the best results, but as mentioned earlier, might not be the best solution for high visitor numbers. Additionally, you shouldn't forget that there is still an insert
being made into the jobs
table.
AWS SQS
to my surprise was slower than using the database. I'm guessing it's because with database
you already have established connections to the database in your connection pool, but the SQS
has to establish a TLS
connection every time. Hence, the additional 300-400ms.
I honestly don't think that SQS
was hard to setup (just follow the guide). I think the decision is based on what your visitor number is.
Redis
in the database category? – Fann