IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

HttpsURLConnection speed download et java 8


Sujet :

Java

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Juin 2010
    Messages
    47
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2010
    Messages : 47
    Par défaut HttpsURLConnection speed download et java 8
    Bonjour a toutes et a tous,

    Je viens faire appel a vous car je rencontre un problème avec une application de téléchargement de fichier avec un ami, en java 7 mon application téléchargeai un fichier sur le reseau local a environ 32mo/s, mais depuis le passage a java 8 la vitesse est de 3mo/s.
    La division par 10 fait mal.
    Le code n'a pas changer entre le passage java 7-8.
    J'ai essayé d'augmenter la taille de mon buffer mais cela n'a pas d'impacte.
    Auriez-vous des suggestions, ou solution?

    Ps : mon module de téléchargement est dans un thread.

    Merci d'avance

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Juin 2010
    Messages
    47
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2010
    Messages : 47
    Par défaut
    j'ai effectué 2 3 tests :
    - utiliser une socket => NOK
    - utilisation de http au lieu de https => mieux 15mo/s

    il semblerai donc que l'utilisation du https ralentisse très très fortement la vitesse de download, je suis bien conscient que l'utilisation du https ralentisse le download mais quand même pas a se point.
    quand je tente de télécharger avec un navigateur internet la vitesse de download est de 30mo/s en https

    j'ai également tenté de repasser en java 7 et la niquel le débit est bon.
    y a t'il de nouveau paramètre pour cette jre 8 pour accélérer les choses?

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Juin 2010
    Messages
    47
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2010
    Messages : 47
    Par défaut
    bon alors j'ai trouvé ^^
    ce lien ma beaucoup aidé : http://stackoverflow.com/questions/1...for-ssl-socket

    j'ai implémenter cette class
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    class SSLSocketFactoryEx extends SSLSocketFactory
    {
        public SSLSocketFactoryEx() throws NoSuchAlgorithmException, KeyManagementException
        {
            initSSLSocketFactoryEx(null,null,null);
        }
     
        public SSLSocketFactoryEx(KeyManager[] km, TrustManager[] tm, SecureRandom random) throws NoSuchAlgorithmException, KeyManagementException
        {
            initSSLSocketFactoryEx(km, tm, random);
        }
     
        public SSLSocketFactoryEx(SSLContext ctx) throws NoSuchAlgorithmException, KeyManagementException
        {
            initSSLSocketFactoryEx(ctx);
        }
     
        public String[] getDefaultCipherSuites()
        {
            return m_ciphers;
        }
     
        public String[] getSupportedCipherSuites()
        {
            return m_ciphers;
        }
     
        public String[] getDefaultProtocols()
        {
            return m_protocols;
        }
     
        public String[] getSupportedProtocols()
        {
            return m_protocols;
        }
     
        public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException
        {
            SSLSocketFactory factory = m_ctx.getSocketFactory();
            SSLSocket ss = (SSLSocket)factory.createSocket(s, host, port, autoClose);
     
            ss.setEnabledProtocols(m_protocols);
            ss.setEnabledCipherSuites(m_ciphers);
     
            return ss;
        }
     
        public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException
        {
            SSLSocketFactory factory = m_ctx.getSocketFactory();
            SSLSocket ss = (SSLSocket)factory.createSocket(address, port, localAddress, localPort);
     
            ss.setEnabledProtocols(m_protocols);
            ss.setEnabledCipherSuites(m_ciphers);
     
            return ss;
        }
     
        public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException
        {
            SSLSocketFactory factory = m_ctx.getSocketFactory();
            SSLSocket ss = (SSLSocket)factory.createSocket(host, port, localHost, localPort);
     
            ss.setEnabledProtocols(m_protocols);
            ss.setEnabledCipherSuites(m_ciphers);
     
            return ss;
        }
     
        public Socket createSocket(InetAddress host, int port) throws IOException
        {
            SSLSocketFactory factory = m_ctx.getSocketFactory();
            SSLSocket ss = (SSLSocket)factory.createSocket(host, port);
     
            ss.setEnabledProtocols(m_protocols);
            ss.setEnabledCipherSuites(m_ciphers);
     
            return ss;
        }
     
        public Socket createSocket(String host, int port) throws IOException
        {
            SSLSocketFactory factory = m_ctx.getSocketFactory();
            SSLSocket ss = (SSLSocket)factory.createSocket(host, port);
     
            ss.setEnabledProtocols(m_protocols);
            ss.setEnabledCipherSuites(m_ciphers);
     
            return ss;
        }
     
        private void initSSLSocketFactoryEx(KeyManager[] km, TrustManager[] tm, SecureRandom random)
        throws NoSuchAlgorithmException, KeyManagementException
        {
            m_ctx = SSLContext.getInstance("TLS");
            m_ctx.init(km, tm, random);
     
            m_protocols = GetProtocolList();
            m_ciphers = GetCipherList();
        }
     
        private void initSSLSocketFactoryEx(SSLContext ctx)
        throws NoSuchAlgorithmException, KeyManagementException
        {
            m_ctx = ctx;
     
            m_protocols = GetProtocolList();
            m_ciphers = GetCipherList();
        }
     
        protected String[] GetProtocolList()
        {
            String[] preferredProtocols = { "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3" };
            String[] availableProtocols = null;
     
            SSLSocket socket = null;
     
            try
            {
                SSLSocketFactory factory = m_ctx.getSocketFactory();
                socket = (SSLSocket)factory.createSocket();
     
                availableProtocols = socket.getSupportedProtocols();
                Arrays.sort(availableProtocols);
            }
            catch(Exception e)
            {
                return new String[]{ "TLSv1" };
            }
            finally
            {
                if(socket != null)
                    socket.close();
            }
     
            List<String> aa = new ArrayList<String>();
            for(int i = 0; i < preferredProtocols.length; i++)
            {
                int idx = Arrays.binarySearch(availableProtocols, preferredProtocols[i]);
                if(idx >= 0)
                    aa.add(preferredProtocols[i]);
            }
     
            return aa.toArray(new String[0]);
        }
     
        protected String[] GetCipherList()
        {
            String[] preferredCiphers = {
     
                // *_CHACHA20_POLY1305 are 3x to 4x faster than existing cipher suites.
                //   http://googleonlinesecurity.blogspot.com/2014/04/speeding-up-and-strengthening-https.html
                // Use them if available. Normative names can be found at (TLS spec depends on IPSec spec):
                //   http://tools.ietf.org/html/draft-nir-ipsecme-chacha20-poly1305-01
                //   http://tools.ietf.org/html/draft-mavrogiannopoulos-chacha-tls-02
                "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305",
                "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305",
                "TLS_ECDHE_ECDSA_WITH_CHACHA20_SHA",
                "TLS_ECDHE_RSA_WITH_CHACHA20_SHA",
     
                "TLS_DHE_RSA_WITH_CHACHA20_POLY1305",
                "TLS_RSA_WITH_CHACHA20_POLY1305",
                "TLS_DHE_RSA_WITH_CHACHA20_SHA",
                "TLS_RSA_WITH_CHACHA20_SHA",
     
                // Done with bleeding edge, back to TLS v1.2 and below
                "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384",
                "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384",
                "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
                "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
     
                "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
                "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384",
                "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
                "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256",
     
                // TLS v1.0 (with some SSLv3 interop)
                "TLS_DHE_RSA_WITH_AES_256_CBC_SHA384",
                "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256",
                "TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
                "TLS_DHE_DSS_WITH_AES_128_CBC_SHA",
     
                "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA",
                "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA",
                "SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA",
                "SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA",
     
                // RSA key transport sucks, but they are needed as a fallback.
                // For example, microsoft.com fails under all versions of TLS
                // if they are not included. If only TLS 1.0 is available at
                // the client, then google.com will fail too. TLS v1.3 is
                // trying to deprecate them, so it will be interesteng to see
                // what happens.
                "TLS_RSA_WITH_AES_256_CBC_SHA256",
                "TLS_RSA_WITH_AES_256_CBC_SHA",
                "TLS_RSA_WITH_AES_128_CBC_SHA256",
                "TLS_RSA_WITH_AES_128_CBC_SHA"
            };
     
            String[] availableCiphers = null;
     
            try
            {
                SSLSocketFactory factory = m_ctx.getSocketFactory();
                availableCiphers = factory.getSupportedCipherSuites();
                Arrays.sort(availableCiphers);
            }
            catch(Exception e)
            {
                return new String[] {
                    "TLS_DHE_DSS_WITH_AES_128_CBC_SHA",
                    "TLS_DHE_DSS_WITH_AES_256_CBC_SHA",
                    "TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
                    "TLS_DHE_RSA_WITH_AES_256_CBC_SHA",
                    "TLS_RSA_WITH_AES_256_CBC_SHA256",
                    "TLS_RSA_WITH_AES_256_CBC_SHA",
                    "TLS_RSA_WITH_AES_128_CBC_SHA256",
                    "TLS_RSA_WITH_AES_128_CBC_SHA",
                    "TLS_EMPTY_RENEGOTIATION_INFO_SCSV"
                };
            }
     
            List<String> aa = new ArrayList<String>();
            for(int i = 0; i < preferredCiphers.length; i++)
            {
                int idx = Arrays.binarySearch(availableCiphers, preferredCiphers[i]);
                if(idx >= 0)
                    aa.add(preferredCiphers[i]);
            }
     
            aa.add("TLS_EMPTY_RENEGOTIATION_INFO_SCSV");
     
            return aa.toArray(new String[0]);
        }
     
        private SSLContext m_ctx;
     
        private String[] m_ciphers;
        private String[] m_protocols;
    }
    je n'ai laissé que les ciphers qui correspondaient le mieux avec le serveur (+ verification poodle)

    concernant l'implementation avec HttpsURLConnection :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
     
    SSLSocketFactoryEx factory = new SSLSocketFactoryEx();
    connection.setSSLSocketFactory(factory);

  4. #4
    Modérateur
    Avatar de Gugelhupf
    Homme Profil pro
    Analyste Programmeur
    Inscrit en
    Décembre 2011
    Messages
    1 326
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Analyste Programmeur

    Informations forums :
    Inscription : Décembre 2011
    Messages : 1 326
    Billets dans le blog
    12
    Par défaut
    C'est peut-être un changement d'algorithme (entre Java 7 et 8) lié à la sécurité qui impacte sur la vitesse.
    A moins d'être fin connaisseur en SSL/TLS je ne prendrais pas le risque d'utiliser ce type de classe.
    N'hésitez pas à consulter la FAQ Java, lire les cours et tutoriels Java, et à poser vos questions sur les forums d'entraide Java

    Ma page Developpez | Mon profil Linkedin | Vous souhaitez me contacter ? Contacter Gokan EKINCI

Discussions similaires

  1. Réponses: 3
    Dernier message: 02/03/2012, 02h16
  2. download source java
    Par stanilas dans le forum Débuter avec Java
    Réponses: 1
    Dernier message: 13/06/2011, 16h29
  3. Download file Java heap space JSF
    Par len1sensibl dans le forum JSF
    Réponses: 2
    Dernier message: 04/05/2011, 15h00
  4. Download avec un appelet java
    Par nabmoah dans le forum Applets
    Réponses: 1
    Dernier message: 19/04/2008, 15h56
  5. downloader un fichier avec une applet JAVA
    Par jacques64 dans le forum Applets
    Réponses: 2
    Dernier message: 03/09/2007, 11h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo