linux_kokoro_performance_worker_init.sh 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #!/bin/bash
  2. # Copyright 2017 gRPC authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # Initializes a fresh GCE VM to become a Kokoro Linux performance worker.
  16. # You shouldn't run this script on your own,
  17. # use create_linux_kokoro_performance_worker.sh instead.
  18. set -ex
  19. sudo apt-get update
  20. # Install Java 8 JDK (to build gRPC Java)
  21. sudo apt-get install -y openjdk-8-jdk
  22. sudo apt-get install -y unzip lsof
  23. sudo apt-get install -y \
  24. autoconf \
  25. autotools-dev \
  26. build-essential \
  27. bzip2 \
  28. ccache \
  29. curl \
  30. gcc \
  31. gcc-multilib \
  32. git \
  33. gyp \
  34. lcov \
  35. libc6 \
  36. libc6-dbg \
  37. libc6-dev \
  38. libcurl4-openssl-dev \
  39. libgtest-dev \
  40. libreadline-dev \
  41. libssl-dev \
  42. libtool \
  43. make \
  44. strace \
  45. python-dev \
  46. python-pip \
  47. python-setuptools \
  48. python-yaml \
  49. python3-dev \
  50. python3-pip \
  51. python3-setuptools \
  52. python3-yaml \
  53. telnet \
  54. unzip \
  55. wget \
  56. zip \
  57. zlib1g-dev
  58. # perftools
  59. sudo apt-get install -y google-perftools libgoogle-perftools-dev
  60. # netperf
  61. sudo apt-get install -y netperf
  62. # required to run kokoro_log_reader.py
  63. sudo apt-get install -y python-psutil python3-psutil
  64. # gcloud tools, including gsutil
  65. sudo apt-get install -y google-cloud-sdk
  66. # C++ dependencies
  67. sudo apt-get install -y libgtest-dev libc++-dev clang
  68. # Python dependencies
  69. sudo pip install --upgrade pip==19.3.1
  70. sudo pip install tabulate
  71. sudo pip install google-api-python-client oauth2client
  72. sudo pip install virtualenv
  73. # pypy is used instead of python for postprocessing benchmark outputs
  74. # because some reports are huge and pypy is much faster.
  75. # TODO(jtattermusch): get rid of pypy once possible, it's hard to
  76. # keep track of all the installed variants of python.
  77. sudo apt-get install -y pypy pypy-dev
  78. curl -O https://bootstrap.pypa.io/get-pip.py
  79. sudo pypy get-pip.py
  80. sudo pypy -m pip install tabulate
  81. sudo pypy -m pip install google-api-python-client oauth2client
  82. # TODO(jtattermusch): for some reason, we need psutil installed
  83. # in pypy for kokoro_log_reader.py (strange, because the command is
  84. # "python kokoro_log_reader.py" and pypy is not the system default)
  85. sudo pypy -m pip install psutil
  86. # Node dependencies (nvm has to be installed under user kbuilder)
  87. touch .profile
  88. curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
  89. # silence shellcheck as it cannot follow the following `source` path statically:
  90. # shellcheck disable=SC1090
  91. source ~/.nvm/nvm.sh
  92. nvm install 0.12 && npm config set cache /tmp/npm-cache
  93. nvm install 4 && npm config set cache /tmp/npm-cache
  94. nvm install 5 && npm config set cache /tmp/npm-cache
  95. nvm alias default 4
  96. # C# dependencies
  97. sudo apt-get install -y cmake
  98. # C# mono dependencies (http://www.mono-project.com/docs/getting-started/install/linux/#debian-ubuntu-and-derivatives)
  99. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
  100. echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
  101. sudo apt-get update
  102. sudo apt-get install -y mono-devel
  103. # C# .NET Core dependencies (https://www.microsoft.com/net/download)
  104. wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
  105. sudo dpkg -i packages-microsoft-prod.deb
  106. sudo apt-get install -y apt-transport-https
  107. sudo apt-get update
  108. sudo apt-get install -y dotnet-sdk-2.1
  109. # Install .NET Core 1.0.5 Runtime (required to run netcoreapp1.0)
  110. wget -q https://download.microsoft.com/download/2/4/A/24A06858-E8AC-469B-8AE6-D0CEC9BA982A/dotnet-ubuntu.16.04-x64.1.0.5.tar.gz
  111. mkdir -p dotnet105_download
  112. tar zxf dotnet-ubuntu.16.04-x64.1.0.5.tar.gz -C dotnet105_download
  113. sudo cp -r dotnet105_download/shared/Microsoft.NETCore.App/1.0.5/ /usr/share/dotnet/shared/Microsoft.NETCore.App/
  114. # To prevent "Failed to initialize CoreCLR, HRESULT: 0x80131500" with .NET Core 1.0.5 runtime
  115. wget -q http://security.ubuntu.com/ubuntu/pool/main/i/icu/libicu55_55.1-7ubuntu0.4_amd64.deb
  116. sudo dpkg -i libicu55_55.1-7ubuntu0.4_amd64.deb
  117. # Install .NET Core 1.1.10 runtime (required to run netcoreapp1.1)
  118. wget -q -O dotnet_old.tar.gz https://download.visualstudio.microsoft.com/download/pr/b25b5650-0cb8-4699-a347-48d73650da0b/920966211e9bb1907232bbda1faa895a/dotnet-ubuntu.18.04-x64.1.1.10.tar.gz
  119. mkdir -p dotnet_old
  120. tar zxf dotnet_old.tar.gz -C dotnet_old
  121. sudo cp -r dotnet_old/shared/Microsoft.NETCore.App/1.1.10/ /usr/share/dotnet/shared/Microsoft.NETCore.App/
  122. # Ruby dependencies
  123. gpg --keyserver hkp://pgp.mit.edu --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
  124. curl -sSL https://get.rvm.io | bash -s stable --ruby
  125. # silence shellcheck as it cannot follow the following `source` path statically:
  126. # shellcheck disable=SC1090
  127. source ~/.rvm/scripts/rvm
  128. git clone https://github.com/rbenv/rbenv.git ~/.rbenv
  129. export PATH="$HOME/.rbenv/bin:$PATH"
  130. eval "$(rbenv init -)"
  131. git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
  132. export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
  133. rbenv install 2.4.0
  134. rbenv global 2.4.0
  135. ruby -v
  136. # Install bundler (prerequisite for gRPC Ruby)
  137. gem install bundler
  138. # PHP dependencies
  139. sudo apt-get install -y php7.2 php7.2-dev php-pear unzip zlib1g-dev
  140. sudo wget https://phar.phpunit.de/phpunit-8.5.8.phar && \
  141. sudo mv phpunit-8.5.8.phar /usr/local/bin/phpunit && \
  142. sudo chmod +x /usr/local/bin/phpunit
  143. curl -sS https://getcomposer.org/installer | php
  144. sudo mv composer.phar /usr/local/bin/composer
  145. # Java dependencies - nothing as we already have Java JDK 8
  146. # Go dependencies
  147. # Currently, the golang package available via apt-get doesn't have the latest go.
  148. # Significant performance improvements with grpc-go have been observed after
  149. # upgrading from go 1.5 to a later version, so a later go version is preferred.
  150. # Following go install instructions from https://golang.org/doc/install
  151. GO_VERSION=1.10
  152. OS=linux
  153. ARCH=amd64
  154. curl -O https://storage.googleapis.com/golang/go${GO_VERSION}.${OS}-${ARCH}.tar.gz
  155. sudo tar -C /usr/local -xzf go$GO_VERSION.$OS-$ARCH.tar.gz
  156. # Put go on the PATH, keep the usual installation dir
  157. sudo ln -s /usr/local/go/bin/go /usr/bin/go
  158. rm go$GO_VERSION.$OS-$ARCH.tar.gz
  159. # Install perf, to profile benchmarks. (need to get the right linux-tools-<> for kernel version)
  160. sudo apt-get install -y linux-tools-common linux-tools-generic "linux-tools-$(uname -r)"
  161. # see http://unix.stackexchange.com/questions/14227/do-i-need-root-admin-permissions-to-run-userspace-perf-tool-perf-events-ar
  162. echo 0 | sudo tee /proc/sys/kernel/perf_event_paranoid
  163. # see http://stackoverflow.com/questions/21284906/perf-couldnt-record-kernel-reference-relocation-symbol
  164. echo 0 | sudo tee /proc/sys/kernel/kptr_restrict
  165. # qps workers under perf appear to need a lot of mmap pages under certain scenarios and perf args in
  166. # order to not lose perf events or time out
  167. echo 4096 | sudo tee /proc/sys/kernel/perf_event_mlock_kb
  168. # Fetch scripts to generate flame graphs from perf data collected
  169. # on benchmarks
  170. git clone -v https://github.com/brendangregg/FlameGraph ~/FlameGraph
  171. # Install scipy and numpy for benchmarking scripts
  172. sudo apt-get install -y python3-scipy python3-numpy
  173. # Install docker
  174. curl -sSL https://get.docker.com/ | sh
  175. # Enable kbuilder to use docker without sudo:
  176. sudo usermod -aG docker kbuilder
  177. # Add pubkey of Kokoro driver VM to allow SSH
  178. # silence false-positive shellcheck warning ("< redirect does not affect sudo")
  179. # shellcheck disable=SC2024
  180. sudo tee --append ~kbuilder/.ssh/authorized_keys < kokoro_performance.pub
  181. # Kokoro requires /tmpfs/READY file to exist the directory and file itself should
  182. # be owned by kbuilder.
  183. sudo mkdir /tmpfs
  184. sudo chown kbuilder /tmpfs
  185. touch /tmpfs/READY
  186. # Disable automatic updates to prevent spurious apt-get install failures
  187. # See https://github.com/grpc/grpc/issues/17794
  188. sudo sed -i 's/APT::Periodic::Update-Package-Lists "1"/APT::Periodic::Update-Package-Lists "0"/' /etc/apt/apt.conf.d/10periodic
  189. sudo sed -i 's/APT::Periodic::AutocleanInterval "1"/APT::Periodic::AutocleanInterval "0"/' /etc/apt/apt.conf.d/10periodic
  190. sudo sed -i 's/APT::Periodic::Update-Package-Lists "1"/APT::Periodic::Update-Package-Lists "0"/' /etc/apt/apt.conf.d/20auto-upgrades
  191. sudo sed -i 's/APT::Periodic::Unattended-Upgrade "1"/APT::Periodic::Unattended-Upgrade "0"/' /etc/apt/apt.conf.d/20auto-upgrades
  192. # Restart for VM to pick up kernel update
  193. echo 'Successfully initialized the linux worker, going for reboot in 10 seconds'
  194. sleep 10
  195. sudo reboot