简体   繁体   English

处理大量HttpRequest的最有效方法

[英]Most efficient way to deal with Large Amount of HttpRequests

I have a fairly straight forward question, I'm going to be doing a lot of HTTP Requests to get an XML payload and I need to parse the payload and make some changes to a database. 我有一个很简单的问题,我将做很多HTTP请求来获取XML有效负载,并且我需要解析有效负载并对数据库进行一些更改。

I'm going to be doing these requests pretty frequently so any optimization will be good. 我将非常频繁地执行这些请求,因此任何优化都会很好。

I'm wondering if there is a more efficient way to do the requests as that will take the most amount of time. 我想知道是否有更有效的方法来执行请求,因为这将花费大量时间。 I'm writing this in Java, I use the SAXParser to parse the XML payload for the data that I need. 我使用Java编写此代码,我使用SAXParser解析XML负载以获取所需的数据。 I'm using the HttpURLConnection class for Http Requests and I just run a thread synchronized and wait for each request. 我正在对Http请求使用HttpURLConnection类,而我只是运行了一个同步线程并等待每个请求。 I've tried concurrently running the requests and I run into some issue's. 我尝试同时运行请求,但遇到了一些问题。 The computer I will be doing this on is very capable so it's not like I will be running into memory or processing issues. 我将要在其上进行操作的计算机功能非常强大,因此与我将要遇到的内存或处理问题不一样。 So my questions are: 所以我的问题是:

  1. Would it be more efficient to take a hash of the XML payload and store it in the DB or parse the XML and check the data manually? 对XML有效负载进行散列并将其存储在DB中或解析XML并手动检查数据会更有效吗?
  2. Is there a more efficient library for HttpRequests than HttpURLConnection? 是否有比HttpURLConnection更有效的HttpRequest库?
  3. Can any optimizations be made with threading the requests? 可以对请求进行线程优化吗?

Any insight is appreciated. 任何见解均表示赞赏。

Would it be more efficient to take a hash of the XML payload and store it in the DB or parse the XML and check the data manually? 对XML有效负载进行散列并将其存储在DB中或解析XML并手动检查数据会更有效吗?

Computing a hash for the XML payload will almost certainly be faster than parsing it. 计算XML有效负载的哈希值几乎肯定比解析它要快。 Thats a good way of detecting if you already have a payload that does not need to be re-parsed. 这是检测您是否已有不需要重新解析的有效负载的好方法。

Is there a more efficient library for HttpRequests than HttpURLConnection? 是否有比HttpURLConnection更有效的HttpRequest库?

Sure, use Apache HttpComponents . 当然,请使用Apache HttpComponents There are several ways to tune it for performance, as highlighted in this legacy but still relevant document . 有许多方法可以对其进行性能调整,如本旧版文档中仍然强调的那样。

Can any optimizations be made with threading the requests? 可以对请求进行线程优化吗?

As with all things thread related, this will depend on several factors including your hardware configuration (particularly your network hardware). 与所有与线程相关的事物一样,这将取决于几个因素,包括您的硬件配置(尤其是您的网络硬件)。 Theoretically you should gain some benefit from multithreading. 从理论上讲,你应该从多线程获得一些好处。 I would not make it the number one priority for tuning. 我不会将其作为调优的第一要务。

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

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