4. Let $x, y, z$ be positive real numbers, $M=\max \left\{x y+\frac{2}{z}, z+\frac{2}{y}, y+z+\frac{1}{x}\right\}$. Then the minimum value of $M$ is
$3 M \geqslant x y+\frac{2}{z}+z+\frac{2}{y}+y+z+\frac{1}{x}=x y+\frac{1}{z}+\frac{1}{z}+z+\frac{1}{y}+\frac{1}{y}+y+z+\frac{1}{x}$ $\geqslant 9 \sqrt[9]{x y \cdot \frac{1}{z} \cdot \frac{1}{z} \cdot z \cdot \frac{1}{y} \cdot \frac{1}{y} \cdot y \cdot z \cdot \frac{1}{x}}=9 \Rightarrow M \geqslant 3$, equality holds when $x=y=z=1$. Therefore, the minimum value of $M$ is 3.