为什么mysql会变慢?

时间:2018-02-27 05:29:40

标签: mysql

<?php

 namespace AppBundle\Entity;

 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Validator\Constraints as Assert;
 use Symfony\Component\HttpFoundation\File\File;
 use Vich\UploaderBundle\Mapping\Annotation as Vich;

 /**
 * Events
 *
 * @ORM\Table(name="event")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\EventRepository")
 * @Vich\Uploadable
 */
 class Event
{
/**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var string
 * @Assert\NotBlank(message = "not null")
 * @ORM\Column(name="nom", type="string", length=255)
 */
private $nom;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="date", type="date")
 */
private $date;

/**
 * @var \Time
 *
 * @ORM\Column(name="heure", type="time")
 */
private $heure;

/**
 * @var string
 * @Assert\NotBlank(message = "not null")
 * @ORM\Column(name="lieu", type="string", length=255)
 */
private $lieu;

/**
 * @var string
 * @Assert\NotBlank(message = "not null")
 * @ORM\Column(name="categorie", type="string", length=255)
 */
private $categorie;

/**
 * @var float
 * @ORM\Column(name="prix", type="float")
 */
private $prix;

/**
 * @var bool
 * @ORM\Column(name="isActive", type="boolean", options={"default":"0"})
 */
protected $isActive;

/**
* One Event has Many Command.
* @ORM\OneToMany(targetEntity="Commande", mappedBy="event")
*/
private $commandes;

/**
 * @ORM\Column(type="string", length=255)
 * @var string
 */
private $image;

/**
 * @Vich\UploadableField(mapping="photo_images", fileNameProperty="image")
 * @var File
 */
private $imageFile;

/**
 * @ORM\Column(type="datetime")
 * @var \DateTime
 */
private $updatedAt;

public function __toString()
{
    return $this->nom;
}

public function setImageFile(File $image = null)
{
    $this->imageFile = $image;

    // VERY IMPORTANT:
    // It is required that at least one field changes if you are using Doctrine,
    // otherwise the event listeners won't be called and the file is lost
    if ($image) {
        // if 'updatedAt' is not defined in your entity, use another property
        $this->updatedAt = new \DateTime('now');
    }
}

public function getImageFile()
{
    return $this->imageFile;
}

public function setImage($image)
{
    $this->image = $image;
}

public function getImage()
{
    return $this->image;
}

/**
 * Get id
 *
 * @return int
 */
public function getId()
{
    return $this->id;
}



/**
 * Set nom
 *
 * @param string $nom
 *
 * @return Event
 */
public function setNom($nom)
{
    $this->nom = $nom;

    return $this;
}

/**
 * Get nom
 *
 * @return string
 */
public function getNom()
{
    return $this->nom;
}

/**
 * Set date
 *
 * @param \DateTime $date
 *
 * @return Event
 */
public function setDate($date)
{
    $this->date = $date;

    return $this;
}

/**
 * Get date
 *
 * @return \DateTime
 */
public function getDate()
{
    return $this->date;
}

/**
 * Set heure
 *
 * @param \DateTime $heure
 *
 * @return Event
 */
public function setHeure($heure)
{
    $this->heure = $heure;

    return $this;
}

/**
 * Get heure
 *
 * @return \DateTime
 */
public function getHeure()
{
    return $this->heure;
}

/**
 * Set lieu
 *
 * @param string $lieu
 *
 * @return Event
 */
public function setLieu($lieu)
{
    $this->lieu = $lieu;

    return $this;
}

/**
 * Get lieu
 *
 * @return string
 */
public function getLieu()
{
    return $this->lieu;
}

/**
 * Set categorie
 *
 * @param string $categorie
 *
 * @return Event
 */
public function setCategorie($categorie)
{
    $this->categorie = $categorie;

    return $this;
}

/**
 * Get categorie
 *
 * @return string
 */
public function getCategorie()
{
    return $this->categorie;
}

/**
 * Set prix
 *
 * @param float $prix
 *
 * @return Event
 */
public function setPrix($prix)
{
    $this->prix = $prix;

    return $this;
}

/**
 * Get prix
 *
 * @return float
 */
public function getPrix()
{
    return $this->prix;
}

/**
 * Set isActive
 *
 * @param boolean $isActive
 *
 * @return Event
 */
public function setIsActive($isActive)
{
    $this->isActive = $isActive;

    return $this;
}

/**
 * Get isActive
 *
 * @return boolean
 */
public function getIsActive()
{
    return $this->isActive;
}
/**
 * Constructor
 */
public function __construct()
{
    $this->commandes = new \Doctrine\Common\Collections\ArrayCollection();
}

/**
 * Add commande
 *
 * @param \AppBundle\Entity\Commande $commande
 *
 * @return Event
 */
public function addCommande(\AppBundle\Entity\Commande $commande)
{
    $this->commandes[] = $commande;

    return $this;
}

/**
 * Remove commande
 *
 * @param \AppBundle\Entity\Commande $commande
 */
public function removeCommande(\AppBundle\Entity\Commande $commande)
{
    $this->commandes->removeElement($commande);
}

/**
 * Get commandes
 *
 * @return \Doctrine\Common\Collections\Collection
 */
public function getCommandes()
{
    return $this->commandes;
}

/**
 * Set updatedAt
 *
 * @param \DateTime $updatedAt
 *
 * @return Event
 */
public function setUpdatedAt($updatedAt)
{
    $this->updatedAt = $updatedAt;

    return $this;
}

/**
 * Get updatedAt
 *
 * @return \DateTime
 */
public function getUpdatedAt()
{
    return $this->updatedAt;
}
}

复制有延迟。

我检查了mysql bin日志。 但我不知道为什么那么慢。

我可以检查什么?

1 个答案:

答案 0 :(得分:0)

你认为你需要调整你的数据库。这是一个复杂的过程。

如果你有一个运行大量SQL的脚本并且使你的数据库运行速度变慢,并且你的cpu和内存使用情况正常,那么你可能会遇到I / O问题。您需要查看脚本中使用的SQL并进行调整。它可能会生成大量的全表扫描或创建太多会降低数据库速度的事务日志。

您可以搜索数据库调优。