Support the ongoing development of Laravel.io →
posted 10 years ago
Database

When connecting to a remote MySql server (local network), each database query takes 20-30-40 or more milliseconds. Both first and subsequent requests, so it's not a cache issue. When executed on the remote server (phpMyAdmin), the query runs blazing fast, under 1millisecond. Queries are very, very simple: select * from users where id = '1' limit 1

This would not be a big issue if you'd have 2 or 3 queries, but when you have 10-20 or even 500 queries, this is a problem.

A similar CodeIgniter application, connecting to the same remote MySql server, runs 20 times (or more) faster. So this is not a MySql issue.

Both Laravel and Codeigniter are executed from a vagrant environment (CentOS 6.5), connecting to a remote database in the same network.

I've tried to exclude the application layer from this and setup a test like this:

  • a Laravel application, in a for...loop, run a query 300 times, both Eloquent and Query Builder variants
  • a CodeIgniter application, in a for...loop, run a query 300 times, both Active Record and raw query variants

Laravel completes in 13 seconds. CodeIgniter in 0.4 seconds

As soon as I switch the connection from remote IP to localhost, Laravel performs very fast, under 100milliseconds.

Trying to exclude a faulty vagrant machine, I've tried with Ubuntu. Same results.

Am I missing something related to remote mysql connections?

An image with queries sent from Laravel to remote server: https://www.dropbox.com/s/6csdhwi4zexstun/mysql-queries.png

An image with queries sent from Laravel to localhost: https://www.dropbox.com/s/qiebqy0bmzqfapa/mysql-queries-localhost.png

Last updated 2 years ago.
0

Hi mate, I am having same issues and nobody answer anything. Have you found anything to improve the query performance? http://laravel.io/forum/02-26-2015-another-question-regarding-performance?page=1#reply-21639

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.