Ultra high-speed multi-process operation key is uint32 value of the data uint32 (for monitoring system)

 

Ultra high-speed multi-process operation key is uint32 value of the data uint32 (for monitoring system)
 
https://www.cnblogs.com/dearplain/
 
1. Initialize, generating the shared memory 40 in the array 1000, each array entry 8 bytes, 4 bytes is a Key, a 4-byte value. 40 array with a different prime number less than 1000. hash key.
 
2. Find the node 40 array, index is hkey = key% hash, if present, is updated, if not, after increasing node update.
 
3.compare and swap support the set operation. (If it fails to re-take process)
 
4.atomic add support for atomic decrease.
 
5.compare and swap support add nodes to operate. (If it fails to re-take process)
 
6. If you can not find the array 40, there is no idle node, it fails.
 
7. collected, agent will be a few seconds to collect all the data and all set to zero. According to the following calculation, support key while using 37 000 in the same machine for a few seconds, can meet most needs.

 

a = [0] * 40000
for i in range(1, 1000000):
    done = 0
    j = 0
    for h in [998, 997, 991, 983, 982, 977, 976, 974, 971, 967, 964, 958, 956, 953, 947, 944, 941, 937, 934, 932, 929, 926, 922, 919, 916, 914, 911, 908, 907, 904, 898, 892, 887, 886, 883, 881, 878, 877, 872, 866]:
        j = j+1
        if a[i%h+(j-1)*1000] == 0:
           a[i%h+(j-1)*1000] = 1
           done = 1
           break
    if done == 0:
        print('error in:', i)
        break

 

Guess you like

Origin www.cnblogs.com/dearplain/p/11578588.html