开发者

write too frequent ,datastore contention timeout

开发者 https://www.devze.com 2022-12-19 09:05 出处:网络
I read app engine wiki, on datastore contention if too frequent 开发者_StackOverflow中文版write

I read app engine wiki, on datastore contention if too frequent 开发者_StackOverflow中文版write more than 5 times in 1 seconds. The wiki introduced use "shard" approach" as workaround. May i know if we use spring @transactional on this, this can prevent datastore contention timeout right since writing in done concurrently ?


No, you can't do that. Whether or not you use @transactional, it will not make the problem go away - the fact that you have one object that you need to keep on writing to. The contention limit will continue to remain whatever approach you use.

The answer to this problem is actually deciding what it is you want to do, and how important accuracy is to you. Take the case of a simple counter, which is a common example of this problem. If you think accuracy is very important, then you will have to have a list of counters that you choose either sequentially, or at random, and write into. If you have ten counters in this list, then that gives you then times more writes per second, even transactional writes. You need to write code to choose which counters you want to write to, though.

On the other had, if you don't require too much precision, you could try writing to memcache very often. The write contention limits are much higher when writing to memcache or incrementing a counter there. You can then write out and reset the counter at a set interval.


When I was on a project that needed to store a lot of individual records to DB I found the system could not handle all the concurrent transactions. I instead build the object in memory and then all at once saved it to the DB.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号