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 8954831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:24:04+00:00 2026-06-15T14:24:04+00:00

That’s my first time with EM so I really need some help here so

  • 0

That’s my first time with EM so I really need some help here

so here’s the code:

EM.run do
  queue = EM::Queue.new
  EM.start_server('0.0.0.0', '9000', RequestHandler, queue)

  puts 'Server started on localhost:9000' # Any interface, actually

  process_queue = proc do |url|
    request = EM::HttpRequest.new(url, connect_timeout: 1).get # No time to wait, sorry

    request.callback do |http| # deferrable
      puts http.response_header.status
    end

    queue.pop(&process_queue)
  end

  EM.next_tick { queue.pop(&process_queue) }
end

I’ve read a couple of articles about EM, now my understanding of above code is the following:

EM::HttpRequest is deferrable, which means it won’t block a reactor.
But when I try running 50 concurrent connections with ab, it only serves ~20 concurrently ( according to ab report ).

But if I place the process_queue execution inside EM.defer( which means it will run in a separate thread? ) it performs just fine.

Why is it so? process_queue just inits a deferrable object and assigns a callback, how does running it inside EM.defer makes a difference?

  • 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-15T14:24:05+00:00Added an answer on June 15, 2026 at 2:24 pm

    One thing you may want to do is put the queue.pop(&process_queue) in the process_queue callback inside an EM.next_tick. Currently you’re going to process all of the queued connections before you allow anything new to connect. If you put the queue.pop into a next_tick call you’ll let the reactor do some work before you process the next item.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That simple. I need to create a View using Code First. I found nothing
That's how I'm new in here on the website so it would be super
That might sound silly but can't do it myself :( Need your help guys.
That's a really awkward title :) I need to write a report that generates
That's my question, and here's my example code. HTML: <a class=fancybox rel=group href=img1.jpg> <img
That's the first time I use stack overflow 'cause I got a problem develop
That title is presumably awfully worded. I have some PostgreSQL tables. There is a
That's about all I need to ask. Checked the PHP manual and saw a
That's kinda vague so here's the meaty stuff: I have seen authentication systems that
That code work: startSlideshow(<?php echo json_encode(glob(photos-animaux/*.jpg))?>); that code dont : $.post(,{'folder':'animaux'}); startSlideshow(<?php echo json_encode(glob(photos-.$_GET[folder]./*.jpg))?>);

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.