Skip to content

Fos elastica populate speed up #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Dockerfile.elasticsearch
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM elasticsearch:2



RUN /usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ services:
depends_on:
- mysql
- rabbitmq
- elasticsearch
volumes:
- ./docker/shared/:/shared
- ./:/mqs
Expand Down Expand Up @@ -44,6 +45,11 @@ services:
- RABBITMQ_DEFAULT_PASS=guest
- RABBITMQ_DEFAULT_VHOST=mqs

elasticsearch:

build: { context: ., dockerfile: Dockerfile.elasticsearch }

ports:

- "9201:9200"

volumes:
mysql-data:
driver: local
4 changes: 3 additions & 1 deletion symfony/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public function registerBundles()
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new Enqueue\Bundle\EnqueueBundle()
new Enqueue\Bundle\EnqueueBundle(),
new Enqueue\ElasticaBundle\EnqueueElasticaBundle(),
new FOS\ElasticaBundle\FOSElasticaBundle(),
];

if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
Expand Down
16 changes: 16 additions & 0 deletions symfony/app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ enqueue:
router_queue: 'router'
default_processor_queue: 'default'

fos_elastica:
clients:
default: { host: %elasticsearch_host%, port: %elasticsearch_port% }
indexes:
app:
index_name: app_%kernel.environment%
types:
blog:
mappings:
text: ~
persistence:
driver: orm
model: AppBundle\Entity\Blog
provider: ~
listener: ~
finder: ~
services:
app.async.say_hello_processor:
class: 'AppBundle\Async\SayHelloProcessor'
Expand Down
18 changes: 10 additions & 8 deletions symfony/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "enqueue/message-queue-sandbox",
"license": "MIT",
"type": "project",
"minimum-stability": "dev",
"autoload": {
"psr-4": { "": "src/" },
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
Expand All @@ -19,13 +18,16 @@
"sensio/distribution-bundle": "^5.0",
"sensio/framework-extra-bundle": "^3.0.2",
"incenteev/composer-parameter-handler": "^2.0",
"enqueue/psr-queue": "*",
"enqueue/enqueue": "*",
"enqueue/stomp": "*",
"enqueue/amqp-ext": "*",
"enqueue/enqueue-bundle": "*",
"enqueue/job-queue": "*",
"enqueue/test": "*"
"enqueue/psr-queue": "dev-master",
"enqueue/enqueue": "dev-master",
"enqueue/stomp": "dev-master",
"enqueue/amqp-ext": "dev-master",
"enqueue/enqueue-bundle": "dev-master",
"enqueue/job-queue": "dev-master",
"enqueue/test": "dev-master",
"friendsofsymfony/elastica-bundle": "^3",
"enqueue/elastica-bundle": "dev-master",
"fzaninotto/faker": "^1.6"
},
"require-dev": {
"sensio/generator-bundle": "^3.0",
Expand Down
51 changes: 51 additions & 0 deletions symfony/src/AppBundle/Command/GenerateBlogsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
namespace AppBundle\Command;

use AppBundle\Entity\Blog;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

class GenerateBlogsCommand extends Command implements ContainerAwareInterface
{
use ContainerAwareTrait;

protected function configure()
{
$this
->setName('app:generate-blogs')
->addOption('number', null, InputOption::VALUE_REQUIRED)
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$faker = \Faker\Factory::create();
/** @var EntityManagerInterface $em */
$em = $this->container->get('doctrine.orm.entity_manager');

for ($i = 1; $i <= $input->getOption('number'); $i++) {
$blog = new Blog();
$blog->setText($faker->paragraphs(3, true));

$em->persist($blog);

if (0 == ($i % 100)) {
$em->flush();
$em->clear();

$output->writeln('Saved 100');
}

}

$em->flush();
$em->clear();

$output->writeln('Saved the rest');
}
}
59 changes: 59 additions & 0 deletions symfony/src/AppBundle/Entity/Blog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
* @ORM\Table(name="blogs")
*/
class Blog
{
/**
* @var int
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;

/**
* @var string
*
* @ORM\Column(type="text")
*/
private $text;

/**
* @return string
*/
public function getText()
{
return $this->text;
}

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

/**
* @param int $id
*/
public function setId($id)
{
$this->id = $id;
}

/**
* @param string $text
*/
public function setText($text)
{
$this->text = $text;
}
}