## 4 Load Balancing Based on an Improved Genetic Algorithm  
In a distributed face recognition architecture, there are multiple agents that can handle multiple tasks simultaneously. However, if the tasks for each agent are not balanced, the agent with a large number of tasks will have time delay and sharp increase of CPU utilization, which affects the overall performance of the distributed system. In this paper, an improved genetic algorithm is used for load balancing to ensure the performance. Assume that k agents are assigned with m videos, each of which involves one or more pedestrians. Here, \(\mathrm{A}=\left\{\mathrm{A}_{1},\mathrm{A}_{2},\cdots,\mathrm{A}_{k}\right\}\) and \(\mathrm{IP}=\left\{\mathrm{IP}_{1},\mathrm{IP}_{2},\cdots,\mathrm{IP}_{k}\right\}\) are used to represent agents and IP addresses, respectively, and \(\mathrm{IP}_{i}\) is the IP address of the i-th agent \(\mathrm{A}_{i}\)\((0<\mathrm{i}\leq\mathrm{k})\). The set of videos is \(\mathrm{V}_{\mathrm{i}}=\left\{\mathrm{V}_{\mathrm{i1}},\mathrm{V}_{\mathrm{i2 }},\cdots,\mathrm{V}_{\mathrm{im}_{j}}\right\}\), \(\mathrm{r}_{\mathrm{i}}\)\((0<\mathrm{n}_{\mathrm{i}}\leq\mathrm{m})\) is the number of videos in the i-th agent, and \(\mathrm{V}_{\mathrm{ij}}\) represents the j-th video in the i-th agent \((0<\mathrm{j}\leq\mathrm{n}_{\mathrm{i}})\). \(\mathrm{P}_{\mathrm{ij}}=\left\{\mathrm{P}_{\mathrm{\bar{g}}}(1),\mathrm{P}_{ \mathrm{\bar{g}}}(2),\cdots,\mathrm{P}_{\mathrm{\bar{g}}}(\mathrm{n}_{\mathrm{ \bar{g}}})\right\}\), where \(\mathrm{P}_{\mathrm{\bar{g}}}\) is the number  
Figure 3: Key steps of the video-based face recognition scheme. of pedestrians in the j-th video. The total number of pedestrians in all the videos processed by the i-th agent is \(\rm{P_{i}}=\left\{{P_{i1},P_{i2},\cdots,P_{in_{i}}}\right\}\). \(\rm{P_{i}}=\sum\limits_{k=1}^{n_{i}}{P_{ik}(n_{ik})}\), \(\rm{P_{ik}}\) is the number of pedestrians in the k-th video. The video processing time of K agents is represented by \(\rm{T}=\left\{{T_{1},T_{2},\cdots,T_{K}}\right\}\), and \(\rm{T_{i}}\) is calculated as follows:  
\[\rm{T_{i}}=\sum\
olimits_{j=1}^{n_{i}}{t_{ij}}, \tag{1}\]  
where \(\rm{t_{ij}}\) is the time to process one frame of the j-th video in the i-th agent, and \(\rm{t_{ij}}=\rm{t_{p}}+\rm{P_{ik}}*\rm{t_{r}}\). Here, \(\rm{t_{p}}\) is the processing time of the agent that includes detection, tracking, feature extraction, and transmission time from the agent to the server; \(\rm{t_{r}}\) is the face recognition time, which is obtained by the server. Hence, the average time \(\rm{\overline{T_{i}}}\) to process a frame in a video is calculated as follows:  
\[\rm{\overline{T_{i}}}=\frac{\max\limits_{1\leq i\leq K}{T_{i}}}{\sum\
olimits _{i=1}^{K}{\sum\
olimits_{j=1}^{n_{i}}{n_{fi}}^{}}},\ (i=1,2,\cdots;j=1,2,\cdots,n_{i}), \tag{2}\]  
where \(\rm{n_{i}}\) is the total number of videos processed by the i-th agent, \(\rm{nf_{ij}}\) is the total number of frames of the j-th video processed by the i-th agent. The average time \(\rm{\overline{t_{p}}}\) for processing a pedestrian is calculated by:  
\[\rm{\overline{t_{p}}}=\frac{\max\limits_{1\leq i\leq K}{T_{i}}}{\sum\
olimits _{i=1}^{K}{\sum\
olimits_{j=1}^{n_{i}}{P_{ij}*\rm{nf_{ji}}}}}. \tag{3}\]  
First, we initialize the chromosomes in the genetic algorithm. Each gene node contains three parameters: \(\rm{IP_{i}}\), \(\rm{V_{ij}}\), and \(\rm{P_{ij}}\). The i-th chromosome is represented by \(\rm{H_{i}}\). The chromosome initialization is as follows:  
\[\rm{H_{i}}=\big{\{}(\rm{IP_{i}},\rm{V_{i1}},\rm{P_{i1}}),(\rm{IP_{i}},\rm{V_{ i2}},\rm{P_{i2}}),\cdots,\big{(}\rm{IP_{i}},\rm{V_{ij}},\rm{P_{ij}}\big{)}, \big{(}\rm{IP_{i}},\rm{V_{in_{i}}},\rm{P_{in_{i}}}\big{)}\big{\}}. \tag{4}\]  
The fitness function \(\rm{F_{i}}\) of the chromosome is defined by  
\[\rm{F_{i}}=c/\sum\
olimits_{j=1}^{n_{i}}{P_{ij}(0<c<1)}. \tag{5}\]  
The roulette algorithm is used to select chromosomes to produce the next generation. The probability that an individual is selected is proportional to its fitness function value.