假设您有一个社交网站,您可以在其中交友并查看他们的最新活动。问题是,立即了解他们的活动的最有效方法(避免性能问题)是什么,例如在他们在线且您同时在线时更改个人资料?
我有两种不同的方法来解决这个问题,但我不确定从数据库的角度以及Java内存的角度来看哪一种是最有效的方法。以下是我的方法,如果您有更好的方法,请告诉我:
1-使用java HTTP会话监听器获取每个用户的会话并遍历更新。
2-每隔几秒检查数据库是否有新更新,然后更新地图。
Assume you having a social networking website where you can have friends and also view their up to date activities. The question is, what is the most efficient way (avoiding performance problem) to be informed of their activities right away such as changing profile when they're online and you're online as well at the same time?
I have two different ways working out this but I am not precisely sure which one will be the most efficient method from DB point of view as well as Java memory point of view. The followings are my methods, and please let me know if you have any better way:
1- Using java HTTP Session Listener to get session of each single user and traverse through for updates.
2- Checking database for new updates after every few seconds and then updating the map.
发布评论
评论(1)
第一:只有完成测量后您才会知道。
话虽如此,总是存在时空权衡。这意味着如果您在内存中存储大量内容,速度会很快,但内存占用量很大。如果你通过数据库,你将有一个小的(java)足迹,但会慢很多。
所以你需要决定做什么。内存很便宜,因此将内容放入内存缓存中会很好地工作。但另一方面,您真的需要亚秒级更新吗?或者配置文件的更新是否可以在 20 秒后才被检测到?
SE-Radio 播客中有一个关于 NoSQL 数据库的精彩节目,其中讨论了很多要做出的决策:http://www.se-radio.net/2010/05/episode-162-project-voldemort-with-jay-kreps/(我希望是这个)
这一集关于内存网格也相当不错:http://www.se- radio.net/2010/11/episode-169-memory-grid-architecture-with-nati-shalom/
First: you will only know after you have done measurements.
Having said this, there is always a space-time-tradeoff. Meaning that if you store a lot of stuff in memory, it will be fast, but you have a large memory footprint. If you go via DB, you will have a small (java) footprint, but will be a lot slower.
So you need to decide what to do. Memory is cheap, so putting stuff in a memory cache will work nicely. But on the other hand, do you really need sub-second updates? Or can an update of a profile be 20sec old, before it is detected?
There is a great episode of the SE-Radio podcast on NoSQL databases that talks a lot about those decisions to make: http://www.se-radio.net/2010/05/episode-162-project-voldemort-with-jay-kreps/ (I hope it is this one)
This episode about memory-grids is also quite good: http://www.se-radio.net/2010/11/episode-169-memory-grid-architecture-with-nati-shalom/