Finding X11 round-trips

X11 is the protocol that is used for displaying windows on all Linux and Unix-like systems. For talking to an X11 server, there are two libraries: Xlib and XCB.

XCB was designed to support "latency-hiding". In X11 there are two kinds of requests that a client can send to the X server. Those that cause a reply from the server and those that don't (All of them can cause errors, let's ignore those for now). Since X11 can be used over the internet, waiting for a reply can take some time. "Latency-hiding" now means that one can send multiple requests at once and doesn't have to wait for the replies. The "Basic XCB notions" section in this document gives some examples on this. Xlib one cannot do something like this.

But just because XCB supports this, stuff doesn't magically get faster. The application that uses XCB has to be written with this in mind. But how does one measure how bad your code behaves? My idea here was to write a program that accepts the TCP connection and forwards everything to the X11 server, but adding some latency. This means that one can simulate how much this latency hurts. Together with xtrace's "--relative-timestamps" one can now take a closer look at which requests are hurt by this latency.

With these tools, I analyzed awesome's behavior. For example, this is xtrace's output while awesome determines the number and geometry of the available monitors (my "latency" program was set to delay the data transfer by 0.5 secs, that means the round-trip time was one second):

2.107 000:<:0046: 16: Request(98): QueryExtension name='RANDR'
2.610 000:>:0046:32: Reply to QueryExtension: present=true(0x01) major-opcode=144 first-event=91 first-error=148
2.610 000:<:0047: 12: RANDR-Request(144,0): QueryVersion major-version=1 minor-version=1
3.113 000:>:0047:32: Reply to QueryVersion: major-version=1 minor-version=1
3.113 000:<:0048:  8: RANDR-Request(144,8): GetScreenResources window=0x00000111
3.620 000:>:0048:676: Reply to GetScreenResources: timestamp=0x010f89c5 config-timestamp=0x010fc55c [...]
3.659 000:<:0049: 16: Request(98): QueryExtension name='XINERAMA'
4.165 000:>:0049:32: Reply to QueryExtension: present=true(0x01) major-opcode=145 first-event=0 first-error=0
4.165 000:<:004a:  4: XINERAMA-Request(145,4): IsActive 
4.669 000:>:004a:32: Reply to IsActive: state=true(0x00000001)
4.669 000:<:004b:  4: XINERAMA-Request(145,5): QueryScreens 
5.173 000:>:004b:40: Reply to QueryScreens: screens={x=0 y=0 width=1500 height=500};

How does one read xtrace's output? Let's take a closer look at the first line:
2.107 000:<:0046: 16: Request(98): QueryExtension name='RANDR' 2.107 seconds after connecting to the X server (this is the output from --relative-timestamps) the client number "000" sent a request to the X server ("<") with the sequence number "0046" (The sequence number is increased with each new request, the first request gets the sequence number 1). This request was awesome asking for the extension 'RANDR'. As one sees from the output, awesome waits after each request for the reply before continuing.

To speed this up, something had to be done. XCB wants to provide latency-hiding, so there has to be a way to do this. A quick look at the docs finds a function called "xcb_prefetch_extension_data()". This function sends the QueryExtension request without waiting for the reply.

This resulted in a patch for awesome that prefetches the needed extensions and moves some stuff later places, so that we don't have to wait for the reply any more.

Written: 7. 8. 2010
Last modified: 8. 8. 2010

Upgrading to KDE 4.4

I'm not using many KDE apps. I only really use akregator (and rarely okular). However, since today this changed. KDE 4.4 hit debian testing and this one would eat lots of my precious disk space because it pulls in mysql (60 MiB) and kdoctools (11 MiB).

I'm 100% sure I will never need either of them and so I decided to bite the bullet and use some other feed reader. liferea won for now. It doesn't seem to be as easily controllable via the keyboard as akregator, but thanks to a blog post I found I can work with it.

Oh and btw, uninstalling all of this kde stuff freed 143 MiB disk space. Edit: After the first run of uninstalls, aptitude found another 61.2 MiB it feels like getting rid of (e.g. phonon).

Written: 19. 5. 2010

Hacking Google (accidentally!)

I was watching some video on google video today when I noticed this:

How did this happen? Actually, I don't have any idea. What I do know is that I visited this guy's youtube profile before this and it told me to "customize my channel". I didn't think anything about back then, but now I do think that this was because I already were logged in as him.

Now that I knew something was going I started to collect evidence. Google Mail, Google Calender and Picasa Web didn't let me in (asking for "my" password), but below are some screenshots of pages which show me being logged in. Browser is uzbl-0.0.0~git.20100403-1 from debian testing. My current cookies for google and youtube look like this.

Written: 3. 5. 2010

Iceland 2010

Chuck Norris begins the grilling season:
Vulcano erruption

Written: 25. 4. 2010

The Joy of Closed Source Software

Today, I found the following blog post: http://extendedsubset.com/?p=30.

Now I wonder how much more fun this would be if we could look at the source code that actually did this. :>

Written: 21. 4. 2010

Opting out

How many ad networks gave your browser a cookie? How much do they know about you? hat can you do to stop them?

I don't know everything, but you can Opt-out on the tracking cookies which sounds definitely like a good idea.
Do it. Now!

Written: 14. 2. 2010

Happy chritmas

To all of the three readers I might have:

Happy Christmas and a wonderful new year!

Written: 24. 12. 2009

Election

Tomorrow there is an important election in Germany. Many people write about it, but this one is my favorite so far.

Written: 26. 9. 2009

The BEFH

You know the BOFH?
Well, today I met the BEFH (Bastard Electrician From Hell). During a presentation (15 people trying to listen to the speaker's explanations) the projector died. Multiple times.

It turned out to be some electrician who "accidentally" triggered the RCD. Well, this sounds boring, but this turned out to be one of the presentation's highlights. ;) So know you must not only fear the network administrator, but also the electrician, the cleaners, the guy with the saw who "prepared" your chair, the.......

Written: 31. 8. 2009

To fork or not to fork

Forks are evil and should be avoided as much as possible, correct?

Well, there is this lua mpd library which obvious uses. Since there are more lua mpd libraries than there is sand at the sea, I got my own one, too. I thought mine was better than the one that obvious was using and thus I proposed to use mine instead.

Shortly afterwards the author of the upstream version showed up and basically told me I suck. Well, he is right.

Forking is bad. It means that now two people are doing the same work twice, having to fix every bug twice and having to add features. It's way better to continue to use upstream's version since then someone else does the maintaining work for you.

Before you fork something, make sure that upstream is really unresponsive or doesn't like your patches. Then do the same again, really!.

Written: 24. 8. 2009