2
[root@ gwan]# file gwan 
gwan: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, stripped
[root@ gwan]# ldd gwan 
    not a dynamic executable

[root@ gwan]# du -csh gwan 
208K    gwan
208K    total

How does gwan do the magic?

As a web server, it needs to do socket programing and many other heavy jobs, which all require linking with libc, but that seems not the case with gwan. How is that possible?

blahdiblah
  • 33,069
  • 21
  • 98
  • 152
Je Rog
  • 5,675
  • 8
  • 39
  • 47

4 Answers4

5

As usual it is no magic, GWAN is packed with UPX to look smaller saving around 200kB. Unpacking it results the below.

 > ldd gwan
 linux-gate.so.1 =>  (0xf770c000)
 libpthread.so.0 => /usr/lib32/libpthread.so.0 (0xf76e9000)
 librt.so.1 => /usr/lib32/librt.so.1 (0xf76e0000)
 libdl.so.2 => /usr/lib32/libdl.so.2 (0xf76db000)
 libm.so.6 => /usr/lib32/libm.so.6 (0xf76b1000)
 libgcc_s.so.1 => /usr/lib32/libgcc_s.so.1 (0xf7695000)
 libc.so.6 => /usr/lib32/libc.so.6 (0xf752c000)
 /lib/ld-linux.so.2 (0xf770d000)
Lonewolfer
  • 51
  • 1
  • 1
2

Nginx

  • 0 native scripted language to generate dynamic contents
  • no extended native API
  • 2.7 MB footprint

G-WAN

  • 5 native scripted languages to generate dynamic contents
  • rich native API (JSON, GIF I/O, KV store, 2D frame buffer primitives, charts, email, compression, encryption, etc.)
  • < 1 MB footprint

Where the 'magic' resides seems to be a matter of taste rather than a matter of reason.

Borg
  • 31
  • 1
2

As it says in the file output, it's statically linked -- i.e., it has all the relevant code pulled out of the libraries and included in the executable. It's "hard-coded".

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186
  • Did you notice how small its size is? – Je Rog Jul 14 '11 at 12:40
  • 1
    @Je Rog: static linking isn't about embedding the whole library, rather only the used functions. – Blagovest Buyukliev Jul 14 '11 at 12:43
  • 208K seems like plenty, honestly, if you leave out the cruft. The PDP-7 that hosted the first UNIX system had a maximum RAM capacity of 144K. – Ernest Friedman-Hill Jul 14 '11 at 12:49
  • @Ernest Friedman-Hill ,is it function level or object level when static linking? – Je Rog Jul 14 '11 at 13:10
  • I believe the standard UNIX linker can only control things at the object level. But if you're going to link `libc` statically, then you could also be crazy enough to first modify `libc` for your own use. Maybe they modify the source to put each function in its own file? Maybe they have their own stripped-down `libc`? This kind of stuff might sound crazy nowadays; it wasn't really all that long ago when it was commonplace. – Ernest Friedman-Hill Jul 14 '11 at 13:22
  • @Ernest Friedman-Hill ,it's still only object level even when you're linking **statically**,right? – Je Rog Jul 14 '11 at 13:25
  • Yes, it is. Not sure what you're getting at though? – Ernest Friedman-Hill Jul 14 '11 at 13:28
  • I'm not getting any more about g-wan's internal,but it seems hard for us to get any further about g-wan right here,so I just accepted your answer . – Je Rog Jul 14 '11 at 13:39
1

Given the footprint of other application servers - most of them merely supporting one scripted language - there's definitely some "magic" at seeing G-WAN (150kB) supporting C, C++, Objective-C, D and Java.

G-WAN and the Linux 64-bit OpenJDK / SUN_JVM takes a mere 20 mB of RAM, after all the application examples are loaded.

They apparently watch memory usage closely since the memory footprint is logged in the gwan.log file at startup.

Vern
  • 11
  • 1