When does the arithmetic mean of ratios equal the ratio of the means? My recent investigations into Pythagorean triplets in these questions,  Question 1 and Question 2 reveled an interesting property that if $p_k$ is the perimeter of the $k$-th primitive Pythagorean triplet in ascending order of the hypotenuse $h_k$ then
$$
\lim_{n \to \infty}\frac{1}{n}\sum_{k = 1}^n \frac{p_k}{h_k}
= \lim_{n \to \infty}\frac{p_1 + p_2 + \cdots + p_n}{h_1 + h_2 + \cdots + h_n} = 1 + \frac{4}{\pi}
$$
More generally if $l_k$ is the longer of the two orthogonal sides and $s_k$ is the shorter then,
$$
\lim_{n \to \infty}\frac{1}{n}\sum_{k = 1}^n \frac{l_k}{h_k}
= \lim_{n \to \infty}\frac{l_1 + l_2 + \cdots + l_n}{h_1 + h_2 + \cdots + h_n} = \frac{2\sqrt{2}}{\pi}
$$
$$
\lim_{n \to \infty}\frac{1}{n}\sum_{k = 1}^n \frac{s_k}{h_k}
= \lim_{n \to \infty}\frac{s_1 + s_2 + \cdots + s_n}{h_1 + h_2 + \cdots + h_n} = \frac{4-2\sqrt{2}}{\pi}
$$
Here the LHS is the arithmetic mean of the ratios while the RHS is the ratio of arithmetic means and both approach the same limit. I am interested in understanding the conditions under which this property of invariance of means holds. 

Question: If $a_k$ and $b_k$ are two sequence of positive real numbers, under what conditions does the arithmetic mean of their
  ratios approach the ratio of the arithmetic means?

Also is there any technical names for such sequences in literature?
Trivial solutions are $a_k = c_1 k, b_k = c_2 k$ for some constant $c_1,c_2$. I am interested in the conditions that lead to a non-trivial solution such as the example of primitive Pythagorean triplets.
 A: Condition 1
A trivial case in which
$$
\frac1n\sum_{k = 1}^n \frac{a_k}{b_k}
= \frac{a_1 + a_2 + \cdots + a_n}{b_1 + b_2 + \cdots + b_n} 
$$
(at every value of $n,$ not just in the limit)
is when $b_1 = b_2 = \cdots = b_n.$
Condition 2
A slightly less trivial case is when $b_n$ is positive and nondecreasing and 
$\lim_{n \to \infty}\frac{a_n}{b_n}$ exists and is finite. Then
$$
\lim_{n \to \infty}\frac1n\sum_{k = 1}^n \frac{a_k}{b_k}
= \lim_{n \to \infty} \frac{a_n}{b_n}
= \lim_{n \to \infty}\frac{a_1 + a_2 + \cdots + a_n}{b_1 + b_2 + \cdots + b_n} .
$$

It is obviously possible for a pair of sequences to satisfy Condition 2 and not Condition 1. But it is also possible to satisfy Condition 1 and not Condition 2,
for example when $a_k=1$ for odd $k$ and $a_k=2$ for even $k.$
I'm sure there are other conditions for equality of the limits which are not implied by either of the conditions above.
But I think Condition 2 is useful for your particular problem.

In each of your sums, group together all terms corresponding to the same hypotenuse.
For notational convenience, let $h_k$ be the $k$th distinct length of a hypotenuse,
let $q_k$ be the number of triangles with hypotenuse $h_k,$
let $p_{k,1}, p_{k,2}, \ldots, p_{k,q_k}$ be the perimeters of those triangles in any sequence you please,
and let $\mu_k = \frac1{q_k} \sum_{m=1}^{q_k} p_{k,m}$
(that is, the mean perimeter of all triangles with hypotenuse $h_k$).
Then provided that both your limits exist, your limits are
$$
\lim_{m \to \infty}\frac1{\sum_{k=1}^m q_k}
    \sum_{k=1}^m \sum_{j=1}^{q_k} \frac{p_{k,j}}{h_k}
= \lim_{m \to \infty}\frac1{\sum_{k=1}^m q_k}
    \sum_{k=1}^m \sum_{j=1}^{q_k} \frac{\mu_k}{h_k}
$$
and 
$$
\lim_{m \to \infty}\frac{\sum_{k=1}^m \sum_{j=1}^{q_k} p_{k,j}}
{\sum_{k=1}^m \sum_{j=1}^{q_k} h_k}
= \lim_{m \to \infty}\frac{\sum_{k=1}^m \sum_{j=1}^{q_k} \mu_k}
{\sum_{k=1}^m \sum_{j=1}^{q_k} h_k}.
$$
So if $\lim_{m \to \infty} \frac{\mu_m}{h_m}$ exists and is finite
(which seems to be true), then
$$
\lim_{m \to \infty}\frac1{\sum_{k=1}^m q_k}
    \sum_{k=1}^m \sum_{j=1}^{q_k} \frac{\mu_k}{h_k}
 = \lim_{m \to \infty} \frac{\mu_m}{h_m}
= \lim_{m \to \infty}\frac{\sum_{k=1}^m \sum_{j=1}^{q_k} \mu_k}
{\sum_{k=1}^m \sum_{j=1}^{q_k} h_k}.
$$
This is not sufficient to prove that your two limits are equal, because the mere fact that $\lim_{m \to \infty} \frac{\mu_m}{h_m}$ is not sufficient to prove that your second limit exists.
That's because when we add a value of $p_{k,j}$ that is much smaller than average, the ratio of the averages could decrease,
whereas if $p_{k,j}$ that is much larger than average, the ratio of the averages could increase.
So we might expect the ratio of averages to oscillate, with alternating periods of increasing and decreasing.
If the decreases are large enough and many enough in each period of decreasing,
the ratio could decrease by some minimum amount $\epsilon$ in each such period,
in which case it would not converge.
I think in your problem, $q_k$ grows so slowly that the total magnitude of the oscillations of the ratio of averages will converge to zero.
I just have not proved this.
