Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TiDB in Webassembly crashes in some mobile browsers #13322

Closed
5kbpers opened this issue Nov 10, 2019 · 19 comments
Closed

TiDB in Webassembly crashes in some mobile browsers #13322

5kbpers opened this issue Nov 10, 2019 · 19 comments
Labels
component/wasm help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/bug The issue is confirmed as a bug.

Comments

@5kbpers
Copy link
Contributor

5kbpers commented Nov 10, 2019

Bug Report

TiDB in Webassembly(#13069) always gets stuck and even crash in some mobile browsers(iOS Safari, Android Chrome, etc.).
In my iOS13.2:
image

@5kbpers 5kbpers added type/bug The issue is confirmed as a bug. component/wasm help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Nov 10, 2019
@5kbpers
Copy link
Contributor Author

5kbpers commented Nov 10, 2019

Seems in Go1.12, the runtime will allocate 1GB initial memory (see golang/go#27462). So I tried with Go1.13 and set initialSize to 64MB(see golang/go#34395), the initial memory finally changed to about 100MB, but it still cannot work in iOS Safari(see the error above).

@siddontang
Copy link
Member

@5kbpers you also adjust the mac proc number to 1, and it still can't work on mobile phone, right?

@siddontang
Copy link
Member

do you have any idea? @syrusakbary

@siddontang
Copy link
Member

Use https://github.com/rustwasm/twiggy, I find most of the size is occupied by the data section, but I have no idea which static var uses so large size.

twiggy top -n 10 main.css
 Shallow Bytes │ Shallow % │ Item
───────────────┼───────────┼────────────────────────────────────────
      14461356 ┊    18.59% ┊ data[99993]
      10291671 ┊    13.23% ┊ data[99997]
       4152701 ┊     5.34% ┊ data[99998]
       2861120 ┊     3.68% ┊ "function names" subsection
        999248 ┊     1.28% ┊ github.com_pingcap_parser.yyParse
        528491 ┊     0.68% ┊ data[43154]
        401922 ┊     0.52% ┊ data[99999]

@siddontang
Copy link
Member

Through wasm-objdump -j data -x main.css, I find the data section 99997 is below, still hard to know the data.

- segment[99997] size=10291660 - init i32=22910259
  - 15d9533: 1000 0000 00f0 920b 0000 0000 0000 0001  ................
  - 15d9543: 1000 0000 0028 930b 0000 0000 0000 0002  .....(..........
  - 15d9553: 1000 0000 0050 940b 0000 0000 0000 0003  .....P..........
  - 15d9563: 1000 0000 00b8 940b 0000 0000 0000 0004  ................
  - 15d9573: 1000 0000 0010 950b 0000 0000 0000 0005  ................
  - 15d9583: 1000 0000 0060 950b 0000 0000 0000 0006  .....`..........
  - 15d9593: 1000 0000 00d0 950b 0000 0000 0000 0007  ................
  - 15d95a3: 1000 0000 0028 960b 0000 0000 0000 0008  .....(..........
  - 15d95b3: 1000 0000 00a0 960b 0000 0000 0000 0009  ................
  - 15d95c3: 1000 0000 0018 970b 0000 0000 0000 000a  ................
  - 15d95d3: 1000 0000 0070 970b 0000 0000 0000 000b  .....p..........
  - 15d95e3: 1000 0000 00c8 970b 0000 0000 0000 000c  ................

@lucklove
Copy link
Member

lucklove commented Nov 14, 2019

image
The expression module take too much place

@siddontang
Copy link
Member

@siddontang
Copy link
Member

I am so surprised that Wasm needs some dependencies like etcdserverpb, debugpb, etc. IMO, if we only use a standalone TiDB, we should not depend on these.

I think we need to refactor the code now.

@siddontang
Copy link
Member

We should remove the etcd and TiKV dependence when we only use a standalone TiDB.
PTAL @winkyao

@lucklove
Copy link
Member

lucklove commented Dec 2, 2019

I have tested with a large binary generated the following code:

package main

import (
        "fmt"
        "syscall/js"
)

func main() {
        fmt.Println(len(xs))
        js.Global().Get("document").Call("write", "Hello, world")
}

var xs []int = []int{
        0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
        0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
        0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
        // many lines copy and paste from above
}

It can work in phone browser when the binary is 170MB. So I think it's not related to the bianry size.

And I execute download, compilation, and initialization operations independently. I found that when I try to compile tidb's binary, the phone browser crashes, and the adb message is:
5091574857149_ pic_hd
It seems the chrome run out of memory when compile WebAssembly binary code.

@lucklove
Copy link
Member

lucklove commented Dec 3, 2019

BTW, the firefox works well:
Screenshot_20191203_133743_org mozilla firefox
And the chrome will crash:
屏幕快照 2019-11-28 下午1 43 06

@lucklove
Copy link
Member

lucklove commented Jan 8, 2020

Closing this issue since there is no good way to solve chrome crashing. If there is any opportunity we can reopen this again.

@lucklove lucklove closed this as completed Jan 8, 2020
@frank-dspeed
Copy link

via the graalvm language research framework i found out that compiling stuff with a lot of so called Nodes where every function call is a node causes such problems.

there is at present a magic number of 40 000 nodes that can safe get compiled

@lucklove
Copy link
Member

@frank-dspeed Thanks for letting us know this! And do you know is there any good way to work around this? We have been plagued by this problem all the time.

@frank-dspeed
Copy link

@lucklove splitting it up into independent wasm is the way to go and then reuse them

@frank-dspeed
Copy link

frank-dspeed commented Mar 20, 2020

wasm needs an overall more modular coding style and mindset you will never want to compile an application to wasm you want to support all functions of the application as wasm so you can, for example, include them inside node.js + wasi to have a high-level language to use them and do efficient prototyping.

this will also lead to being so modular that we can improve even a single sorting algo via replacing a single wasm in the stack.

@frank-dspeed
Copy link

frank-dspeed commented Mar 20, 2020

I have for example at present the idea to expose many data structures as wasm and a way to access them so you can create them like objects with a fixed size and operate efficiently on them.

others are going the same way already https://unpkg.com/browse/[email protected]/merkle_tree_wasm.js

I would code more of the interface inside the wasm and expose a more friendly API but this shows where it goes.

I am also looking only for that into tikv and tidb i want to make the functionality useable as was modules so that I can do coprocessing on the data where the data is :) my response to universal grid computing my research showed that this is the best we can archive today.

i want feature parity with apache ignite inside the wasm universe :)

@Zireael07
Copy link

The parent issue to this was closed as frozen. This one is also closed, but without any info whether it's still an issue or not?

@frank-dspeed
Copy link

@Zireael07 it is a issue that can not get fixed lets call it upstream issues nothing can be done at present inside here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/wasm help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

5 participants