Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

performance issue on mac os x when using localhost in url #44

Closed
ErikGrimes opened this issue Oct 14, 2016 · 1 comment
Closed

performance issue on mac os x when using localhost in url #44

ErikGrimes opened this issue Oct 14, 2016 · 1 comment

Comments

@ErikGrimes
Copy link

A simple request like getting the string "hello" using the http package from a shelf server running on the same host takes an unusually long time (5 seconds) when the url refers to localhost on my mac. The same connection takes less than 5 milliseconds on Chrome. The request takes less than 100 ms when the url uses 127.0.0.1 instead of localhost. I repeated the test on an Ubuntu Linux machine using localhost and it behaves as expected.

client

import 'package:http/http.dart' as http;

main(List<String> args) async {

    var client = new http.Client();

    Stopwatch sw = new Stopwatch();
    sw.start();

    var response = await client.get(Uri.parse("http://localhost:10080"));

    sw.stop();

    print('response received ${sw.elapsedMilliseconds}');
    client.close();



}

server

import 'dart:io';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart';

main(List<String> args) async {

  var handler = (Request r){
    return new Response.ok("hello");
  } ;

  var server = await serve(const Pipeline()
      .addMiddleware(logRequests())
      .addHandler(handler),  InternetAddress.ANY_IP_V4, 10080);

  print('Serving at http://${server.address.host}:${server.port}');

sdk: 1.19.1
mac os x: 10.11.6
http: 0.11.3+9
shelf: 0.6.5+3

@ErikGrimes ErikGrimes changed the title localhost connection performance issue on mac os x performance issue on mac os x when using localhost in url Oct 14, 2016
@ErikGrimes
Copy link
Author

This appears to be related to Mac OS X and not Dart. I'm seeing the same connection delay to "localhost" from Java.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant