debuggable

 
Contact Us
 
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11

CouchDB Insert Benchmarks

Posted on 25/6/09 by Felix Geisendörfer

Hey folks,

I am currently working on replacing Amazon S3 as the key value storage service for Debuggable's new startup. The main reason for that choice is that we want the ability to license the technology for in-house usage, which means the S3 dependency has to go.

Over the past year or so I have repeatedly heard good things about CouchDB (not to mention that Damien Katz became a personal hero of mine after seeing this video). But the main reason for preferring CouchDB over all the alternative key value stores is CouchDB's simplicity. Using HTTP + JSON as the protocol and embracing complete RESTfulness makes getting started with CouchDB ridiculously easy. It also makes it very awesome as you can build your architecture with other HTTP tools such as reverse proxies, http load balancers, etc..

Anyway, having done absolutely nothing with CouchDB before, I feel I should avoid shooting myself in the foot by making poor performance / scaling assumptions that may or may not be true for our particular use cases. So I did what every new user of an open source project would should do and setup some benchmarks.

However, the whole point of these is not to find out how fast CouchDB really is - I don't care as long as it scales horizontally. No, I am mostly interested in finding out 2 things:

  • a) How much slacking time do I have left before we seriously need to scale out to multiple CouchDB nodes
  • b) When that day comes, what can we expect in terms of replication delay (eventual consistency) in a multi-master setup

So far I have been mostly studying question a). Since our application is mostly storage heavy, but does not necessarily have lots of read hits (see, this is the point where you should realize my tests might not help answer your questions at all - sorry), I was wondering about the disk space consumption relative to the number of documents stored in the database.

After reading a bit about the B+ tree CouchDB uses for storage, I assumed that the required disk space would grow linear with the number of documents stored. However, my initial tests indicated that the disk space / document was growing with each document I was adding. Assuming a bad setup and after discussing this a bit in #couchdb, I decided to create a more serious setup on Amazon Ec2 inserting anywhere from 0 - 1 million records.

I put all the code for setting up the environment and running the tests on GitHub, see my couchdb-benchmarks project.

Anyway you waited long enough. Time for my initial results:

doc count (before compact): 0
doc count (after compact): 0
insert time: 0 sec
insert time / doc: n/a ms
compact time: 1.0064 sec
compact time / doc: n/a ms
disk size (before compact): 79 bytes
disk size (after compact): 79 bytes
.couch size (before compact): 79 bytes
.couch size (after compact): 79 bytes
.couch size / doc (before compact): n/a bytes
.couch size / doc (after compact): n/a bytes

doc count (before compact): 1
doc count (after compact): 1
insert time: 0.0015 sec
insert time / doc: 1.46 ms
compact time: 1.0051 sec
compact time / doc: 1005.14 ms
disk size (before compact): 315 bytes
disk size (after compact): 4179 bytes
.couch size (before compact): 315 bytes
.couch size (after compact): 4179 bytes
.couch size / doc (before compact): 315 bytes
.couch size / doc (after compact): 4179 bytes

doc count (before compact): 2
doc count (after compact): 2
insert time: 0.0015 sec
insert time / doc: 0.75 ms
compact time: 1.0057 sec
compact time / doc: 502.87 ms
disk size (before compact): 503 bytes
disk size (after compact): 8281 bytes
.couch size (before compact): 503 bytes
.couch size (after compact): 8281 bytes
.couch size / doc (before compact): 251.5 bytes
.couch size / doc (after compact): 4140.5 bytes

doc count (before compact): 3
doc count (after compact): 3
insert time: 0.0017 sec
insert time / doc: 0.56 ms
compact time: 1.0053 sec
compact time / doc: 335.1 ms
disk size (before compact): 693 bytes
disk size (after compact): 8281 bytes
.couch size (before compact): 693 bytes
.couch size (after compact): 8281 bytes
.couch size / doc (before compact): 231 bytes
.couch size / doc (after compact): 2760.33 bytes

doc count (before compact): 4
doc count (after compact): 4
insert time: 0.0017 sec
insert time / doc: 0.44 ms
compact time: 1.0053 sec
compact time / doc: 251.33 ms
disk size (before compact): 883 bytes
disk size (after compact): 8281 bytes
.couch size (before compact): 883 bytes
.couch size (after compact): 8281 bytes
.couch size / doc (before compact): 220.75 bytes
.couch size / doc (after compact): 2070.25 bytes

doc count (before compact): 5
doc count (after compact): 5
insert time: 0.0018 sec
insert time / doc: 0.36 ms
compact time: 1.0054 sec
compact time / doc: 201.08 ms
disk size (before compact): 1071 bytes
disk size (after compact): 8281 bytes
.couch size (before compact): 1071 bytes
.couch size (after compact): 8281 bytes
.couch size / doc (before compact): 214.2 bytes
.couch size / doc (after compact): 1656.2 bytes

doc count (before compact): 6
doc count (after compact): 6
insert time: 0.0019 sec
insert time / doc: 0.32 ms
compact time: 1.0051 sec
compact time / doc: 167.52 ms
disk size (before compact): 1261 bytes
disk size (after compact): 8281 bytes
.couch size (before compact): 1261 bytes
.couch size (after compact): 8281 bytes
.couch size / doc (before compact): 210.17 bytes
.couch size / doc (after compact): 1380.17 bytes

doc count (before compact): 7
doc count (after compact): 7
insert time: 0.0021 sec
insert time / doc: 0.3 ms
compact time: 1.005 sec
compact time / doc: 143.57 ms
disk size (before compact): 1459 bytes
disk size (after compact): 8281 bytes
.couch size (before compact): 1459 bytes
.couch size (after compact): 8281 bytes
.couch size / doc (before compact): 208.43 bytes
.couch size / doc (after compact): 1183 bytes

doc count (before compact): 8
doc count (after compact): 8
insert time: 0.0022 sec
insert time / doc: 0.27 ms
compact time: 1.0049 sec
compact time / doc: 125.61 ms
disk size (before compact): 1655 bytes
disk size (after compact): 8281 bytes
.couch size (before compact): 1655 bytes
.couch size (after compact): 8281 bytes
.couch size / doc (before compact): 206.88 bytes
.couch size / doc (after compact): 1035.13 bytes

doc count (before compact): 9
doc count (after compact): 9
insert time: 0.0023 sec
insert time / doc: 0.25 ms
compact time: 1.0053 sec
compact time / doc: 111.7 ms
disk size (before compact): 1849 bytes
disk size (after compact): 8281 bytes
.couch size (before compact): 1849 bytes
.couch size (after compact): 8281 bytes
.couch size / doc (before compact): 205.44 bytes
.couch size / doc (after compact): 920.11 bytes

doc count (before compact): 10
doc count (after compact): 10
insert time: 0.0025 sec
insert time / doc: 0.25 ms
compact time: 1.0042 sec
compact time / doc: 100.42 ms
disk size (before compact): 2043 bytes
disk size (after compact): 8281 bytes
.couch size (before compact): 2043 bytes
.couch size (after compact): 8281 bytes
.couch size / doc (before compact): 204.3 bytes
.couch size / doc (after compact): 828.1 bytes

doc count (before compact): 50
doc count (after compact): 50
insert time: 0.0072 sec
insert time / doc: 0.14 ms
compact time: 1.0038 sec
compact time / doc: 20.08 ms
disk size (before compact): 10319 bytes
disk size (after compact): 16473 bytes
.couch size (before compact): 10319 bytes
.couch size (after compact): 16473 bytes
.couch size / doc (before compact): 206.38 bytes
.couch size / doc (after compact): 329.46 bytes

doc count (before compact): 100
doc count (after compact): 100
insert time: 0.0136 sec
insert time / doc: 0.14 ms
compact time: 1.0054 sec
compact time / doc: 10.05 ms
disk size (before compact): 20430 bytes
disk size (after compact): 24665 bytes
.couch size (before compact): 20430 bytes
.couch size (after compact): 24665 bytes
.couch size / doc (before compact): 204.3 bytes
.couch size / doc (after compact): 246.65 bytes

doc count (before compact): 500
doc count (after compact): 500
insert time: 0.0687 sec
insert time / doc: 0.14 ms
compact time: 1.0062 sec
compact time / doc: 2.01 ms
disk size (before compact): 104616 bytes
disk size (after compact): 110690 bytes
.couch size (before compact): 104616 bytes
.couch size (after compact): 110690 bytes
.couch size / doc (before compact): 209.23 bytes
.couch size / doc (after compact): 221.38 bytes

doc count (before compact): 1000
doc count (after compact): 1000
insert time: 0.1361 sec
insert time / doc: 0.14 ms
compact time: 1.003 sec
compact time / doc: 1 ms
disk size (before compact): 212260 bytes
disk size (after compact): 217186 bytes
.couch size (before compact): 212260 bytes
.couch size (after compact): 217186 bytes
.couch size / doc (before compact): 212.26 bytes
.couch size / doc (after compact): 217.19 bytes

doc count (before compact): 2500
doc count (after compact): 2500
insert time: 0.4686 sec
insert time / doc: 0.19 ms
compact time: 1.006 sec
compact time / doc: 0.4 ms
disk size (before compact): 814957 bytes
disk size (after compact): 819298 bytes
.couch size (before compact): 814957 bytes
.couch size (after compact): 819298 bytes
.couch size / doc (before compact): 325.98 bytes
.couch size / doc (after compact): 327.72 bytes

doc count (before compact): 5000
doc count (after compact): 5000
insert time: 0.9165 sec
insert time / doc: 0.18 ms
compact time: 1.0065 sec
compact time / doc: 0.2 ms
disk size (before compact): 2012394 bytes
disk size (after compact): 2015330 bytes
.couch size (before compact): 2012394 bytes
.couch size (after compact): 2015330 bytes
.couch size / doc (before compact): 402.48 bytes
.couch size / doc (after compact): 403.07 bytes

doc count (before compact): 7500
doc count (after compact): 7500
insert time: 1.5116 sec
insert time / doc: 0.2 ms
compact time: 2.0112 sec
compact time / doc: 0.27 ms
disk size (before compact): 3778774 bytes
disk size (after compact): 3797090 bytes
.couch size (before compact): 3778774 bytes
.couch size (after compact): 3797090 bytes
.couch size / doc (before compact): 503.84 bytes
.couch size / doc (after compact): 506.28 bytes

doc count (before compact): 10000
doc count (after compact): 10000
insert time: 2.3111 sec
insert time / doc: 0.23 ms
compact time: 3.015 sec
compact time / doc: 0.3 ms
disk size (before compact): 5653905 bytes
disk size (after compact): 5652578 bytes
.couch size (before compact): 5653905 bytes
.couch size (after compact): 5652578 bytes
.couch size / doc (before compact): 565.39 bytes
.couch size / doc (after compact): 565.26 bytes

doc count (before compact): 25000
doc count (after compact): 25000
insert time: 6.8684 sec
insert time / doc: 0.27 ms
compact time: 7.0746 sec
compact time / doc: 0.28 ms
disk size (before compact): 20595235 bytes
disk size (after compact): 20635746 bytes
.couch size (before compact): 20595235 bytes
.couch size (after compact): 20635746 bytes
.couch size / doc (before compact): 823.81 bytes
.couch size / doc (after compact): 825.43 bytes

doc count (before compact): 50000
doc count (after compact): 50000
insert time: 15.8227 sec
insert time / doc: 0.32 ms
compact time: 14.1612 sec
compact time / doc: 0.28 ms
disk size (before compact): 51808040 bytes
disk size (after compact): 51724386 bytes
.couch size (before compact): 51808040 bytes
.couch size (after compact): 51724386 bytes
.couch size / doc (before compact): 1036.16 bytes
.couch size / doc (after compact): 1034.49 bytes

doc count (before compact): 100000
doc count (after compact): 100000
insert time: 35.3071 sec
insert time / doc: 0.35 ms
compact time: 33.4723 sec
compact time / doc: 0.33 ms
disk size (before compact): 125497442 bytes
disk size (after compact): 125419618 bytes
.couch size (before compact): 125497442 bytes
.couch size (after compact): 125419618 bytes
.couch size / doc (before compact): 1254.97 bytes
.couch size / doc (after compact): 1254.2 bytes

doc count (before compact): 250000
doc count (after compact): 250000
insert time: 104.0009 sec
insert time / doc: 0.42 ms
compact time: 97.3738 sec
compact time / doc: 0.39 ms
disk size (before compact): 394489375 bytes
disk size (after compact): 394457190 bytes
.couch size (before compact): 394489375 bytes
.couch size (after compact): 394457190 bytes
.couch size / doc (before compact): 1577.96 bytes
.couch size / doc (after compact): 1577.83 bytes

doc count (before compact): 500000
doc count (after compact): 500000
insert time: 230.6021 sec
insert time / doc: 0.46 ms
compact time: 209.0139 sec
compact time / doc: 0.42 ms
disk size (before compact): 900271866 bytes
disk size (after compact): 900280422 bytes
.couch size (before compact): 900271866 bytes
.couch size (after compact): 900280422 bytes
.couch size / doc (before compact): 1800.54 bytes
.couch size / doc (after compact): 1800.56 bytes

doc count (before compact): 750000
doc count (after compact): 750000
insert time: 354.7959 sec
insert time / doc: 0.47 ms
compact time: 380.9895 sec
compact time / doc: 0.51 ms
disk size (before compact): 1446452532 bytes
disk size (after compact): 1445376102 bytes
.couch size (before compact): 1446452532 bytes
.couch size (after compact): 1445376102 bytes
.couch size / doc (before compact): 1928.6 bytes
.couch size / doc (after compact): 1927.17 bytes

doc count (before compact): 1000000
doc count (after compact): 1000000
insert time: 487.3284 sec
insert time / doc: 0.49 ms
compact time: 570.2633 sec
compact time / doc: 0.57 ms
disk size (before compact): 2023280441 bytes
disk size (after compact): 2022334566 bytes
.couch size (before compact): 2023280441 bytes
.couch size (after compact): 2022334566 bytes
.couch size / doc (before compact): 2023.28 bytes
.couch size / doc (after compact): 2022.33 bytes

From this data, a few assumptions can be made:

  • CouchDB inserts ~2-3k documents / second in a >100k documents database (for this particular hardware / benchmark setup)
  • CouchDB inserts get slower on bigger databases
  • CouchDB seems to use more bytes / document the larger the database gets (this is scary, but might explain the previous 2 observations)
  • The time it takes for compacting a database with identical, unmodified documents seems to be almost equal to the time it took to insert the initial documents. Makes lots of sense assuming the writes are I/O bound.

Now since I am new to CouchDB there is a very large chance for problems with my setup and the logic behind my assumptions. However, I hope that by sharing them I can get feedback to make the benchmarks better and provide explanations for the observed characteristics.

I also hope that some of you might feel compelled to fork the project on GitHub and provide more benchmarks. Personally I am going to work on analyzing replication next. If I find time I'll also add some CSV exports and pretty rendering facilities with some google charts.

Comment if you have any thoughts, want to see more tests or share some religious propaganda related to your key-value storage system of choice : ).

-- Felix Geisendörfer aka the_undefined

PS: A few questions I can already see coming up:

Why does compact always take at least 1 second?
Because I use a while() loop with sleep(1) to determine when compact is done. I could check more frequently, but its not really a variable I'm interested in.

Why does compact increase the file size for < 50000 documents?
Good question, I have no idea. Anybody?

What insert method is used?
Have a look at the benchmark source. Basically it's bulk-inserts of 1000 items at a time with pre-generated UUIDs.

I ran the benchmark and got some additional output
Yeah, I removed some debugging / activity indicators to make the results more readable for this article.

 

Final CakeFest Schedule Announced!

Posted on 24/6/09 by Tim Koschützki

Hey folks,

the final schedule for the upcoming CakePHP Conference - our beloved "CakeFest" - is announced! For those of you who don't know about the event yet, here is a little wrapup.

The next and third CakeFest will be held in Berlin, hometown of Debuggable! From July 9-12, people from all over Europe and the rest of the world will travel to Germany in order to celebrate and learn about the best PHP framework there is. Throughout the day you will learn a lot about:

  • .. how you can tweek your application to run faster
  • .. how to write cleaner code
  • .. how to make your code ready for the real world
  • .. how you can just become a better CakePHP developer

The evenings are packed with fun events .. dinner with the Core Team, going to bars, chatting about this and that and programming. And more.

You don't want to miss this event! :)

If you have not attended a CakeFest so far, here are some cool memories from the past:

The event consists of two parts:

  • July 9-10: CakePHP Workshop - (Lead by the CakePHP core team)
  • July 11-12: CakePHP Conference - (Presented by the core team + community)

In order to check out the full schedule with the talks and their speakers, head on over to the official CakeFest site.

Hope to see you all there!

-- Tim Koschützki aka DarkAngelBGE

 

[JOB] Senior CakePHP position with english360.com

Posted on 22/6/09 by Felix Geisendörfer

Hey there,

if you are looking for a fantastic full-time opportunity to write CakePHP code, check out this position with english360.com:

We’re a unique combination: an e-learning startup looking to shake things up through innovation, recently partnered with one of the oldest, most prestigious educational publishers in the world, Cambridge University Press.

Our flagship web application is now at version 1, and we are looking for a senior PHP developer with the desire and attitude to take the technology lead within English360. Have no fear of a poor code base: the initial application has been developed by the Cake Development Corporation, the frameworks largest contributors.

Now we are looking for you:

You’re a world-class PHP developer who has previous experience with CakePHP, or the ambition to pick it up from the folks who wrote it. You are a testing / Q&A fanatic, proficient in jQuery/HTML/CSS, and a SysAdmin wizard.

After a 6-month, full-time contractor role, you would take full responsibility for the technology side of the company, manage contractors, build your department, and collaborate with senior management on the future direction of our products. Ideally you would also be located in, or willing to relocate to either our New York City or Cambridge offices, after successful completion of your contract.

Interested? Contact e360jobs@gmail.com and impress them with a fantastic cover letter and a list of previous work!

-- Felix Geisendörfer aka the_undefined

 

What is a Testcase - especially in CakePHP?

Posted on 9/6/09 by Tim Koschützki

Hey folks,

it's amazing how many people on the public CakePHP irc channel don't know what a test case is. This has to stop. To clear up some confusion, let's have a look at it.

What is a Test Case? A Possible Definition

This is what wikipedia has to say about a testcase:

A test case in software engineering is a set of conditions or variables under which a tester will determine whether an application or software system is working correctly or not. The mechanism for determining whether a software program or system has passed or failed such a test is known as a test oracle. In some settings, an oracle could be a requirement or use case, while in others it could be a heuristic. It may take many test cases to determine that a software program or system is functioning correctly. Test cases are often referred to as test scripts, particularly when written. Written test cases are usually collected into test suites.

So is this me testing stuff in my browser?

Yes and no. The definition does not necessarily imply that a testcase has anything to do with Unit Testing, or other testing approaches.

You testing your menu bar's javascript in several browsers in different resolutions can also be considered to be a testcase (or many for that matter) according to the definition. However, most of the time a testcase is meant to be a written test. When it comes to CakePHP, it's mainly a Unit Test.

Where can I learn about test cases?

There are a ton of resources on the web for tests. If you are looking for material for CakePHP, try out these:

  1. The Article "Introduction to Unit Testing Part 1" written by yours truly
  2. The CakePHP CookBook Chapter on Testing
  3. Your First Testcase
  4. Mark Story's Unit Testing Talk Slide for CakeFest Argentinia December 2009
  5. My slides for the Unit Testing Talk for CakeFest Orlando February 2008

Lets get a discussion started to clear up confusion.

-- Tim Koschuetzki aka DarkAngelBGE

 

Migrating a Database Table for use with the CakePHP Sluggable Behavior

Posted on 8/6/09 by Tim Koschützki

Hey folks,

if you are not familiar with Mariano's Sluggable Behavior, you should definitely check it out. It's a nice tool to generate SEO-friendly urls in your application. If you are anything like debuggable.com with our long urls, you might want to look at it. ;)

If you don't know what a url slug is:

A slug is a few words that describe a post or a page. Slugs are usually a URL friendly version of the post title, but a slug can be anything you like. Slugs are meant to be used with your site's urls as they help describe what the content at the URL is. They might or might not help your SEO ranking as well for the keywords in the slug/content.

Example post url: http://flashfun247.com/games/play/racing/tg-motocross-2.

The slug for that game content is "tg-motocross-2".

This blogpost deals with migrating an existing production table into using Mariano's sluggable behavior and thereby increasing SEO friendliness of your site.

Step 1: Back up the database table

Back up the table for which you want to add slugs. We cannot be blamed for any database damage this might cause.

Step 2: Modify your database

Add a "slug" field to the table. The default length that the behavior uses is 100 chars which should be enough in most cases. So VARCHAR(100) is what you need or the equivalent for your db driver.

Step 3: Add your $actsAs declaration

Add the proper call to $actsAs to the model that you want to migrate. Put in any existing behaviors that you need as well:

var $actsAs = array(
  'Containable',
  'Lookupable',
  'Sluggable' => array('overwrite' => true)
);

Make sure to set the overwrite option, as otherwise the behavior will refuse to overwrite the slug field the way we will do it. Also make sure to set the 'label' option if the table field that your slugs will depend on is not called 'title'.

For the full host of options, check the sluggable behavior.

Important: The field your slugs depend on (title, name or combinations) MUST NOT be empty for any row in your table. The shell takes this into account and provides you with an error log. To save you some headaches, make sure the fields are properly filled before you run the sluggish shell.

Step 4: Modify The Sluggable Behavior Code

You need to change the Sluggable behavior code on two occurances to make it work with the recent Cake releases.

1. Change Line 121 to:

$conditions = array($Model->alias . '.' . $this->__settings[$Model->alias]['slug'] . ' LIKE' => $slug . '%');

2. Change Line 125 to:

$conditions[$Model->alias . '.' . $Model->primaryKey . ' <>'] = $Model->id;

This is simply changing the syntax for NOT and LIKE conditions.

Step 5: Download Debuggable's Sluggish Shell

Copy the following code to a 'sluggish.php' file in your vendors/shells folder. Just mouseover the code to see it in raw text.

<?php
/**
 * Sluggish Shell
 *
 * Set overwrite => true before running this in your $actsAs declaration!
 * This shell allows you to generate unique slugs for a database table ready for use
 * with the sluggable behavior by Mariano Iglesias
 *
 *
 * Sluggish Shell : Make your table sluggable
 * Copyright 2009, Debuggable, Ltd. (http://debuggable.com)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright 2009, Debuggable, Ltd. (http://debuggable.com)
 * @link          http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */

class SluggishShell extends Shell {
/**
 * undocumented function
 *
 * @return void
 * @access public
 */

  function main() {
    if (empty($this->args)) {
      return $this->out('You need to specify a modelname');
    }

    $model = $this->args[0];
    $force = isset($this->args[1]) ? $this->args[1] : false;

    $Model = ClassRegistry::init($model);
    $behavior = 'Sluggable';

    if (!is_object($Model)) {
      return $this->out('This model does not exist.');
    }

    if (!in_array($behavior, $Model->actsAs) && !array_key_exists($behavior, $Model->actsAs)) {
      return $this->out('The Sluggable Behavior is not yet linked to the model.');
    }

    $label = 'title';
    if (isset($Model->actsAs['Sluggable']['label'])) {
      $label = $Model->actsAs['Sluggable']['label'];
    }

    $Model->recursive = -1;
    $conditions = $force ? false : array('slug' => '');
    $rows = $Model->find('all', compact('conditions'));
    $count = count($rows);

    $i = 0;
    foreach ($rows as $row) {
      $Model->set(array(
        $Model->primaryKey => $row[$model][$Model->primaryKey],
        $label => $row[$model][$label]
      ));
      $Model->save();

      $row = $Model->find('first', array(
        'conditions' => array(
          $Model->primaryKey => $row[$model][$Model->primaryKey],
          'slug' => ''
        ),
        'contain' => false
      ));
      if (empty($row)) {
        $i++;
      } else {
        $this->out('Problem saving the slug for ' . $row[$model][$label]);
        $this->out($Model->validationErrors);
      }
    }

    $this->out('Added ' . $i . ' slugs for ' . $count . ' ' . Inflector::pluralize($model));
  }
/**
 * undocumented function
 *
 * @return void
 * @access public
 */

  function help() {
    $this->out('Debuggable Ltd. Sluggish Shell - http://debuggable.com');
    $this->hr();
    $this->out('Important: Configure your paths in the shell\'s initialize() function.');
    $this->hr();
    $this->out('This shell allows you to migrate a database table to use Mariano Iglesias\' Sluggable Behavior.');
    $this->out('Add a slug field to the table, download the sluggable behavior, add your $actsAs declaration and run this shell.');
    $this->out('');
    $this->hr();
    $this->out("Usage: cake sluggish ModelNameInCamelCase");
    $this->out('');
  }
}
?>

The code is very simple. The shell takes a modelname and checks if your $actsAs declaration is properly set up. If it is, it finds all rows from the table and saves them right away, with the label field in the Model::set() call.
Since we have specified overwrite => true in the $actsAs declaration, the sluggable behavior now overwrites all slug fields in the table, giving you nice slugs.

Step 6: Run The Sluggish Shell

Run "cake sluggish ModelNameInCamelCase" in your terminal.

Step 7: Change your urls

The Sluggable behavior creates unique slugs. If two of your blogposts for example have the same title, the first one will have 'my-blogpost-title' as its slug and the second one will have 'my-blogpost-title-1'. Mariano's behavior attaches an integer to the slug depending on how often the slug was used already.

Now that you have unique slugs, you can change your controller code and view code to take account of this. If you are heavily indexed in google already, you might want to provide 301 (permanent) redirects for the old urls, or just offer both urls to access the same blogpost, but only use slugs throughout the app.

Enjoy! Post any feedback or help requests in the comments below.

-- Tim Koschuetzki aka DarkAngelBGE

 
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11