cli icon indicating copy to clipboard operation
cli copied to clipboard

Re-pushing war-file packaged app results in a large upload size

Open lhotari opened this issue 12 years ago • 24 comments

Large Grails applications might be using a lot of Java libraries that take a lot of storage space. The problem is that re-pushing a war-file without doing any changes causes a large upload each time. The expectation is that CF cli only transfers the files that have been modified.

In this example, the compressed size is about 60MB and the uncompressed size of the files in the war-file is about 89MB (6286 files). Re-pushing an unchanged app causes an 28.3MB upload.

This is the output from cf push when I re-push a war file:

Uploading grailsorg-dev...
Uploading app files from: /home/lari/grails-website/target/site-2.3.0.war
Uploading 28.3M, 6115 files
OK

You can reproduce the problem with grails-website Grails app (the opensource webapp that backs http://grails.org website).

Here the steps to reproduce the problem (the gist repo contains manifest.yml and war file):

git clone https://gist.github.com/150e5bc8bcf3b1f6275a.git grails-website-war
cd grails-website-war
cat manifest.yml
cf push

access to log files from my test runs:

git clone https://gist.github.com/65874d9306e922524a75.git grails-website-cf-trace-logs
cd grails-website-cf-trace-logs

or command output - cf push 2. time CF trace log - cf push 1. time CF trace log - cf push 2. time

lhotari avatar May 14 '14 13:05 lhotari

We have created an issue in Pivotal Tracker to manage this. You can view the current status of your issue at: https://www.pivotaltracker.com/story/show/71314456. This repo is managed by the 'CLI' team.

cf-gitbot avatar May 14 '14 13:05 cf-gitbot

@lhotari interesting, when I deploy a normal Spring application, I only need to redeploy a small amount of files. Most times between 2 - 5 MB, with an initial size of 94 MB.

jhiemer avatar May 14 '14 13:05 jhiemer

@jhiemer yes that's what you would expect. it's quite easy to reproduce the problem with the instructions I've provided.

lhotari avatar May 14 '14 14:05 lhotari

@lhotari just updating my environment to v171, and afterwards I will check it.

jhiemer avatar May 14 '14 14:05 jhiemer

(update: OFF TOPIC, please ignore this comment) btw. There is nice details of a rolling checksum algorithm in bup design doc . bup is a backup tool providing fast incremental saves and global deduplication. I wonder what kind of implementation CF go client is using? It would be possible to use similar technical solutions as bup has done, however bup has a LGPL license. bup uses a solution based on source code from librsync ("algorithm with what we call "rollsum," based on code in librsync. It's essentially the same as what rsync does, except we use a fixed window size.")

lhotari avatar May 14 '14 14:05 lhotari

@tjarratt @lcddave Could you comment on this?

Thanks, CF Community Pair (@stupakov, @mbhave)

stupakov avatar May 14 '14 20:05 stupakov

The go cli uses the file matching API that cloud controller provides. It's not great, but it is ... Useful.

I'm not entirely sure what this issue is about? Is this a bug? A discussion?

Sent From A Very Small Keyboard

On May 14, 2014, at 13:38, stupakov [email protected] wrote:

@tjarratt @lcddave Could you comment on this?

Thanks, CF Community Pair (@stupakov, @mbhave)

— Reply to this email directly or view it on GitHub.

tjarratt avatar May 14 '14 22:05 tjarratt

Are you pushing due to environment variable changes? In that case the diff would be nothing and nothing should be uploaded correct?

That might be an easier case to solve than delta file transfers.

The issue isn't just client side support for diff, but server side storage features that allow for processing deltas transfers.

lcddave avatar May 15 '14 00:05 lcddave

@tjarratt @lcddave Could you try reproducing the problem (there is instructions in the issue description) I'm seeing and decide if it's a bug or not? Please let me know if you cannot reproduce the problem with the instructions.

lhotari avatar May 15 '14 10:05 lhotari

@lcddave normally I'd do a change to the app and then push it, but in this problem report I wanted to make it more clear that even when you don't do any changes, it will upload about 30MB each time. Please try to reproduce it your self.

These are the instructions to reproduce the problem:

git clone https://gist.github.com/150e5bc8bcf3b1f6275a.git grails-website-war
cd grails-website-war
cat manifest.yml   # edit name etc. if that's required
cf push
cf push

lhotari avatar May 15 '14 10:05 lhotari

@tjarratt @lcddave Note too that this is a regression in behaviour. Cloud Foundry v1 had no problems ensuring that only the files that were changed in a WAR file were uploaded. The new versions of CF and the CLI do not handle this at all well it seems.

I believe that @nebhale tried to get this issue addressed as well, but faced some push back.

graemerocher avatar May 15 '14 10:05 graemerocher

There's a thread from 3 February 2013 that I'd be happy to provide (internally) that discusses this in detail. The short of it is that the matching API referenced by @tjarratt was modified some time back. To quote @MarkKropf in that email chain:

The existing resource matching endpoint can be removed/disabled without breaking v2 compatibility. Returning no matched files will always result in the client having to send all files up. This is what gcf is doing today, and should not break other clients.

This may have changed in the intervening months though.

nebhale avatar May 15 '14 11:05 nebhale

After poking about, I now think that some sort of de-duping is happening. Let's take a look at what's actually happening. According to the CLI, @lhotari's application is:

Uploading 28.3M, 6115 files

However, a test of the WAR itself tells us:

bhale-desktop master: ll site-2.3.0.war 
-rw-r--r--  1 bhale  staff    59M 15 May 12:35 site-2.3.0.war
bhale-desktop master: jar tf site-2.3.0.war | wc -l
    6286

That's a discrepancy of 30.7M and 171 files. If we examine the contents of the JAR, sorted by size, we find something interesting:

bhale-desktop master: jar tvf site-2.3.0.war | sort -n | tail -n 172
 64188 Fri May 09 15:06:06 BST 2014 img/page/light.png                            # 172nd smallest
 65261 Fri May 09 15:15:40 BST 2014 WEB-INF/lib/oro-2.0.8.jar                     # 171st smallest
 65707 Wed May 14 12:22:54 BST 2014 plugins/yui-2.8.2/js/yui/slider/slider.js     # 170th smallest

It would appear that there are about 171 files larger than 64K. I don't think that's a coincidence. As I remember, the de-duping algorithm used to have a size limit, under which, no hash would be calculated (because it would take longer to calculate it than to simply upload the file).

If this is the case, then it's disproportionally affecting Grails applications (and possibly all large Java applications) that have a ton of small files. It might be time to re-visit either the size limit (bringing it down to something smaller and avoiding more files) or the entire de-duping algorithm.

nebhale avatar May 15 '14 11:05 nebhale

I've been unable to reproduce the same behavior using our Play Framework test application:

Uploading 1.5M, 150 files

ZIP itself tells us:

bhale-desktop master: ll target/universal/play-application-1.0-SNAPSHOT.zip 
-rw-r--r--  1 bhale  staff    36M 15 May 12:57 target/universal/play-application-1.0-SNAPSHOT.zip
bhale-desktop master: unzip -l target/universal/play-application-1.0-SNAPSHOT.zip | wc -l
     198

That's a discrepancy of 34.5M and 48 files. Examining the contents of the ZIP, sorted by size, we find:

bhale-desktop master: unzip -l target/universal/play-application-1.0-SNAPSHOT.zip | sort -n | tail -n 55
    93435  05-15-14 12:56   play-application-1.0-SNAPSHOT/share/doc/api//lib/jquery.js
    98578  05-01-14 01:33   play-application-1.0-SNAPSHOT/lib/com.typesafe.play.play-java_2.10-2.2.3.jar
   102696  05-01-14 01:33   play-application-1.0-SNAPSHOT/lib/org.reflections.reflections-0.9.8.jar
   107063  04-24-14 12:19   play-application-1.0-SNAPSHOT/lib/org.apache.commons.commons-pool2-2.0.jar
   110600  05-01-14 01:33   play-application-1.0-SNAPSHOT/lib/com.jolbox.bonecp-0.8.0.RELEASE.jar

That sends me back to the drawing board. :confused:

nebhale avatar May 15 '14 12:05 nebhale

And on the other hand, I was able to reproduce the behavior using our Grails test application:

Uploading 1.5M, 124 files

A test of the WAR itself tells us:

bhale-desktop master: ll target/grails-application-0.1.war 
-rw-r--r--  1 bhale  staff    27M 15 May 13:10 target/grails-application-0.1.war
bhale-desktop master: jar tf target/grails-application-0.1.war | wc -l
     187

The discrepancy is 25.5M and 63 files. Examining the contents, sorted by zip, we find:

bhale-desktop master: jar tvf target/grails-application-0.1.war | sort -n | tail -n 63
 61709 Wed May 07 14:43:06 BST 2014 WEB-INF/lib/grails-plugin-async-2.3.8.jar
 62050 Thu May 01 13:56:04 BST 2014 WEB-INF/lib/commons-logging-1.1.3.jar
 65261 Thu Apr 24 11:21:20 BST 2014 WEB-INF/lib/oro-2.0.8.jar
 69002 Tue May 06 10:02:18 BST 2014 WEB-INF/lib/commons-fileupload-1.3.1.jar
 76806 Wed May 07 14:43:06 BST 2014 WEB-INF/lib/grails-async-2.3.8.jar

That seems to corroborate the 64K theory.

nebhale avatar May 15 '14 12:05 nebhale

I would like to nominate @nebhale as a hero for identifying the source of this problem so well. From my perspective, it's been a known issue for some time that apps with a disproportionate number of small files cannot take advantage of the resource matching API as well as apps with larger files.

From what I recall, the threshold where Cloud Controller will determine whether or not to cache a file is configurable in the bosh manifest, and the gcf cli will always send up the SHA1 sum for each file. After talking to some people on the CC team, we confirmed that this is the correct way to use this API. I looked around for official docs on the resource matching API but couldn't find any.

I've created a story in the CC pivotal tracker to follow up on this and explore new algorithms for resource matching that will aid apps with smaller files.

tjarratt avatar May 16 '14 01:05 tjarratt

To reconsider if CC API improves for this.

lcddave avatar May 16 '14 01:05 lcddave

@lcddave Why has the issue been closed? Surely it should be left open until the problem is fixed by whatever changes are necessary in Cloud Controller? By closing it it is just likely to be forgotten

@tjarratt The link to the story on CC pivotal tracker returns a 404. Please correct it.

graemerocher avatar May 16 '14 06:05 graemerocher

Fixed the link to the runtime tracker. Sorry about that.

My understanding is that the CLI is using the v2 API correctly, as it's defined. I agree with you that we should improve resource matching so that apps with small files can benefit as much as apps with large files (this seems like it would benefit everyone, realistically), but I don't think there's anything we can do to change the v2 resource matching API. In order to improve this we would really need to make a new resource matching api, which would either require

  • changing the CC API to v3.
  • implementing an alternative resource matching API alongside the current one in a minor version bump

Having followed CC changes for a few months now and implemented some code in the CLI that makes backwards compatible requests... I'm not really thrilled about the prospect of the latter. The former choice is likely in the not-too-distant future; it's convenient to close this issue until such a point in time when the CLI could take advantage of a new API. There's a cost associated with keeping issues open because it increases the number of issues we track and makes it difficult to ensure we aren't ignoring the things that matter.

Just to be clear, I'm very sympathetic to this issue. I agree it's terrible. I don't think keeping this issue open on the CLI is going to help make progress on it in the near future (e.g.: one to two months). I am but a mere mortal and am often wrong though...

tjarratt avatar May 16 '14 06:05 tjarratt

@graemerocher You've raised a valid point... I've merely closed it as a won't fix for now. Rather than have a long list of issues which can't be effectively tracked, I'm working towards keeping this list current and active.

Should things change, I would be glad for a reminder that the CC has enabled a better UX.

lcddave avatar May 16 '14 08:05 lcddave