gpt4 book ai didi

performance - WWW::Mechanize with SSL 可以工作,但响应很慢

转载 作者:太空宇宙 更新时间:2023-11-03 12:59:15 25 4
gpt4 key购买 nike

我正在使用 WWW::Mechanize与运行其自己的基于 SSLv3 的 Web 服务器的硬件建立 HTTPS 连接。

我的代码可以运行,但对 get()、submit() 和 click() 的响应很慢,需要 6 到 12 秒。

配置问题导致服务器的 IP 地址与其证书中使用的 IP 地址不同。因此,我暂时忽略主机名验证。

这可能是 WWW::Mechanize 运行缓慢的原因。但是,使用常规 Web 浏览器执行相同功能时不会出现任何缓慢。我在 Solaris 10 (sparc) 上运行,使用 Perl 5.20.1 和 OpenSSL 0.7.9d。 Mechanize 在与不同服务器建立正常 HTTP 连接时运行速度很快。

我还尝试了所有代理别名。没提升。

use WWW::Mechanize;
$ENV{HTTPS_VERSION} = 3; # Try SSLv3 first
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; # Ignore verification
my $agent = WWW::Mechanize->new( autocheck => 1 );
$agent->get($https_url);
$agent->credentials( $username, $password );
$agent->get($status_url);
print "$agent->{content}\n";
$agent->form_number(2);
$agent->click();
print "$agent->{content}\n";

更新:

我将 OpenSSL 更新为 1.0.1j 并重新编译了 Net::SSLeay 1.66。我还将 IO::Socket::SSL 更新为 2.002。我仍然看到相同的行为。

然后我重新编译了 LWP::Protocol::https 6.0.6 和 WWW::Mechanize 1.73 以取得良好的效果。相同的行为。

我将 use IO::Socket::SSL qw(debug3); 添加到我的脚本中。我可以在调试输出中看到 6 秒的延迟。

Fetching initial page...
DEBUG: .../IO/Socket/SSL.pm:2537: new ctx 11476520
DEBUG: .../IO/Socket/SSL.pm:529: socket not yet connected
DEBUG: .../IO/Socket/SSL.pm:531: socket connected
DEBUG: .../IO/Socket/SSL.pm:553: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:589: not using SNI because hostname is unknown
DEBUG: .../IO/Socket/SSL.pm:640: set socket to non-blocking to enforce timeout=180
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:663: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:673: waiting for fd to become ready: SSL wants a read first
DEBUG: .../IO/Socket/SSL.pm:693: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:663: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:673: waiting for fd to become ready: SSL wants a read first
# >>> There's a 6 second delay here <<<
DEBUG: .../IO/Socket/SSL.pm:693: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:708: ssl handshake done
DEBUG: .../IO/Socket/SSL.pm:2570: free ctx 11476520 open=11476520
DEBUG: .../IO/Socket/SSL.pm:2582: OK free ctx 11476520
Credentials...
Fetching status page...
DEBUG: .../IO/Socket/SSL.pm:2537: new ctx 11476520
DEBUG: .../IO/Socket/SSL.pm:529: socket not yet connected
DEBUG: .../IO/Socket/SSL.pm:531: socket connected
DEBUG: .../IO/Socket/SSL.pm:553: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:589: not using SNI because hostname is unknown
DEBUG: .../IO/Socket/SSL.pm:640: set socket to non-blocking to enforce timeout=180
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:663: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:673: waiting for fd to become ready: SSL wants a read first
DEBUG: .../IO/Socket/SSL.pm:693: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:663: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:673: waiting for fd to become ready: SSL wants a read first
# >>> Another 6 second delay <<<
DEBUG: .../IO/Socket/SSL.pm:693: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:708: ssl handshake done
DEBUG: .../IO/Socket/SSL.pm:2570: free ctx 11476520 open=11476520
DEBUG: .../IO/Socket/SSL.pm:2582: OK free ctx 11476520
DEBUG: .../IO/Socket/SSL.pm:2537: new ctx 11476520
DEBUG: .../IO/Socket/SSL.pm:529: socket not yet connected
DEBUG: .../IO/Socket/SSL.pm:531: socket connected
DEBUG: .../IO/Socket/SSL.pm:553: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:589: not using SNI because hostname is unknown
DEBUG: .../IO/Socket/SSL.pm:640: set socket to non-blocking to enforce timeout=180
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:663: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:673: waiting for fd to become ready: SSL wants a read first
DEBUG: .../IO/Socket/SSL.pm:693: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:663: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:673: waiting for fd to become ready: SSL wants a read first
# >>> Another 6 second delay <<<
DEBUG: .../IO/Socket/SSL.pm:693: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:708: ssl handshake done
DEBUG: .../IO/Socket/SSL.pm:2570: free ctx 11476520 open=11476520
DEBUG: .../IO/Socket/SSL.pm:2582: OK free ctx 11476520
Submitting form...
# Repeat of behavior when fetching the initial page, except ctx is 12700768

解决方案:

这是我的工作脚本,其中包含我与 Steffen 对话中描述的更改。保持事件是解决方案。

use WWW::Mechanize;
use IO::Socket::SSL qw(debug3); # Turn on level 3 debug
use LWP::ConnCache;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; # Ignore verification
my $agent = WWW::Mechanize->new(autocheck => 1);
$agent->conn_cache(LWP::ConnCache->new); # Enable keep-alive
$agent->get($https_url);
$agent->credentials($username, $password);
$agent->get($status_url);
$agent->form_number(2);
$agent->click();

最佳答案

There's a configuration issue that's causing the server's IP address to differ from the one it uses in its certificate. For that reason, I'm ignoring hostname verification for the time being.

最好使用 IO::Socket::SSL 的 SSL_verifycn_name 设置来定义证书中您期望的名称。

That could be the reason why WWW::Mechanize is slow.

可能不会,因为您只是禁用检查。禁用不会使其变慢,但启用也不会使其变慢,因为这些检查很快并且不需要任何额外的网络事件。

I'm running on Solaris 10 (sparc), with Perl 5.20.1 and OpenSSL 0.7.9d.

我怀疑您使用的是 0.7.9d,您可能是指 0.9.7d。它仍然是一个非常不寻常的配置,即使用现代 Perl 和 10 年前的 OpenSSL 版本。我建议您改用当前版本,这样也许您的问题就会消失。

However, there isn't any slowness when using a regular web browser to perform the same functions.

当前的浏览器使用现代 TLS 堆栈,它具有更高效的密码、 session 恢复等。再次尝试使用最新版本的 OpenSSL。

关于performance - WWW::Mechanize with SSL 可以工作,但响应很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26617065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com