Closed rygh4775 closed 5 years ago
computing cluster
and return, processing node can be different for each requestprocessSearch()
is expensive operation, thus reduce its cost by introduce cache
Worker
) which is ready takes request from request queuesharing keyword-result matching info between every Worker
in the cluster is needed.
processSearch()
but get from cacheprocessSearch()
, save into cache.processSearch()
Design for item in cache:
case class CacheItem(val keyword: String, val result: String, var lastAccess: Timestamp, val createdAt: Timestamp)
Priority Queue
is proper data structure for choosing discard item If so, lastAccess
can be the priority (ascending order. if priority queue is implemented with heap, min-heap
could be best way I thinkmin-heap
with lastAccess updated method — may not the best method using min-heap
).processSearch()
even though it is not necessary to do. (especially, request same keyword)
Cache: Imagine a web server for a simplified search engine. This system has 100 machines to respond to search queries, which may then call out using processSearch(string query) to another cluster of machines to actually get the result. The machine which responds to a given query is chosen at random, so you cannot guarantee that the same machine will always respond to the same request. The method processSearch is very expensive. Design a caching mechanism for the most recent queries. Be sure to explain how you would update the cache when data changes.