我们正在使用基于Rancher的Docker环境。
服务器设备齐全,我没有任何性能问题。
但是启动性能和控制台性能严重降低。
rails c
(在我的本地VM上:7秒)Object.where(view: 0).each { |obj| obj.update_columns(view: 1) }
我认为这应该更快。当我是数据库中的唯一用户时,我进行了测试。
我还比较了本地VM(2核3GB RAM)
Benchmark.bm do |x|
x.report { 1000.times do Object.first.update_columns(view: 0) end }
end
本地
user system total real
2.472000 0.216000 2.688000 ( 4.719130)
服务器
user system total real
1.961856 0.164141 2.125997 ( 14.161671)
那么,有没有人知道什么能使一切放慢呢?
根据PgHero的说法,数据库还可以,没有没有用的索引。
请询问您是否需要更多信息。
硬件
CPU和内存的比率为30%-一切安静。
提到的“单一”过程使用了一个核心的5.7%
CPU:Intel®Core™i7-6700四核
内存:64 GB DDR4 RAM
硬盘:1TB SSD
环境
作业系统:Ubuntu 18.04.1
ruby :2.6.6
导轨:5.2.4.2
PostgreSQL:10.12
PostgreSQL不存储在pod中,而是直接存储在机器上,可以通过ip 172.17.0.1访问
Rancher :v2.2.3
用户界面:v2.2.41
Helm :v2.10.0-rancher10
机器:v0.15.0-rancher6-1
项目
一个中型项目,约有74个 gem ,167个模型和1128条路线。
time bundle exec rake environment
real 0m2,164s
user 0m1,717s
sys 0m0,423s
Benchmark.ms { Rails.application.eager_load! }
=> 16.18773490190506
主Dockerfile使用标准的ruby-slim-image。
Dockerfiles
mytag / my_ruby_2_6_6:
FROM ruby:2.6.6-slim
LABEL maintainer="[email protected]"
WORKDIR /app
EXPOSE 3000
# Set the locale
RUN apt-get update && \
apt-get install -y locales
RUN sed -i -e 's/# de_DE.UTF-8 UTF-8/de_DE.UTF-8 UTF-8/' /etc/locale.gen && \
locale-gen de_DE.UTF-8
ENV LANG=de_DE.UTF-8 \
LANGUAGE=de_DE:de \
LC_ALL=de_DE.UTF-8
RUN echo "set input-meta on" >> /etc/inputrc && \
echo "set output-meta on" >> /etc/inputrc && \
echo "set convert-meta off" >> /etc/inputrc && \
echo "export LANG=de_DE.utf8" >> /etc/profile && \
cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime
# install bundler
RUN gem install bundler
# install some tools
RUN apt-get install -y cron build-essential git nodejs imagemagick libpq-dev
# Rails ENV
ARG RAILS_ENV=production
# BUNDLER options
ARG BUNDLER_OPTS=" --without development test"
# clean up
RUN apt-get autoremove -y
# dummy start command
CMD ["/bin/bash"]
FROM mytag/my_ruby_2_6_6
LABEL maintainer="[email protected]"
ARG RAILS_ENV=production
COPY Gemfile* ./
# install rubygem
COPY Gemfile Gemfile.lock /app/
RUN bundle config git.allow_insecure true && \
bundle install --jobs 20 $BUNDLER_OPTS
COPY . /app
RUN rails assets:precompile
WORKDIR /app
# Expose Puma port
EXPOSE 3000
# Start up
CMD ["docker/startup.sh"]
脚本docker / startup.sh是迁移和启动服务器的简单任务。
#! /bin/sh
bundle exec rake db:migrate
echo "Migration Done!"
bundle exec rails s -b 0.0.0.0
Rancher YAML (提取//匿名)
apiVersion: apps/v1beta2
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "58"
creationTimestamp: "2019-06-03T19:03:28Z"
generation: 75
labels:
workload.user.cattle.io/workloadselector: deployment-railsapp-railsapp
name: railsapp
namespace: railsapp
resourceVersion: "2133509"
selfLink: /apis/apps/v1beta2/namespaces/railsapp/deployments/railsapp
spec:
progressDeadlineSeconds: 600
replicas: 5
revisionHistoryLimit: 10
selector:
matchLabels:
workload.user.cattle.io/workloadselector: deployment-railsapp-railsapp
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
annotations:
cattle.io/timestamp: "2019-06-18T12:40:43Z"
creationTimestamp: null
labels:
workload.user.cattle.io/workloadselector: deployment-railsapp-railsapp
spec:
affinity: {}
containers:
- env:
- name: DB_HOST
value: 172.17.0.1
image: myapp/railsapp:master-4996
imagePullPolicy: Always
livenessProbe:
failureThreshold: 10
initialDelaySeconds: 70
periodSeconds: 5
successThreshold: 1
tcpSocket:
port: 3000
timeoutSeconds: 2
name: railsapp
readinessProbe:
failureThreshold: 10
initialDelaySeconds: 70
periodSeconds: 5
successThreshold: 2
tcpSocket:
port: 3000
timeoutSeconds: 2
resources: {}
securityContext:
allowPrivilegeEscalation: false
capabilities: {}
privileged: false
procMount: Default
readOnlyRootFilesystem: false
runAsNonRoot: false
stdin: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
tty: true
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status:
availableReplicas: 5
conditions:
- lastTransitionTime: "2019-06-18T12:33:27Z"
lastUpdateTime: "2019-06-18T12:33:27Z"
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
- lastTransitionTime: "2019-06-11T08:22:59Z"
lastUpdateTime: "2019-06-21T13:11:49Z"
message: ReplicaSet "railsapp-958579c56" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
observedGeneration: 75
readyReplicas: 5
replicas: 5
updatedReplicas: 5
我发现,删除所有路由后,服务器的启动速度非常快。但是我对此并不感到惊讶。
最佳答案
在您的YAML中看到“资源:{}”吗?您忘记指定它,这很可能是原因。我从未使用过Rancher,但在Kubernetes中,如果您不指定资源-它会为您指定资源,并且很可能会使用一些低值(value)的资源。
因此,您应该为应用程序指定资源。下面是一个简单的示例:
resources:
requests:
memory: "8Gi"
cpu: "2"
limits:
memory: "8Gi"
cpu: "2"
在此处阅读有关容器的计算资源的更多信息:https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/
关于ruby-on-rails - 在基于Postgresql的基于Rancher的Docker环境中,Rails速度很慢,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55754335/