Absolute fastest way to transmit tabular data out of SQL over HTTP using WebHttpBinding
What would be the fastest way to transmit SQL tabular data over HTTP using WCF endpoints?
Right now I am querying Entity Framework with ESQL and then serializing the DataTable result into a byte[] and just sending that over, then deserializing on the other end, which seems slow. Right now the size of the serialized data is coming to about 4000 bytes for 15000+ rows. I also experimented with OData Services but that was also rather slow.
In contrast to JSON, which I would think would be the fastest - a JSON file that contains only 1048 SQL rows is coming up as almost 200000 bytes. Is there any direct correlation between the size of the data and how fast it will transfer over HTTP? (seems intuitive, but I'm not positive).
What would be the fastest format? I am thinking of going with SQLDataReader to JSON and send 开发者_运维技巧the JSON over, which I would think should perform well but I'm not sure. This would be for data synchronization purposes only.
Thanks.
EDIT Did some more tracing, looks like some of my initial measurements were wrong. See below the respective methods in milliseconds.
6:42:23 PM Monday, July 11, 2011 : :Function 'Deserialize' duration. Elapsed: 481 ms
6:42:23 PM Monday, July 11, 2011 : :Function 'HttpRequest' duration. Elapsed: 4776 ms
6:42:22 PM Monday, July 11, 2011 : :DataTable Length (Bytes) = 13047247 bytes
The DataTable referenced above contained ~7000 rows, seems steep, right?
The SqlDataReader is the fastest method for getting data out of the database, yes. The trouble you're going to have then is that you're going to need to assemble your result in full before sending it out over HTTP. You cannot just stream the result as it's read from the database. JSON is a reasonably tight way of representing data, but since you'll have to repeat the column names over and over, you'd be much better off with a simple plain text tab separated value file. Set you Content-type = text/plain and scrub any tabs out of your data when you get it from the SqlDataReader. You might also want to consider gzipping your result - depending on the speed of your network vs your web server's processing power.
-- EDIT --
As Sean rightly pointed out, the plain text option isn't a WCF solution.
精彩评论