简体   繁体   English

如何使Web Service报告过载?

[英]How to make Web Service report overload?

I am making a Web Service that implements a function that takes input parameters and stores them in database. 我正在制作一个Web服务,该服务实现了接受输入参数并将其存储在数据库中的功能。 (The code is in Java, written using NetBeans IDE, deployed on WebLogic server.) Something like this: (代码是用Java编写的,使用NetBeans IDE编写,并部署在WebLogic服务器上。)类似这样的东西:

@WebService
class DataSaver {
    void saveData( ...data... ) {
        ...
    }
}

It's already completed and it seems to work correctly, so now I am concerned about safety: 它已经完成并且似乎可以正常工作,所以现在我担心安全性:

What happens if too many clients would connect at the same time (or someone would do a Denial-of-Service attack on my site), so the server would not be able to correctly process all the requests? 如果太多客户端同时连接(或者有人会对我的站点进行拒绝服务攻击),那么服务器将无法正确处理所有请求,将会发生什么?

1) I would prefer if the server/application does not crash . 1)我希望服务器/应用程序不崩溃 What mechanisms are there to send away the request in case of overload? 有什么机制可以在过载的情况下发送请求? Are they enabled by default? 它们是否默认启用? If not, how do I turn them on? 如果没有,如何打开它们?

2) Since the web service function does not return a value (and I would prefer to keep its code as it is now, if possible), the clients can tell the difference between processed and unprocessed request only by HTTP error code. 2)由于Web服务功能不返回值(如果可能的话,我希望保留其代码,如果可能的话),客户端只能通过HTTP错误代码来区分已处理请求和未处理请求 So I would prefer the solution to return a HTTP error code in case of overload. 因此,我希望解决方案在过载的情况下返回HTTP错误代码。

I am not very familiar with Web Services and performance tuning (I am more of a theoretical programmer; algorithms and stuff), so I don't even know what to look for. 我对Web服务和性能调优不是很熟悉(我更是一个理论程序员;算法和东西),所以我什至不知道要寻找什么。 Solving this problem in Java seems to me too late -- when the message gets to my code, the XML request was already parsed. 在我看来,用Java解决这个问题似乎为时已晚-当消息到达我的代码时,XML请求已被解析。 I would expect some parameter in server configuration to handle this; 我希望服务器配置中的某些参数可以处理此问题; but I did not succeed to find it by Google or reading a WebLogic manual. 但是我没有成功通过Google找到它,也没有阅读WebLogic手册。 Perhaps I am using the wrong keywords, or I have a completely wrong idea how to approach this problem... which is why a partial answer could also be very useful. 也许我使用了错误的关键字,或者我对如何解决此问题有一个完全错误的想法……这就是为什么部分答案也可能非常有用的原因。

If you want to defend against DOS attacks then you can obtain software/hardware to do that. 如果您想防御DOS攻击,则可以获取软件/硬件来执行此操作。

If you want to do it in code then you could write you own javax.servlet.Filter. 如果要在代码中进行操作,则可以编写自己的javax.servlet.Filter。 You could simply keep a count of active requests and reply with HTTP 502 or whatever you require. 您只需保留一个活动请求计数,然后使用HTTP 502或您需要的任何内容进行回复。

As a general rule : don't code, use. 作为一般规则:不要编码,请使用。 It applies well for DoS attacks prevention, Wikipedia has a good list of Prevention and response checklist : 它非常适用于DoS攻击的预防,Wikipedia拥有很好的“ 预防和响应检查表”列表

  • Firewalls configuration 防火墙配置
  • Switches configuration 开关配置
  • Routers configuration 路由器配置
  • Application front end hardware 应用前端硬件
  • IPS based prevention 基于IPS的预防
  • DDS based defense systems 基于DDS的防御系统
  • Blackholing and sinkholing 黑洞和沉坑
  • Clean pipes 清洁管道

DoS prevention is a hard topic that must be tackled by security professionals (and you are not from what you say). 防止DoS是安全专家必须解决的一个硬问题(而且您的言论并非如此)。

If you are alone creating a small WebService for few clients, you don't even have to think to prevent DoS attacks as you're not likely to ever encounter such attack. 如果仅是为少数客户端创建一个小型WebService,您甚至不必考虑防止DoS攻击,因为您不太可能遇到这种攻击。

If the DoS prevention is something mandatory for you and for good reasons, then ask security professionals because you'll have to take into consideration the following types of DoS attacks : 如果出于对您有充分的理由对DoS预防是强制性的,那么请向安全专家询问,因为您必须考虑以下类型的DoS攻击:

  • ICMP flood ICMP洪水
  • SYN flood SYN洪水
  • Teardrop attacks 泪珠攻击
  • Low-rate Denial-of-Service attacks 低速率拒绝服务攻击
  • Peer-to-peer attacks 对等攻击
  • Asymmetry of resource utilization in starvation attacks 饥饿攻击中资源利用的不对称性
  • Permanent denial-of-service attacks 永久性拒绝服务攻击
  • Application-level floods 应用程序级洪水
  • Nuke 努克
  • RU-Dead-Yet? RU-Dead-Yet?
  • Distributed attack 分布式攻击
  • Reflected / Spoofed attack 反映/欺骗攻击
  • Unintentional denial of service 意外拒绝服务
  • Denial-of-Service Level II 拒绝服务级别II

Now if you just wish your legitimate users to be able to know if the service ran fine or failed, just use the classic behavior of your Web Server : if too many legitimate users happen to connect at the same time, then your code will fail with an Exception. 现在,如果您只是希望合法用户能够知道该服务是否运行良好或失败,请使用Web Server的经典行为:如果有太多合法用户同时连接,则您的代码将失败异常。 Your servlet server will then respond with a 503 HTTP error code . 然后,您的Servlet服务器将以503 HTTP错误代码响应。 This code will tell your users that something went wrong. 此代码将告诉您的用户出了点问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM