Question

We are running a MySQL/PHP based web app coded in Laravel. Basically we use it to manage service jobs/work orders at a computer repair shop. We have almost 2500 work orders in there and it's running a tad slow sometimes, especially when multiple technicians are entering or updating work orders. What are the best ways to make it faster and work more efficiently especially as we continue to add customers and work orders. The server is running CentOS 6 x64, cPanel, Intel Xeon E3, 2x Enterprise SATA in Linux Software RAID1. Thanks!

Was it helpful?

Solution

Not sure how deep one answer can go in specifying a solution but there many best practices to follow. I take it this is what you're after as you didn't specify any particular bottlenecks.

Some quick tips would be to

  • Cache your queries:

So if there is a query run on your app, for which the data is only updated every x days, why not cache this for x days so that your db saves being hit needlessly in between? Example from the docs:

$value = Cache::remember('users', $minutes, function()
{
    return DB::table('users')->get();
});
  • Make use of queues:

It may be the case that background tasks are being run when a user, for example, updated work order (emails, calling other logic) which may take some time and causes that user to have to wait. Instead of having these tasks run at that moment and slow things down for the user, you could queue them to be run at a later point. Laravel supports many different queue drivers for this purpose. I've personally used Beanstalk but you could try something like IronMQ as well.

Basic usage with Beanstalk: change /app/config/queue.php to specify your default queue driver and any config, including the name of a queue:

'default' => 'beanstalkd',


'beanstalkd' => array(
        'driver' => 'beanstalkd',
        'host'   => 'localhost',
        'queue'  => array('default','SendEmail'),
    ),

Then, within your controller, you could do the following to push to that queue:

Queue::push('SendEmail', array('message' => 'Something...'));

FYI, Fideloper has an excellent tutorial on this.

  • Be wary of the n+1 problem and use eager loading:

The docs explain this issue.

  • Consider switching to a NoSql database like MongoDB (depends entirely on requirements):

As I mentioned, this depends entirely on your app and what you're doing but using a NoSql database over MySQL has its merits in certain cases. You could make use of sharding and replication to help with scaling your app with MongoDB but ofcourse aren't limited to mongo alone.

There are many other things you can do, but with the above tips alone, I think you could make your app significantly faster and more efficient.

OTHER TIPS

Make sure too your most used tables are Innodb and not MyIsam to avoid table locking.

For MyIsam table when a row is inserted or updated, all other changes to that table are held up until that request has been completed.

You can try using this packagist https://packagist.org/packages/enfil/sharding

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top