为什么我收到响应代码:非 HTTP 响应代码:java.net.SocketException? [英] Why am I receiving Response code: Non HTTP response code: java.net.SocketException?

查看:34
本文介绍了为什么我收到响应代码:非 HTTP 响应代码:java.net.SocketException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 JMeter 向我在 localhost 上运行的应用程序发送请求,但由于 java.net.SocketException,许多请求都失败了.不过,我在控制台中没有看到任何异常.

I am trying to send requests using JMeter to my application that is running on localhost but many of the requests get failed due to java.net.SocketException. I do not see any exceptions in console though.

我阅读了这些 question1question2 但没有太大帮助.

I read these question1 and question2 but did not help much.

我的代码如下:

 try {
        return myService.findItems(group);

    } catch (NullPointerException n) {
        n.printStackTrace();
    } catch (HibernateException h) {
        h.printStackTrace();
    } catch (IOException i) {
        i.printStackTrace();
    }
    return null;

存储库

  public LinkedHashMap findItems(String group) throws NullPointerException, HibernateException, IOException {
        Session session = sessionFactory.getCurrentSession();
                 ..... //request is sent to database

        return items;
    }

我的 JMeter 配置的屏幕截图

推荐答案

从你提供的截图来看,我认为你要么认为你的系统/本地主机是超级计算机,要么你错误地配置了 jmeter 设置.

From Screenshots you provided, I think either you thought your system/localhost as super computer or you have mis-configured the jmeter settings.

屏幕截图显示,10000 个用户/线程将在 1 秒内启动,这对于在本地主机上运行的应用程序来说是完全不真实的.仅 Jmeter 会占用大部分 CPU、内存,即系统资源.

Screenshot shows, 10000 users/threads will start in 1 second which is completely unreal for application running on a localhost. Jmeter alone will eat most CPU, memory i.e. system resources.

如果您的 Jmeter 正在吃掉所有资源,您的应用程序将获得任何资源(简单的答案是否定的)因此应用程序将关闭,您将开始收到超时错误或套接字异常.

If your Jmeter is eating all resources will your application will get anything (Simple answer is NO) Thus application will go down and you will start getting timeout errors or socket exceptions.

如果你在 diff 机器上有 jmeter 和应用程序,那么在 1 秒内仍然有 10000 个用户对于普通应用程序来说是非常高的负载,很明显你会遇到这样的错误.尝试使用给定硬件的应用程序预期的实际负载运行测试.可能在 1 秒内有 100 个用户,并逐渐将其增加到预期值.

If you have jmeter and application on diff machines then still 10000 users in 1 second is very high load for a normal application and it is obvious that you will face such errors. Try running test with realistic load that is expected for your application with given hw. Maybe 100 users in 1 second and gradually increase them to expected value.

我希望你现在明白了:)

I hope you understood it now :)

这篇关于为什么我收到响应代码:非 HTTP 响应代码:java.net.SocketException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆