# Assessing Database Contribution via Distributed Tracing for Microservice Systems
## 3 Methodology
### Formalizing the Task as a Nonlinear Programming Problem  
To transform this problem into a mathematical problem, we define corresponding operators for the four basic operations on the database (creating, retrieving, updating, and deleting), as shown in Table 4.  
In our definition, \(\alpha\), \(\beta\), \(\gamma\), and \(\delta\) are four parameters, representing the weight of creating, retrieving, updating, and deleting operations, respectively. Based on the aggregated matrices of business scenarios, the number of records processed by each operation can be calculated by the equations in Table 5. The weight of the operation corresponding to the smallest number of records is 1; the weight of the operation corresponding to the smaller number of records is 2; the weight of the operation corresponding to the larger number of records is 3; the weight of the operation corresponding to the largest number of records is 4. \(N_{i}\) in the operators represents the numbers of operated records in the \(i\)-th business scenario, which can be calculated by Equation (7). \[N_{i}=\sum_{k=1}^{n}(c_{ik}+r_{ik}+u_{ik}+d_{ik}) \tag{7}\]  
The structure of the defined operators in Table 4 can ensure that the number of operated records \(h\) and the weight of four basic database operations maintain a positive correlation with database contribution \(x_{k}\), to a certain extent, while appropriately reducing the impact of the large gap between \(h\) on the calculating database contribution. Based on the defined operators and the aggregation matrix of each business scenario, we can use the database contribution \((x_{1},x_{2},\cdots,x_{n})\) to represent the importance weight vector \(\mathbf{g}=(g_{1},g_{2},\ldots,g_{m})\) of business scenarios: \begin{table}
\begin{tabular}{c c} \hline \hline
**Operation** & **Operator** \\ \hline Create \(h\) records on the \(k\)-th database in the \(i\)-th business scenario. & \(\dfrac{1}{\sqrt{\frac{h}{N_{i}}\cdot\alpha}}x_{k}\) \\ Retrieve \(h\) records on the \(k\)-th database in the \(i\)-th business scenario. & \(\dfrac{1}{\sqrt{\frac{h}{N_{i}}\cdot\beta}}x_{k}\) \\ Update \(h\) records on the \(k\)-th database in the \(i\)-th business scenario. & \(\dfrac{1}{\sqrt{\frac{h}{N_{i}}\cdot\gamma}}x_{k}\) \\ Delete \(h\) records on the \(k\)-th database in the \(i\)-th business scenario. & \(\dfrac{1}{\sqrt{\frac{h}{N_{i}}\cdot\delta}}x_{k}\) \\ \hline \hline \end{tabular}
\end{table} 
Table 4: The definitions of operators for the four basic database operations \((1\leq k\leq n,\,1\leq i\leq m)\). \begin{table}
\begin{tabular}{c c} \hline \hline
**Operation** & **Equation** \\ \hline Create & \(\sum_{i=1}^{m}\sum_{k=1}^{n}c_{ik}\) \\ Retrieve & \(\sum_{i=1}^{m}\sum_{k=1}^{n}r_{ik}\) \\ Update & \(\sum_{i=1}^{m}\sum_{k=1}^{n}u_{ik}\) \\ Delete & \(\sum_{i=1}^{m}\sum_{k=1}^{n}d_{ik}\) \\ \hline \hline \end{tabular}
\end{table} 
Table 5: The equations of counting records operated by four basic operations. \[g_{i}=\sum_{k=1}^{n}\frac{1}{\sqrt{\frac{c_{ik}^{2}}{N_{i}}}\alpha+\sqrt{\frac{r_{ ik}^{2}}{N_{i}}}\beta+\sqrt{\frac{u_{ik}}{N_{i}}}\gamma+\sqrt{\frac{d_{ik}}{N_{i}}} \delta}x_{k} \tag{8}\]  
Then, combined with the business scenario importance weight **w** by AHP, the database contribution assessment problem can be formalized as the following nonlinear programming problem:  
\[ \begin{split}&\mathcal{M}in\left(1-\frac{\mathbf{g}\cdot\mathbf{w}}{ \|\mathbf{g}\|\cdot\|\mathbf{w}\|}\right)^{2}\\ & s.t.\ \sum_{i=1}^{n}x_{i}=1,\\ & x_{i}\in(0,1),i=1,2,\ldots,n\end{split}  \tag{9}\]  
The optimization objective in Equation (9) is defined based on cosine similarity. According to the meaning of cosine similarity, Equation (9) essentially finds the \(\mathbf{x}\) that minimizes the angle between vector \(\mathbf{g}\) and vector \(\mathbf{w}\) under constraints, which is a constrained nonlinear optimization problem.