java - 如何处理高并发的RESTful接口
PHP中文网
PHP中文网 2017-04-17 17:47:32
0
1
537

现在有一个系统,他有两个接口并发量特别高,或者说比其他接口高出几个档次。
那么如何针对这两个接口进行处理?
目前我有几点疑惑。
1、不少高并发网站在指出将模块服务化,这样可以对各个模块进行负载均衡,按需分配,那么他其实是代码层级上就是分开编写的还是只是部署在不同的机器上用nginx转发实现模块化?
2、如果代码不是分开编写的,像这种个别接口访问量高的应该怎么处理。
3、就算是分开编写,每个服务已经自成一个系统,那么如何处理该系统中极个别接口访问量特别高的情况?

现在想到的方法是:
使用nginx负载均衡,针对这两个接口给予专门的服务器集群做处理(代码还是那一套)。
我不知道这样做是不是正确的?因为我为了这两个接口部署了整个系统,我感觉是有问题的。

请各位大牛指点迷津,或提供一些参考资料。

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
PHPzhong

You first check to see if there are duplicate requests. If there are a large number of duplicate requests, and the response returned by your interface is idempotent, then you can use caching to block most of the duplicate requests.
Later, consider deploying the two interfaces separately to see if a single machine can support it. If a single machine cannot support it, you can only turn the interface into a cluster. In the previous step, nginx was used for load balancing, and you can use ip hash or round robin.
You can also add a queue in front to limit requests. This depends on your business needs. For example, some businesses can only accept 100 requests at the same time, so it makes no sense to process 1,000 requests at the same time.
The final plan still depends on your business needs.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template