How to get the XML document size

Source: Internet
Author: User

Are the XML documents determined from the format to the size. Some may have only a few lines, but some may have several megabytes. You may wonder if you need to know the XML document size. When performance becomes the primary issue, knowing the XML document size is a must.

From a performance perspective, there are two types of methods to process XML documents. Batch processing takes a short time to parse documents in groups. The real-time method is to process documents in real time. The performance of the batch processing method can be measured by the number of documents processed within a certain period of time, and the performance of the real-time mode also adopts a similar measurement method, however, it takes time to process a document.

Scenarios scenario
Imagine that you have a real-time working system, such as a web server. The system needs to receive orders from customers in real time and respond to the orders immediately.

This system obviously cannot be processed in batches. In a simple estimation, assume that this is a very simple order with only 10 projects. In this way, the generated XML document is relatively small, and each document is about 4 kb. In this case, use Dom to parse the received document.

If your order is only a few hours, the system performance is not a problem for you. However, in the long run, the number of orders will increase one day to make you realize that the system performance must be improved.

Now you are considering improving the performance to adapt to the increasing load. Your order documents are very small, and it makes no practical sense to combine them into large documents. From the vertical perspective, you can improve the processing capability of the existing system. From the horizontal perspective, you can increase more systems to distribute load.

Let's look at another completely different field. What you want to deal with now is a large data warehouse. Unlike the web server, you now use ftp to transmit XML documents with an average size of MB. If you still use Dom to parse XML documents, you will soon be in serious trouble. On the contrary, it will be much better if you use SAX. It can directly parse the inbound XML documents without loading them into the memory beforehand.

Change document size
Sometimes you may need to change the XML document size in special circumstances. Imagine that you have a web server that processes XML documents in real time, and all documents are MB instead of 4 kb in size. You cannot use Dom, because it occupies too much memory. However, because this is a real-time system, the performance is very important. You can use SAX, but it takes time to allow and have a powerful processor.

In this case, you can change the document size to improve the system performance. For example, you can divide a MB document into 10 40 MB or 40 10 MB small documents, which is more efficient than processing a MB document. In this way, you can use the DOM method to read files into the memory for processing and respond to the requests of each document in a timely manner. You can also clear irrelevant documents.

This is also true for batch processing. Imagine that you are processing thousands of 4 kb documents in Dom batch processing. The best way is to combine the one thousand files into a 4 MB file. Because the loading of each document takes the system time (Dom or SAX ). By combining one thousand documents into one file, you only need to load one file, which takes only 1‰ of the original time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.