background

A system needs to go through the following stages: testing, pre-release, gray scale, etc. Different stages correspond to different environments: testing environment, pre-release environment… . During development and testing, Host switching is often required to point to different environments. The accuracy of Host and real-time after switching is very critical, but the inaccurate and ineffective configuration files often make this goal difficult to achieve.

Incorrect configuration

The problem of inaccurate configuration is caused by the timely sharing and updating of data and human flesh. There is no management and strong reliance on human flesh leads to uncontrollable problems:

Data sharing

At present, Host data is mostly shared by copying each other, without reasonable management and check mechanism, resulting in the spread of an inaccurate configuration to multiple computers is very common. This mode of data sharing may lead to configuration redundancy, environmental errors, confusion and other problems.

Inform the update

When some product environments change, due to the lack of a perfect notification mechanism, the Host file saved by users in the local system may not be updated in time. If the Host file is not updated in a timely manner, the system cannot be accessed due to configuration errors.



No real-time effect

Due to the DNS cache problem of the browser, modifying the Hosts file directly does not take effect in real time, sometimes causing unknown environment confusion and online faults.

DNS cache

DNS records for a domain name have two local caches: browser caches and operating system (OS) caches. If no match is found, the server accesses the OS cache. Finally, the DNS server recursively searches for domain name records and returns the result.

DNS records have a TTL value (time to Live), in seconds, which indicates the maximum validity period of the record. Through experiments, the OS cache will reference the TTL value, but not exactly equal to the TTL value, and the browser DNS cache time is independent of the TTL value, each browser uses a fixed value.

Browser cache

To reduce the cost of network requests, the browser caches the actual IP address of the web site’s domain name. Each browser has a fixed DNS cache time, where Chrome’s expiration time is 1 minute, and DNS requests are not made again during this time. In this case, the following occurs: When development switches from a test environment to a pre-release environment, the test environment system is still returned.


The solution

The basic flow

As shown in the following flow chart, in order to solve the problems of inaccurate and ineffective Host configuration mentioned above, the scheme designs the Host configuration background and Host client.

After the product Owner configures the Host list related to the product in the Host configuration background, the student pays attention to the application, testing and development of the product and can automatically pull the Host data of the related product through the client.

If you need to change the development environment, you can add local customized configurations after selecting a product. After selecting a configuration file, the client automatically merges and replaces the configuration file. After modifying the Hosts file, the client automatically executes an automatic script to clear the DNS cache of the browser, enabling the Host to take effect in real time.



Remote Data sharing

As shown in the figure below, remote data sharing can be achieved by configuring the background and client to pull remote data, and the accuracy of Host configuration can be ensured through unified maintenance of machine data.



Auto clear cache

After the Host switch is completed by the client, the client will automatically execute the script to clear the browser DNS. The script essentially opens the browser DNS and Sockets links, respectively:

  • DNS link: Chrome ://net-internals/# DNS
  • Sockets Link: Chrome ://net-internals/# Sockets

Clear the browser, and then close the browser.



Attached is the clearing cache script:


conclusion

After the background is updated, the client updates the data to the local user through scheduled tasks in real time. After each user switch, the latest and accurate Host can be used to ensure the accuracy of the configuration. By executing the system’s own scripting language to operate the browser open interface, the DNS cache of the browser can be automatically cleared. Host takes effect in real time, ensuring the real-time switching of Host.

In your daily work life, sometimes you find small problems, and when you peel them off, you get an idea, and you go from there and make a small and beautiful change.

reference

  • DNS: zh.wikipedia.org/zh-hans/%E5…
  • Remove the browser DNS cache: www.zhihu.com/question/19…
  • AppleScript: developer.apple.com/library/arc…



For more articles, please pay attention to wechat public number: The road of front-end visualization




———————————————— This is a dividing line ————————————————


Technology and wisdom, youth and finance,

Ant Financial Risk Control Plus, looking forward to working with you.

Here, you can get in touch with the most cutting-edge risk control technology, develop and design high-concurrency, high-availability and high-performance systems, get in touch with cloud computing, big data, artificial intelligence, block chain and other trendy technologies, and communicate freely with all kinds of technology masters.

You must be the best

All that was missing was a platform to show it

We’re offering you more than a job

Is a sky for you to fly

No more flowery words, just hope we can be honest with each other.

Job wanted: WEB Front-end Engineer (React Technology Stack)

Don’t be stingy with your talents, we want to see your resume soon: [email protected]