Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8374803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:00:33+00:00 2026-06-09T15:00:33+00:00

In Video controller – Show action, I’ve tried with two scenarios. The first one

  • 0

In Video controller – Show action, I’ve tried with two scenarios. The first one uses increment_counter, and writes to the db directly:

Video.increment_counter(:views_count, @video.id)

The second approach uses the save method.

@video.views_count = @video.views_count + 1
@video.save

In ApacheBench, I do:

ab -n 100 -c 10 http://127.0.0.1:3000vidoes/18

Video id is 18. I make sure to reset views_count on each ab run, via Video.find(18).update_attribute(:views_count, 18).

After running ApacheBench for both scenarios, views_count is consistent at 100. I would have imagined increment_counter to be more accurate than save method, since it writes to the db directly.

Am I benching correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:00:34+00:00Added an answer on June 9, 2026 at 3:00 pm

    The reason you get the correct answer with both methods is that you’re not really testing parallelism here. While apachebench is firing off 10 concurrent requests, your rails server is only handling one of them at a time. Try one of the following to exploit the race condition present in the second scenario:

    • fire up multiple rails servers and put them behind a load balancer. You can do this with passenger, or with something like thin -s 4 and then putting all those servers behind an nginx or haproxy instance.
    • switch to using a threaded solution that avoids the GIL, like JRuby or rubinius running under puma
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My app uses video displayed by a view controller in a view (View 1)
I'm serving video from an MVC3 site, with the controller action that returns the
I present one controller to play video: [self presentModalViewController:movieController animated:YES]; and add an observer
I call this method in my controller: delete_heard_timeline_event(current_user.id, @showable_video.user.id, @showable_video.video.id) and I definite it
Hey all... I have a view controller (A) which on some action, alloc init's
I want to play a video with an MPMoviePlayerViewController. So in my view controller
I'm currently watching a video course about ASP.NET Web API. When a controller gets
I'm trying to get my XBox controller working in Unity. I used this video:
I want to create a audio or video controller, but my current code only
I have a view controller which plays a video in viewDidLoad . I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.