I have a Ruby on Rails Application that stores JSON data in a MySQL database through a POST request. I also have accompanying GET routes to access the data in the database. When I first send one of the requests, either through the POST or GET route, the request takes about 1 second. When I send either the same request, or the other request, it then takes about 0.1 seconds, which is significantly faster.
I first thought that the SQL queries were being cached by rails, and this is why the subsequent same request was so much faster, but in the web server console, the requests were being shown again with times next to them (ex. 0.3 ms) and without a "CACHE". In any case, even if it was caching the SQL queries, the queries for the other route are very different with only minimal similar queries, so query caching shouldn't have sped up the other query so much.
I read somewhere that MySQL might be caching the indexes, which makes sense why it is faster if done immediately, but if I wait an hour, it takes the same slower speed. Is the time MySQL spends accessing the uncached indexes not shown in the SQL query log, because if I add up the various (0.1 ms) next to each query, it doesn't nearly add up to the overall request time (even the one shown at the bottom of the log).
If all of this is correct, and I am experiencing the effects of index caching and a performance penalty for accessing an index that isn't cached, is there a way I can reduce the time for this first request. My request will be sent about every hour or so, and by then the cache will no longer have my indexes. Anything for me to even look into to speed up my requests would be appreciated.
Aucun commentaire:
Enregistrer un commentaire