Ten million to build large data volume high concurrency, cluster uses SpringBoot, SpringCloud technology

 Today we talk about how to use SpringCloud to achieve one million and ten million concurrent with the beginning we explain some theoretical knowledge, combined with a back of our example to explain

    How have some development experience of the programmer is to achieve high concurrency of it, we must be blurted out apache, nginx proxy and dynamic load balancing, which is deploying multiple applications in tomcat behind nginx, all user access requests to reach nginx and then from nginx according to a predetermined algorithm tomcat requests to the application, which means that a user's multiple requests may be different tomcat process, users log in after a tomcat behind the access is associated with a user , that other tomcat know how it is, this principle is that the user has logged tomcat cluster uses session sharing mechanism, create a tomcat session and modify data in the session, the session and the corresponding data will be synchronized to all other tomcat , when the request to access the other tomcat, will be able to find the appropriate session information

    As more and more users access the frequency increases, a nginx is unable to support one million concurrent (nginx and a number of hundreds of thousands), this time how to do it, we can re-deploy a nginx + tomcat clusters (we write B service, service before as A), all requests are just now reaching the A services, how to make a request that it reaches the B services, you can use DNS streaming technology, the user request arrives nginx in access to resources through the domain name, before, DNS access using algorithm determines the corresponding nginx service, this step is true, that last as long as all session tomcat a, B, two sets of services are shared, will be able to achieve the expansion of services

    Introduction to thinking, let's use SpringCloud combination eureka (registry), a gateway, business services do a simple implementation

 

Examples of code corresponding to the item can be downloaded right [Examples] button Get 

Development Tools: IntelliJ IDEA2017 JDK1.8 Redis3.2 Maven3.0.2

[Project] contains the content (see below): 

image.png

1. Prepare two machines (A, B), respectively, in these two steps the following machine deployment services deployed on the following explanation machine A, B machines empathy

         A machine ip: 192.168.1.4 B machine ip: 192.168.1.2

2. Start On A registry service eureka, listening on port 8761 start command: java -jar eureka.jar --server.port = 8761

3. Start the Gateway service api-gateway, listen port 9000 start command: java -jar api-gateway.jar --server.port = 9000

4. Start two business services sessionshare, listening ports are 8080, 8090

     启动命令: java -jar sessionshare.jar --server.port=8080    java -jar sessionshare.jar --server.port=8090

   Note: When you start sessionshare, you need to install redis ahead and start a service (set redis access password: config set requirepass 123456)

 

Enter 192.168.1.4:8761 address bar, see the following that is a description of all services start successfully

image.png

 

5. gateway access through service interfaces:    http://192.168.1.4:9000/service-session-redis/getUser

           9000 is the gateway listening port, service-session-redis for the business name on the registry, getUser for the service-session-redis interfaces

  image.png

 

6. Similarly we visited on machine B

image.png

 

Compare 5,6 two steps strRandom is not the same, that they do not share the session

Well, this is why, in the address bar to access the service is not the same ip, if domain names, dns shunt words, A, session in the value of B is the same

That there is no way to validate our ideas, let A cookie value can be copied to the machine B machine, then visit the corresponding interface, this time session on the same data in the AB

Guess you like

Origin www.cnblogs.com/java188/p/12124358.html