turms icon indicating copy to clipboard operation
turms copied to clipboard

some user case easy to cause "Client requests are too frequent"

Open weishirongzhen opened this issue 1 year ago • 3 comments

in some cases like: new user A joined 20 groups, each group has 50+ users. user A need pull every group's member profile use to show chat name and avatar, so it will cause at least 20 times userService.queryUserProfile(ids), that mostly will cause "Client requests are too frequent", so how to config this "frequent" for more requst-able,

I can merge all member's ids and only requst one time of userService.queryUserProfile(ids), but after response, will need to seperate result mapping to each gourp, that will make logic complex and more bug.

any advice?

weishirongzhen avatar Jul 14 '23 14:07 weishirongzhen

  • It's common that when you want to make development easier, it needs more system resources to support it. You should better query the info of group members when the user views the info group members on UI so that you don't need to query and cache the members' info that the user may never view.

    And if you really need to query all members' info, it's recommended to merge all member's ids and only request one time of userService.queryUserProfile(ids) for consuming fewer resources.

  • And it's also common that when you want to make development easier, it comes with less security. So if you want to make development easier at the cost of less security, you can configure these in turms-gateway:

turms.gateway.client-api.rate-limiting.capacity=200
turms.gateway.client-api.rate-limiting.initial-tokens=100
turms.gateway.client-api.rate-limiting.tokens-per-period=20

(TODO: I think the default quota is a little limited, and I will make it larger later)

The meaning of the properties are: image


If you want the system to be more secure, you need to implement a request queue to throttle on the client side while keeping the default Turms server rate limiting properties. I think this is a common practice, so I will implement the request queue this month so that other developers do not have to reinvent the wheel.

JamesChenX avatar Jul 14 '23 22:07 JamesChenX

thanks for explain, even I have a local request queue to send request, with the increase of initial data, either ui data will load slower or it will reach the 1101 , it's really to find a balance point, wait for you wheel~

weishirongzhen avatar Jul 21 '23 10:07 weishirongzhen

if change limit value on admin page, sava change, db still shows default value.

image

if I delete "abstract" then rebuild image, change limit value on admin page, then value will also save to db. is that a bug? or that's how it was designed

telegram-cloud-photo-size-5-6192968985859961853-y

weishirongzhen avatar Jul 24 '23 03:07 weishirongzhen