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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:32:16+00:00 2026-05-27T21:32:16+00:00

When I run my test code for EventMachine, I found there are too many

  • 0

When I run my test code for EventMachine, I found there are too many “TIME_WAIT” connections. Is it a problem?

run netstat -anp | grep 8080

    tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      13012/ruby      
    tcp        0      0 127.0.0.1:38701         127.0.0.1:8080          TIME_WAIT   -               
    tcp        0      0 127.0.0.1:38706         127.0.0.1:8080          TIME_WAIT   -               
    tcp        0      0 127.0.0.1:38709         127.0.0.1:8080          TIME_WAIT   -               
    tcp        0      0 127.0.0.1:38708         127.0.0.1:8080          TIME_WAIT   -               
    tcp        0      0 127.0.0.1:38699         127.0.0.1:8080          TIME_WAIT   -               
    tcp        0      0 127.0.0.1:38700         127.0.0.1:8080          TIME_WAIT   -               
    tcp        0      0 127.0.0.1:38707         127.0.0.1:8080          TIME_WAIT   -               
    tcp        0      0 127.0.0.1:38705         127.0.0.1:8080          TIME_WAIT   -               
    tcp        0      0 127.0.0.1:38702         127.0.0.1:8080          TIME_WAIT   -               
    tcp        0      0 127.0.0.1:38703         127.0.0.1:8080          TIME_WAIT   -               
    tcp        0      0 127.0.0.1:38704         127.0.0.1:8080          TIME_WAIT   -   

My test client code is:

require 'rubygems'
require 'benchmark'
require 'socket'
require 'logger'
Benchmark.bm do |x|
  logger = Logger.new('test.log', 10, 1024000) 
  logger.datetime_format = "%Y-%m-%d %H:%M:%S"
  logger.info "----------------------------------"
  x.report("times:") do
    for i in 0..20
      sleep 0.1
      Thread.new do
        TCPSocket.open "127.0.0.1", 8080 do |s|
                    s.send "#{i}", 0
          if result = s.recv(100)  
            logger.info result
          end
        end
      end
    end
  end
end

My test server code is:

require 'rubygems'
require 'benchmark'
require 'eventmachine'
class Handler  < EventMachine::Connection
  def initialize(*args)
    super
  end

  def receive_data(data)
    puts "------------------------"
    @reply = data   
    @state = :processing
    EventMachine.defer(method(:do_something), method(:callback))
  rescue Exception => ex
    LOGGER.error "#{ex.class}: #{ex.message}\n#{ex.backtrace.join("\n")}"
  end

  def do_something
    #simulate a long running request
    a = []
    for i in 1..3000
      a << rand(3000)
      a.sort!
    end 
    return @reply
  end

  def callback(msg)
    self.send_data msg
    @state = :closing
  end

  def unbind
    close_connection_after_writing #unless @state == :processing 
  end

end

EventMachine::run {
  EventMachine.epoll
  EventMachine::start_server("0.0.0.0", 8080, Handler)
  puts "Listening..."
}
  • 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-05-27T21:32:16+00:00Added an answer on May 27, 2026 at 9:32 pm

    The TIME_WAIT state lasts for two minutes and provides critically important connection security in TCP. It isn’t a problem, it’s a solution.

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

Sidebar

Related Questions

When I run a Test Project on Visual Studio I use the code below
When I run the following code to test copying a directory, I get a
I have a problem: if i run this test in NUnit ,it works Board
In symfony 1.x, with some code it was possible to run test without modify
When I select run file to test my code the GUI application's menu bar
Sometimes I see people use http://codepad.org as a way to quickly run/test their Perl
When I run the test suite of django I get errors on the auth
How can you run AsUnit test runner from Ant? I'm on the Mac OS
When I run a test harness through the Visual Studio 2005 debugger, it creates
I'm trying to run JUnit4 test cases on Eclipse 3.4.2 but it's not even

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.