title: python xarray slow in multiple thread
body: <p>Dear xarray python users,</p>
  <p>I have a code where some xarray dataset are loaded, passed between function, created from calculation and writed in the end.
  These operation have to be done for several areas over the globe in an operational way. As each areas are independent (didn't load the same data) I can use a main for creating thread (using the multiprocessing toolbox) or launching manually the different areas in separate terminal.</p>
  <p>When I launch one area, I have reasonable time of processing. There isn't any multiprocessing inside the thread of function so in my htop it only use 1 cpu core over the 8 available, and a cProfile of the code will lead to the following results:</p>
  <pre><code>Thu Jul 30 10:54:01 2020    Tahiti.txt
  
           2190436 function calls (2150695 primitive calls) in 131.330 seconds
  
     Ordered by: cumulative time
     List reduced from 9195 to 10 due to restriction &lt;10&gt;
  
     ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1722/1    0.013    0.000  131.332  131.332 {built-in method builtins.exec}
          1    0.049    0.049  131.332  131.332 main_b_GHI_Tahiti.py:1(&lt;module&gt;)
          1    0.529    0.529   65.203   65.203 /home/ubuntu/SteadySat/Codes/steadysat-python/dev/Irradiance/base_pvlib.py:43(pvlib_turbidity_optim)
          1   29.864   29.864   60.960   60.960 /home/ubuntu/SteadySat/Codes/steadysat-python/dev/cloud_forecast/Cloud_Forecasting.py:71(Cloud_Wind)
         34    1.664    0.049   54.530    1.604 /home/ubuntu/SteadySat/Codes/steadysat-python/dev/Irradiance/base_pvlib.py:97(Projection_ombre)
         34   38.775    1.140   42.352    1.246 /home/ubuntu/SteadySat/Codes/steadysat-python/dev/Irradiance/base_pvlib.py:124(Projection_ombre_optim)
          1    3.268    3.268   23.795   23.795 /home/ubuntu/SteadySat/Codes/steadysat-python/dev/cloud_forecast/Cloud_Forecasting.py:135(Wind_Map)
         34    0.000    0.000   20.541    0.604 /home/ubuntu/anaconda3/envs/steadysat/lib/python3.7/site-packages/scipy/io/matlab/mio.py:83(loadmat)
         13    0.000    0.000   20.496    1.577 /home/ubuntu/anaconda3/envs/steadysat/lib/python3.7/site-packages/scipy/io/matlab/mio5.py:254(get_variables)
         13    0.000    0.000   20.493    1.576 /home/ubuntu/anaconda3/envs/steadysat/lib/python3.7/site-packages/scipy/io/matlab/mio5.py:235(read_var_array)
  </code></pre>
  <p>Now if I launch two or more areas (in different terminal, same code), the computing time is much slower (here it's a time 2, I have to 8 time slower), the htop show that the processes spend long time in D state (waiting), cpu's aren't working so much. I have to precise that the same code, with same consuming operation, but using non elegant numpy implementation work fine (with no real lose of time when several areas are computed).
  In this case the cProfile show completly different results, as it's not my time consuming function that lead the top 10 but xarray</p>
  <pre><code>Thu Jul 30 09:31:14 2020    Tahiti.txt
  
           2190294 function calls (2150553 primitive calls) in 358.310 seconds
  
     Ordered by: cumulative time
     List reduced from 9195 to 10 due to restriction &lt;10&gt;
  
     ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1722/1    0.012    0.000  358.313  358.313 {built-in method builtins.exec}
          1    0.030    0.030  358.313  358.313 main_b_GHI_Tahiti.py:1(&lt;module&gt;)
  6017/4415    0.142    0.000  234.321    0.053 {built-in method numpy.array}
  4142/2546    0.003    0.000  234.198    0.092 /home/ubuntu/anaconda3/envs/steadysat/lib/python3.7/site-packages/numpy/core/_asarray.py:16(asarray)
    111/109    0.001    0.000  234.172    2.148 /home/ubuntu/anaconda3/envs/steadysat/lib/python3.7/site-packages/xarray/core/indexing.py:555(__array__)
        109    0.001    0.000  234.163    2.148 /home/ubuntu/anaconda3/envs/steadysat/lib/python3.7/site-packages/xarray/backends/netCDF4_.py:71(__getitem__)
        109    0.003    0.000  234.162    2.148 /home/ubuntu/anaconda3/envs/steadysat/lib/python3.7/site-packages/xarray/core/indexing.py:809(explicit_indexing_adapter)
        109    0.002    0.000  234.151    2.148 /home/ubuntu/anaconda3/envs/steadysat/lib/python3.7/site-packages/xarray/backends/netCDF4_.py:76(_getitem)
        109  234.122    2.148  234.137    2.148 {built-in method _operator.getitem}
        173    0.001    0.000  234.135    1.353 /home/ubuntu/anaconda3/envs/steadysat/lib/python3.7/site-packages/xarray/core/dataarray.py:555(values)
  </code></pre>
  <p>If anyone have an idea of what can be wrong in the xarray that induce this problème, it would be very helpfull. I only use few function over the datarray : open_dataset, sel, to_netcdf but I can see the increase of time computing from the beggening where only open_dataset and sel are used.</p>
  <p>Thanks in advance.</p>