[Spice-devel] [master PATCH 2/2] server: netstat: send random data not zeros

Yaniv Kaul ykaul at redhat.com
Tue Oct 18 14:50:37 PDT 2011


On 18/10/2011 19:20, Uri Lublin wrote:
> WAN accelerators may compress the zeros which results with a
> wrong bandwidth calculation.

Is this really the right approach? Why not calculate the latency based 
on the time it takes to send the first image?
That image is not using the WAN feature anyway, regardless of its being 
set or not.
A waste of 256K, and possibly several seconds on WAN. Hundreds of 
packets, for sure.
Y.

>
> The buffer is initialized once.
> ---
>   server/main_channel.c |   32 ++++++++++++++++++++++++++++----
>   1 files changed, 28 insertions(+), 4 deletions(-)
>
> diff --git a/server/main_channel.c b/server/main_channel.c
> index a4db724..3a94066 100644
> --- a/server/main_channel.c
> +++ b/server/main_channel.c
> @@ -34,6 +34,7 @@
>   #include<fcntl.h>
>   #include<errno.h>
>   #include<ctype.h>
> +#include<stdlib.h>
>
>   #include "server/red_common.h"
>   #include "server/demarshallers.h"
> @@ -44,7 +45,7 @@
>   #include "red_channel.h"
>   #include "generated_marshallers.h"
>
> -#define ZERO_BUF_SIZE 4096
> +#define RANDOM_BUF_SIZE 4096
>
>   // approximate max receive message size for main channel
>   #define RECEIVE_BUF_SIZE \
> @@ -57,7 +58,7 @@
>
>   #define PING_INTERVAL (1000 * 10)
>
> -static uint8_t zero_page[ZERO_BUF_SIZE] = {0};
> +static uint8_t random_page[RANDOM_BUF_SIZE];
>
>   typedef struct RedsOutItem RedsOutItem;
>   struct RedsOutItem {
> @@ -155,6 +156,28 @@ enum NetTestStage {
>       NET_TEST_STAGE_RATE,
>   };
>
> +
> +static void random_page_init(void)
> +{
> +    static int done = 0; /* do it only once */
> +    int i, n;
> +    uint32_t *p = (uint32_t*)random_page;
> +
> +    if (done)
> +        return;
> +    done = 1;
> +
> +    /* assuming devides with no remainder. otherwise some zeros at the end */
> +    n = sizeof(random_page) / sizeof(uint32_t);
> +
> +    srandom(time(NULL));
> +    for (i=0; i<n; i++, p++) {
> +        *p = random();
> +    }
> +
> +}
> +
> +
>   int main_channel_is_connected(MainChannel *main_chan)
>   {
>       return red_channel_is_connected(&main_chan->base);
> @@ -370,9 +393,9 @@ static void main_channel_marshall_ping(SpiceMarshaller *m, int size, int ping_id
>       spice_marshall_msg_ping(m,&ping);
>
>       while (size>  0) {
> -        int now = MIN(ZERO_BUF_SIZE, size);
> +        int now = MIN(RANDOM_BUF_SIZE, size);
>           size -= now;
> -        spice_marshaller_add_ref(m, zero_page, now);
> +        spice_marshaller_add_ref(m, random_page, now);
>       }
>   }
>
> @@ -982,6 +1005,7 @@ MainChannel* main_channel_init(void)
>       RedChannel *channel;
>       ChannelCbs channel_cbs;
>
> +    random_page_init();
>
>       channel_cbs.config_socket = main_channel_config_socket;
>       channel_cbs.on_disconnect = main_channel_client_on_disconnect;



More information about the Spice-devel mailing list