Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

2g cut to the wifi, the network seems to still use 2g, very slow #11

Closed
zhuolaiqiang opened this issue Dec 29, 2013 · 6 comments
Closed

Comments

@zhuolaiqiang
Copy link

2g cut to the wifi, the network seems to still use 2g, very slow。

You can determine the current state of network status and to establish a network socket connection is the same, if not the same, re-socket connection

@goaway
Copy link
Collaborator

goaway commented Dec 29, 2013

Hey @zhuolaiqiang, thanks for opening the issue. This is known problem when hopping networks and is due to a bug in how session re-use occurs. The fix, as you describe, is to drain the currently active session when network reachability status changes to indicate the presence of a potentially faster network and establish a new connection. We need to do some testing though to ensure we're not frequently and unnecessarily draining healthy sessions.

@seivan
Copy link
Contributor

seivan commented Dec 30, 2013

@goaway By sessions, do you mean NSURLSession or a request?

@goaway
Copy link
Collaborator

goaway commented Dec 30, 2013

Sorry, to clarify, what I meant was a SPDY session, as encapsulated by the SPDYSession class and described in the protocol draft.

If you have an open SPDY connection (session) to a server via a cellular data connection (WWAN) and a WIFI connection becomes available while the WWAN is also still available, as currently implemented the protocol will continue to dispatch requests over the existing session until it closes. If both the client and the server are configured to allow long-lived connections this could be quite a long time, resulting in the faster network not getting utilized.

As a stopgap measure, you could of course configure the server to timeout the connection after a shorter period, ensuring the user would switch to the faster network sooner, but setting it too short defeats some of the purpose (and performance gains) of SPDY.

If we operate on the premise that a WIFI connection is always better (not necessarily always true from a performance standpoint, but probably a reasonable assumption for now), probably the best case solution would be to open a WIFI SPDY session as soon as WIFI becomes available while attempting to gracefully drain the WWAN session. Another possibility would be to maintain both, but prefer the WIFI session as long as it's open. The disadvantage here is that it potentially complicates the landscape for things like server push.

@zhuolaiqiang
Copy link
Author

hi, I have a temporary fix this problem , every time I make a network request , will determine whether the current network status and links to network socket consistent state , and if not , re- socket connection. There is no performance problems found

@zhuolaiqiang
Copy link
Author

  • (SPDYSession )sessionForURL:(NSURL *)url error:(NSError *)pError
    {
    SPDYOrigin *origin = [[SPDYOrigin alloc] initWithURL:url error:pError];
    NSMutableDictionary *activeSessions = [SPDYSessionManager activeSessions];
    SPDYSession *session = activeSessions[origin];

    BOOL networkChange = NO; //亿刀加
    if (session) //亿刀加
    { //亿刀加
    networkChange = session.currentStatus != session.networkStatus; //亿刀加
    } //亿刀加

    if (!session
    || !session.isOpen
    || networkChange //亿刀加
    )
    {
    session = [[SPDYSession alloc] initWithOrigin:origin
    configuration:currentConfiguration
    error:pError];
    if (session)
    {
    activeSessions[origin] = session;
    }
    }
    return session;
    }

@goaway
Copy link
Collaborator

goaway commented Jan 7, 2014

Care to issue a pull request against the develop branch? I think this at least seems like a good starting point, and I'm curious as to how you scheduled your SCNetworkReachability callback (which I'm assuming is what you used to set currentStatus/networkStatus).

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

No branches or pull requests

3 participants