Hey Guys, i have a performance question that is no...
# ktor
m
Hey Guys, i have a performance question that is not directly related to K-Tor, but since i am building my backend & clients using ktor/multiplatform i will ask it here (i am primally an android dev). I have a bigger data set around 15 000 entries, the whole set is around 20 MB in MySQL and i was experimenting a bit with the performance tuning when i want to get one element. My assumption was that if i cache the collection in
HashMap<Long,MyObject>
and don't access the DB all the time i will get faster response times, but i did not . It takes more time to execute the request if i add this "cache (hash map)" there. Is it fine to use mysql only, since it contains some sort of caching?
r
MySQL will handle 15,000 records just fine. In fact, it can handle millions of records just fine. This is more of a data structures question than a ktor question. Hashmaps have an O(1) lookup speed, lookups in mysql on an indexed field have O(log(N)) lookup speed because MySQL organizes indexes using a Btree, and unindexed fields have an O(N) lookup time typically because the engine has to iterate over the entire data set. In short, I would not recommend adding your own caching for 15,000 records. Furthermore caching via a hashmap is the wrong approach. You want your server to be stateless so that your app can scale to multiple servers. Once you need caching, reach for something like memcache or redis.
👍 2
🍻 1
m
@Robert Menke thank you. Makes sense 🙂
👍 1