我们正在使用基于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% - 一切都很安静。 所述“oneliner”的过程使用了一个核心的5.7% CPU:Intel®Core™i7-6700四核 RAM:64 GB DDR4 RAM 硬盘:1TB SSD
环境 操作系统:Ubuntu 18.04.1 Ruby:2.5.5 Rails:5.3 PostgreSQL:10.6
PostgreSQL不存储在pod中,而是直接存储在计算机上。
牧场主:v2.2.3 用户界面:v2.2.41 Helm:v2.10.0-rancher10 机器:v0.15.0-rancher6-1
项目 一个中等规模的项目,拥有约80个宝石,146个桌子和986条路线。
time bundle exec rake environment
real 0m1.793s
user 0m1.486s
sys 0m0.252s
Benchmark.ms { Rails.application.eager_load! }
=> 27.172662317752838
主Dockerfile使用标准的ruby-slim图像。
Dockerfiles
mytag / my_ruby_2_5_5:
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_5_5
LABEL maintainer="[email protected]"
ARG RAILS_ENV=production
COPY Gemfile* /app/
RUN bundle config git.allow_insecure true && \
bundle install --jobs 20 $BUNDLER_OPTS
COPY . /app
RUN rails assets:precompile
CMD [ "rails", "application:start" ]
rake任务应用程序:start是一项简单的任务
desc 'migrate and start up'
task start: ['db:migrate', :up]
desc 'start rails in prod env'
task up: :environment do
sh "rails server -b 0.0.0.0 -p 3000"
end
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中看到“resources:{}”?你忘了指定它,这很可能是原因。我从未使用过Rancher,但是如果你没有指定资源,那么在Kubernetes中 - 它将为你指定它,并且很可能会使用一些低值。
因此,您应该为您的应用程序指定资源。简单的例子如下:
resources:
requests:
memory: "8Gi"
cpu: "2"
limits:
memory: "8Gi"
cpu: "2"
在此处阅读有关容器计算资源的更多信息:https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/