Vapor Octane Support Is Now Available

Nuno Maduro
Nuno Maduro
...

Today we're pleased to announce that Octane support is now available in Laravel Vapor. The speed improvements are just mind-blowing, so put on your seat belt and let's get into the details.

If you haven't heard about Octane, it's a Laravel library that supercharges your application's performance by booting your application once, keeping it in memory, and then feeding it requests at supersonic speeds.

Now, when combining Octane with Vapor's on-demand auto-scaling, you get blazing-fast load times at any scale. Let's take a look at some numbers using a Vapor project on the Amazon's us-west-1 region. This Vapor application is configured with 1024 MB of RAM and an RDS MySQL instance (db.t2.micro) with 1 VCPU and 1Gib RAM.

First, let's take a look at an API endpoint that gets a user from the database. Using Octane, this endpoint is 7x faster and uses 44% less memory:

# Before Vapor's Octane integrationRequest Duration: 39.40 ms, Memory Used: 169 MBRequest Duration: 40.20 ms, Memory Used: 169 MBRequest Duration: 37.71 ms, Memory Used: 169 MBRequest Duration: 42.16 ms, Memory Used: 169 MBRequest Duration: 40.60 ms, Memory Used: 169 MBRequest Duration: 45.75 ms, Memory Used: 169 MB# After Vapor's Octane integrationRequest Duration: 6.78 ms, Memory Used: 112 MBRequest Duration: 6.64 ms, Memory Used: 112 MBRequest Duration: 6.67 ms, Memory Used: 112 MBRequest Duration: 6.38 ms, Memory Used: 112 MBRequest Duration: 6.75 ms, Memory Used: 112 MBRequest Duration: 6.47 ms, Memory Used: 112 MB

Next, let's take a look at a login route which renders a static template. Using Octane, this endpoint is almost 3x faster and uses 35% less memory:

# Before Vapor's Octane integrationRequest Duration: 11.32 ms, Memory Used: 165 MBRequest Duration: 11.35 ms, Memory Used: 165 MBRequest Duration: 11.29 ms, Memory Used: 165 MBRequest Duration: 11.29 ms, Memory Used: 165 MBRequest Duration: 11.36 ms, Memory Used: 165 MBRequest Duration: 11.43 ms, Memory Used: 165 MB# After Vapor's Octane integrationRequest Duration: 4.89 ms, Memory Used: 108 MB Request Duration: 4.89 ms, Memory Used: 108 MB Request Duration: 4.83 ms, Memory Used: 108 MB Request Duration: 4.66 ms, Memory Used: 108 MB Request Duration: 4.79 ms, Memory Used: 108 MB Request Duration: 4.91 ms, Memory Used: 108 MB

As you can see, using Octane decreases both request duration and memory usage. And, of course, because AWS applies 1ms billing granularity on Lambda, you will pay less for your HTTP function.

How to get started

First, ensure you are using latest version of Laravel, Vapor Core, and Vapor CLI:

  • Laravel Framework: ^8.62.0
  • Vapor Cli: ^1.26.0
  • Vapor Core: ^2.14.0

Next, install Octane in your Vapor project. Octane may be installed via the Composer package manager:

composer require laravel/octane

After installing Octane, you may execute the octane:install Artisan command, which will install Octane's configuration file into your application:

php artisan octane:install

Next, if you haven't tried Octane before in your application, you may want to test it locally. Of course, don't forget to review important Octane documentation topics such as dependency injection and managing memory leaks.

Finally, you may instruct Vapor to use Octane by setting the octane configuration option within your application's vapor.yml file:

id: 1name: my-applicationenvironments: staging: memory: 1024 runtime: 'php-8.0:al2' octane: true

In addition, if your project uses a database, you may use the octane-database-session-persist and octane-database-session-ttl options to instruct Octane that database connections should be reused between requests:

 database: my-database octane: true octane-database-session-persist: true octane-database-session-ttl: 10
  • The octane-database-session-persist option indicates that database connections should persist between requests. The main purpose of this option is to reduce the overhead involved on creating a database connection on each request.
  • The octane-database-session-ttl option allows specifying the time (in seconds) the Lambda container should stay connected to the database when the Lambda container is not being used.

We recommended that you specify an octane-database-session-ttl value; otherwise, the Lambda container will stay connected to your database until the Lambda container gets destroyed. This may take several minutes and may result in your database becoming overwhelmed with active connections.

Please review Vapor's Octane integration documentation for more details.

Conclusion

Also, we would like to thanks Aaron Francis, for the proposal and initial exploration on having Octane on Vapor. We care and study every proposal made by the community.

We hope you enjoy this new feature. At Laravel, we're committed to providing you with the most robust and developer-friendly PHP experience in the world. If you haven't checked out Vapor, now is a great time to start! You can create your account today at: vapor.laravel.com.

At Larasoft.io Ltd, We offer web design company London at an unbeatable cost. Our main motive only is customer satisfaction.

Nuno Maduro
Nuno Maduro

Latest Stories

Here’s what we've been up to recently.

Request a code sample

Certified Quality. Great Prices

We use cookies to improve your experience and to help us understand how you use our site. By using this site, you accept our use of cookies. Cookie Infox