Rancher中的Rails开始缓慢

时间:2019-04-18 22:15:27

标签: ruby-on-rails docker rancher

我们最近将环境从标准配置更新为基于Rancher的Docker环境。 由于change rails命令非常慢。例如:

  • 62秒启动瘦服务器(本地9秒)
  • 51秒访问控制台rails c(本地7秒)

我认为这应该更快。
请询问您是否需要更多信息。

硬件
CPU和内存的比率为30%-一切都很安静。
CPU :英特尔®酷睿™i7-6700四核
RAM :64 GB DDR4 RAM

环境
作业系统:Ubuntu 18.04.1 Ruby:2.5.3
Rails:5.2.1.1
PostgreSQL:10.6

PostgreSQL未存储在pod中,而是直接存储在计算机中。

牧场主:v2.1.7
用户界面:v2.1.21
头盔:v2.10.0-rancher5
机器:v0.15.0-rancher1-1

项目
一个中型项目,包含约80个宝石,146个表和986条路线。

time bundle exec rake environment
real    0m1.793s
user    0m1.486s
sys     0m0.252s

Dockerfile使用标准的ruby-slim-image。

Dockerfile

FROM ruby:2.5.3-slim
LABEL maintainer="my@e-mail.com"

WORKDIR /app

EXPOSE 3000

# Set the locale
RUN apt-get update && \
    apt-get install -y locales

ENV locale-gen C.UTF-8 && \
    LANG=C.UTF-8 \
    LANGUAGE=C.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 

Rancher YAML (提取//匿名)

apiVersion: v1
kind: Pod
metadata:
  annotations:
    cattle.io/timestamp: "2019-04-15T11:36:21Z"
    cni.projectcalico.org/podIP: 10.42.0.51/32
  creationTimestamp: "2019-04-17T13:05:16Z"
  generateName: name-5b4f5d5dd6-
  labels:
    pod-template-hash: 5b4f5d5dd6
    workload.user.cattle.io/workloadselector: deployment-name-name
    workloadID_ingress-fa0f39036879f3f3d4144743a8779ae0: "true"
  name: server-5b4f5d5dd6-m9df9
  namespace: server
  ownerReferences:
  - apiVersion: apps/v1
    blockOwnerDeletion: true
    controller: true
    kind: ReplicaSet
    name: name-5b4f5d5dd6
    uid: name-6111-11e9-b860-901b0ebbaa46
  resourceVersion: "2857427"
  selfLink: /api/v1/namespaces/server/pods/name-5b4f5d5dd6-m9df9
  uid: 72092456-6111-11e9-b860-901b0ebbaa46
spec:
  containers:
  - env:
    - name: A_KEY
      value: a_value
    image: myimage-name
    imagePullPolicy: Always
    livenessProbe:
      failureThreshold: 10
      initialDelaySeconds: 30
      periodSeconds: 5
      successThreshold: 1
      tcpSocket:
        port: 3000
      timeoutSeconds: 2
    name: name
    readinessProbe:
      failureThreshold: 10
      initialDelaySeconds: 30
      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
    volumeMounts:
    - mountPath: /app/logs
      name: logs
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  nodeName: myserver-name
  priority: 0
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - hostPath:
      path: /srv/shared/logs
      type: DirectoryOrCreate
    name: logs

1 个答案:

答案 0 :(得分:0)

看到YAML中的“资源:{}”了吗?您忘记指定它,这很可能是原因。我从未使用过Rancher,但是在Kubernetes中,如果您不指定资源-它会为您指定资源,并且很可能会使用一些低价值的资源。

因此,您应该为应用程序指定资源。下面是一个简单的示例:

resources:
  requests:
    memory: "8Gi"
    cpu: "2"
  limits:
    memory: "8Gi"
    cpu: "2"

在此处了解有关容器的计算资源的更多信息:https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/