Code Monkey home page Code Monkey logo

snowflake's Introduction

snowflake

GoDoc Go report Coverage Build Status Discord Gophers

snowflake is a Go package that provides

  • A very simple Twitter snowflake generator.
  • Methods to parse existing snowflake IDs.
  • Methods to convert a snowflake ID into several other data types and back.
  • JSON Marshal/Unmarshal functions to easily use snowflake IDs within a JSON API.
  • Monotonic Clock calculations protect from clock drift.

For help with this package or general Go discussion, please join the Discord Gophers chat server.

Status

This package should be considered stable and completed. Any additions in the future will strongly avoid API changes to existing functions.

ID Format

By default, the ID format follows the original Twitter snowflake format.

  • The ID as a whole is a 63 bit integer stored in an int64
  • 41 bits are used to store a timestamp with millisecond precision, using a custom epoch.
  • 10 bits are used to store a node id - a range from 0 through 1023.
  • 12 bits are used to store a sequence number - a range from 0 through 4095.

Custom Format

You can alter the number of bits used for the node id and step number (sequence) by setting the snowflake.NodeBits and snowflake.StepBits values. Remember that There is a maximum of 22 bits available that can be shared between these two values. You do not have to use all 22 bits.

Custom Epoch

By default this package uses the Twitter Epoch of 1288834974657 or Nov 04 2010 01:42:54. You can set your own epoch value by setting snowflake.Epoch to a time in milliseconds to use as the epoch.

Custom Notes

When setting custom epoch or bit values you need to set them prior to calling any functions on the snowflake package, including NewNode(). Otherwise the custom values you set will not be applied correctly.

How it Works.

Each time you generate an ID, it works, like this.

  • A timestamp with millisecond precision is stored using 41 bits of the ID.
  • Then the NodeID is added in subsequent bits.
  • Then the Sequence Number is added, starting at 0 and incrementing for each ID generated in the same millisecond. If you generate enough IDs in the same millisecond that the sequence would roll over or overfill then the generate function will pause until the next millisecond.

The default Twitter format shown below.

+--------------------------------------------------------------------------+
| 1 Bit Unused | 41 Bit Timestamp |  10 Bit NodeID  |   12 Bit Sequence ID |
+--------------------------------------------------------------------------+

Using the default settings, this allows for 4096 unique IDs to be generated every millisecond, per Node ID.

Getting Started

Installing

This assumes you already have a working Go environment, if not please see this page first.

go get github.com/bwmarrin/snowflake

Usage

Import the package into your project then construct a new snowflake Node using a unique node number. The default settings permit a node number range from 0 to 1023. If you have set a custom NodeBits value, you will need to calculate what your node number range will be. With the node object call the Generate() method to generate and return a unique snowflake ID.

Keep in mind that each node you create must have a unique node number, even across multiple servers. If you do not keep node numbers unique the generator cannot guarantee unique IDs across all nodes.

Example Program:

package main

import (
	"fmt"

	"github.com/bwmarrin/snowflake"
)

func main() {

	// Create a new Node with a Node number of 1
	node, err := snowflake.NewNode(1)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Generate a snowflake ID.
	id := node.Generate()

	// Print out the ID in a few different ways.
	fmt.Printf("Int64  ID: %d\n", id)
	fmt.Printf("String ID: %s\n", id)
	fmt.Printf("Base2  ID: %s\n", id.Base2())
	fmt.Printf("Base64 ID: %s\n", id.Base64())

	// Print out the ID's timestamp
	fmt.Printf("ID Time  : %d\n", id.Time())

	// Print out the ID's node number
	fmt.Printf("ID Node  : %d\n", id.Node())

	// Print out the ID's sequence number
	fmt.Printf("ID Step  : %d\n", id.Step())

  // Generate and print, all in one.
  fmt.Printf("ID       : %d\n", node.Generate().Int64())
}

Performance

With default settings, this snowflake generator should be sufficiently fast enough on most systems to generate 4096 unique ID's per millisecond. This is the maximum that the snowflake ID format supports. That is, around 243-244 nanoseconds per operation.

Since the snowflake generator is single threaded the primary limitation will be the maximum speed of a single processor on your system.

To benchmark the generator on your system run the following command inside the snowflake package directory.

go test -run=^$ -bench=.

If your curious, check out this commit that shows benchmarks that compare a few different ways of implementing a snowflake generator in Go.

snowflake's People

Contributors

bwmarrin avatar carsonslovoka avatar codemedic avatar connor4312 avatar foobar2016 avatar ninerec avatar nishaad78 avatar szpnygo avatar yapcheekian avatar zerozshadow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

snowflake's Issues

Why DEPRECATED for func Time?

Why DEPRECATED for func Time?

// Time returns an int64 unix timestamp in milliseconds of the snowflake ID time
// DEPRECATED: the below function will be removed in a future release.
func (f ID) Time() int64 {
	return (int64(f) >> timeShift) + Epoch
}

got repeated id

hi,

i've tested with my laptop on window7, call the function test_id in example for several times,

test_id()

// time.Sleep(1)
test_id()
// time.Sleep(1)
test_id()
// time.Sleep(1)
test_id()
// time.Sleep(1)
test_id()
// time.Sleep(1)

and got
======log==============
Int64 ID: 890399407000784896
String ID: 890399407000784896
Base2 ID: 110001011011010101011000101100001010100000000001000000000000
Base64 ID: ODkwMzk5NDA3MDAwNzg0ODk2
ID Time : 1501122736107
ID Node : 1
ID Step : 0
ID : 890399407000784897
Int64 ID: 890399407000784896
String ID: 890399407000784896
Base2 ID: 110001011011010101011000101100001010100000000001000000000000
Base64 ID: ODkwMzk5NDA3MDAwNzg0ODk2
ID Time : 1501122736107
ID Node : 1
ID Step : 0
ID : 890399407000784897
Int64 ID: 890399407000784896
String ID: 890399407000784896
Base2 ID: 110001011011010101011000101100001010100000000001000000000000
Base64 ID: ODkwMzk5NDA3MDAwNzg0ODk2
ID Time : 1501122736107
ID Node : 1
ID Step : 0
ID : 890399407000784897
Int64 ID: 890399407000784896
String ID: 890399407000784896
Base2 ID: 110001011011010101011000101100001010100000000001000000000000
Base64 ID: ODkwMzk5NDA3MDAwNzg0ODk2
ID Time : 1501122736107
ID Node : 1
ID Step : 0
ID : 890399407000784897
Int64 ID: 890399407000784896
String ID: 890399407000784896
Base2 ID: 110001011011010101011000101100001010100000000001000000000000
Base64 ID: ODkwMzk5NDA3MDAwNzg0ODk2
ID Time : 1501122736107
ID Node : 1
ID Step : 0
ID : 890399407000784897

the id are the same~~~~~~~

calling with time delay, the id changed,
test_id()
time.Sleep(1)
test_id()
time.Sleep(1)
test_id()
time.Sleep(1)
test_id()
time.Sleep(1)

seems the id isn't increased

Base64 should encode bytes rather than string representation of int64

func main() {

	// Create a new Node with a Node number of 1
	node, err := snowflake.NewNode(1)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Generate a snowflake ID.
	id := node.Generate()

	// Print out the ID in a few different ways.
	fmt.Println(id)
	fmt.Println(id.Base64())
	b := id.IntBytes()
	fmt.Println(base64.StdEncoding.EncodeToString(b[:]))
}

result:

-129775853767749632
LTEyOTc3NTg1Mzc2Nzc0OTYzMg==
/jLxjG/AEAA=

dig into souce, i found that base64 method use string representation of int64 for encoding, which make no sense:

// Base64 returns a base64 string of the snowflake ID
func (f ID) Base64() string {
	return base64.StdEncoding.EncodeToString(f.Bytes())
}

// Bytes returns a byte slice of the snowflake ID
func (f ID) Bytes() []byte {
	return []byte(f.String())
}

it only make representation much longer.

生成的ID会重复

func NextIdentity() (int64, error) {
//TODO: NodeID 换成读取配置
node, err := snowflake.NewNode(1)

if err != nil {
	Logger().Info(
		"Generate identity fail.",
		zap.String("error", err.Error()),
	)
}

ID := node.Generate()
return ID.Int64(), nil

}

r.GET("/testOrder", func(c *gin.Context) {
fmt.Println(utils.NextIdentity())
}

ab -c 10 -n 11 http://localhost:8080/testOrder

就在10个并发的时候就会重复

NodeBits & StepBits change

Would it possible that two different nodes created by two different NodeBits produce the same snowflakeID in the same time?

snowflake.NodeBits = 18
snowflake.StepBits = 7
a, _ := snowflake.NewNode(1)

snowflake.NodeBits = 14
snowflake.StepBits = 8
b, _ := snowflake.NewNode(2)

//a.Generate() == b.Generate() ?

Feature request for bulk generation of IDs

Use Case

In cases where a process is constantly processing items, for speed of processing and for database efficiency, it is common practice to batch together records into a bulk insert or group them under one transaction. Usually this improves INSERT query performance due to optimal table locking and fewer index rebuilds; of course it varies from database to database.

In these cases, an ID will have to generate for each record in a batch. In a classic scenario these IDs would be generated by the database itself using sequence or auto-increments. In a distributed environment snowflake IDs would do better.

Proposal

Since snowflake IDs, with the default config, are designed to generate only up to 4096 IDs per millisecond, we need to look at options to increase that while staying within the rules. This can be achieved if the Node can be allowed to overflow slightly allowing to generate IDs "in the future". Any chance of a run-away overflow can be checked using a max-overflow limit.

Version latest released version as v1.0.0

When you download this repo with go get github.com/bwmarrin/snowflake go installs version v0.3.0 to your go.mod. Updating the tag on this repo will enable go to install the latest version instead, which you have to specify currently with v0.3.1-0.20190412223032-c09e69ae5993

The readme states this project is feature complete, and no breaking API changes will be introduced. That's why I suggest v1.0.0 for the current commit.

Short BaseXX

In go-alone the encode/decode methods create a very small Base64 timestamp by removing prefixing zeros and trailing characters. Implement something similar for our snowflake library here.

got same ids from different machines

we got same ids from two machine, code likes below:

`var node *sf.Node
func init_node() (err error) {
node, err = sf.NewNode(1)
if err != nil {
panic("init node failed!")
return
}
return
}

func GenOrderid() {
for {
for i := 0; i < 4000; i++ {
id := node.Generate()
sorderid := strconv.FormatInt(id,10)
if strings.TrimSpace(sorderid) == "" {
continue
}

		orderidchn <- strings.TrimSpace(sorderid)
	}
	time.Sleep(1 * time.Millisecond)
}

}`

Add parsers

We've got many methods to convert a snowflake into different formats but no methods to convert from those formats back into a snowflake. There should be a 1:1 pair for all formats.

Release/Tag v1.0.0

A few months ago Go 1.11 has been released with the concept of modules which allows to fetch a release by tag of the format vX.Y.Z (e.g. v1.0.0). Years before that projects like glide and dep also rely on tags to determine version and ensure safe updates without breaking API changes.

The project status since last year says:

This package should be considered stable and completed. Any additions in the future will strongly avoid API changes to existing functions. Please see issues for any remaining TODO items that are planned.

There are no any TODO items left and since there are no planned API changes I propose to introduce a v1.0.0 tag.

Cached ID?

Thanks for your library.

I wonder if you'd add a cached ID module, it might increase the performance.

Thanks again.

Data race-unsafe use of package-level variables

Global package-level variables are being used unsafely from the perspective of the race detector. For example, trying to use NewNode() and Generate() at the same time will trip the race detector for nodeShift in:

snowflake/snowflake.go:97
snowflake/snowflake.go:132

Steps to reproduce:

  • Run NewNode() and Generate() in parallel, such as via tests using t.Parallel().
  • Use race detector when running tests.

Other package-level variables besides nodeShift may also affected.

Generate unique node ID

The node ID accepts an int between 0~1023.

Is there a way to generate distributed unique or sequential node ID?

Because it's only has 10 bits, it's difficult to generate unique node ID by machine ID or process ID.

Android Log: März 29, 2022 07:23:09 GMT+02:00

--------- beginning of main
I/libc ( 6486): SetHeapTaggingLevel: tag level set to 0
E/org.jtb.alogca( 6486): Not starting debugger since process cannot load the jdwp agent.
D/ActivityThread( 6486): setConscryptValidator
D/ActivityThread( 6486): setConscryptValidator - put
--------- beginning of system
D/ActivityThread( 6486): handleBindApplication()++ app=org.jtb.alogcat
D/ApplicationLoaders( 6486): Returning zygote-cached class loader: /system/framework/android.test.base.jar
I/org.jtb.alogca( 6486): The ClassLoaderContext is a special shared library.
D/LoadedApk( 6486): LoadedApk::makeApplication() appContext=android.app.ContextImpl@a3ee05 appContext.mOpPackageName=org.jtb.alogcat appContext.mBasePackageName=org.jtb.alogcat appContext.mPackageInfo=android.app.LoadedApk@5300e5a
D/NetworkSecurityConfig( 6486): No Network Security Config specified, using platform default
D/NetworkSecurityConfig( 6486): No Network Security Config specified, using platform default
D/ActivityThread( 6486): handleBindApplication() -- skipGraphicsSupport=false
I/DecorView( 6486): [INFO] isPopOver=false, config=true
I/DecorView( 6486): updateCaptionType >> DecorView@615a814[], isFloating=false, isApplication=true, hasWindowDecorCaption=false, hasWindowControllerCallback=true
D/DecorView( 6486): setCaptionType = 0, this = DecorView@615a814[]
D/CompatibilityChangeReporter( 6486): Compat change id reported: 147798919; UID 10264; state: DISABLED
D/Toast ( 6486): show: caller = org.jtb.alogcat.LogActivity.reset:244
I/Toast ( 6486): show: focusDisplayId = 0, isFocusInDesktop = false mCustomDisplayId=-1 isDexDualMode=false
I/Toast ( 6486): show: isActivityContext = true
D/InputTransport( 6486): Input channel constructed: 'b884cf0', fd=68
I/ViewRootImpl@9ea325bLogActivity: setView = com.android.internal.policy.DecorView@615a814 TM=true
V/ToastPresenter( 6486): Text: Sead in android.widget.ToastPresenter@acb7bd1
D/InputTransport( 6486): Input channel constructed: '408387f', fd=62
I/ViewRootImpl@cdd2ea4Toast: setView = android.widget.LinearLayout@53b040d TM=true
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x46adfc2 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/ViewRootImpl@9ea325bLogActivity: Relayout returned: old=(0,0,720,1600) new=(0,0,720,1339) req=(720,1600)0 dur=16 res=0x100007 s={true 482331262976} ch=true fn=-1
D/AbsListView( 6486): in onLayout changed
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x3ba91d3 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/ViewRootImpl@cdd2ea4Toast: Relayout returned: old=(0,43,720,1510) new=(152,1317,568,1390) req=(416,73)0 dur=39 res=0x7 s={true 482331303936} ch=true fn=-1
I/ViewRootImpl@cdd2ea4Toast: MSG_RESIZED_REPORT: frame=(152,1317,568,1390) ci=(0,0,0,0) vi=(0,0,0,0) or=1
I/SurfaceControl( 6486): nativeRelease nativeObject s[482331248352]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482331248352]
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x3ba91d3 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/ViewRootImpl@cdd2ea4Toast: Relayout returned: old=(152,1317,568,1390) new=(152,1317,568,1390) req=(416,73)0 dur=10 res=0x1 s={true 482331303936} ch=false fn=2
I/ViewRootImpl@cdd2ea4Toast: dispatchDetachedFromWindow
I/SurfaceControl( 6486): nativeRelease nativeObject s[482331248736]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482331248736]
D/InputTransport( 6486): Input channel destroyed: '408387f', fd=62
I/org.jtb.alogca( 6486): Thread[5,tid=8737,WaitingInMainSignalCatcherLoop,Thread*=0x704d377000,peer=0x131001e0,"Signal Catcher"]: reacting to signal 28
I/org.jtb.alogca( 6486):
I/org.jtb.alogca( 6486): SIGSAVEPRF profile save
I/ViewRootImpl@9ea325bLogActivity: MSG_WINDOW_FOCUS_CHANGED 1 1
D/InputMethodManager( 6486): prepareNavigationBarInfo() DecorView@615a814[LogActivity]
D/InputMethodManager( 6486): getNavigationBarColor() -855310
D/InputMethodManager( 6486): prepareNavigationBarInfo() DecorView@615a814[LogActivity]
D/InputMethodManager( 6486): getNavigationBarColor() -855310
V/InputMethodManager( 6486): Starting input: tba=org.jtb.alogcat ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
D/InputMethodManager( 6486): startInputInner - Id : 0
I/InputMethodManager( 6486): startInputInner - mService.startInputOrWindowGainedFocus
D/InputTransport( 6486): Input channel constructed: 'ClientS', fd=62
D/InputMethodManager( 6486): prepareNavigationBarInfo() DecorView@615a814[LogActivity]
D/InputMethodManager( 6486): getNavigationBarColor() -855310
V/InputMethodManager( 6486): Starting input: tba=org.jtb.alogcat ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
D/InputMethodManager( 6486): startInputInner - Id : 0
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435343392]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435343392]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435343296]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435343296]
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 0
D/AbsListView( 6486): reportScrollStateChange() newState : 1
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 1
D/AbsListView( 6486): onTouchUp() mTouchMode : 3
D/AbsListView( 6486): reportScrollStateChange() newState : 0
I/SurfaceControl( 6486): nativeRelease nativeObject s[482331246624]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482331246624]
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x46adfc2 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/SurfaceControl( 6486): nativeRelease nativeObject s[484980815808]
I/SurfaceControl( 6486): nativeRelease nativeObject e[484980815808]
I/SurfaceControl( 6486): nativeRelease nativeObject s[484980813888]
I/SurfaceControl( 6486): nativeRelease nativeObject e[484980813888]
I/SurfaceControl( 6486): nativeRelease nativeObject s[484980815712]
I/SurfaceControl( 6486): nativeRelease nativeObject e[484980815712]
I/ViewRootImpl@9ea325bLogActivity: Relayout returned: old=(0,0,720,1339) new=(0,0,720,1339) req=(720,1339)0 dur=32 res=0x100001 s={true 482331262976} ch=false fn=74
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 0
D/AbsListView( 6486): reportScrollStateChange() newState : 1
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 1
D/AbsListView( 6486): onTouchUp() mTouchMode : 3
D/AbsListView( 6486): reportScrollStateChange() newState : 0
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 0
D/AbsListView( 6486): reportScrollStateChange() newState : 1
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 1
D/AbsListView( 6486): onTouchUp() mTouchMode : 3
D/AbsListView( 6486): reportScrollStateChange() newState : 2
D/AbsListView( 6486): reportScrollStateChange() newState : 0
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 0
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 1
D/InputTransport( 6486): Input channel constructed: 'b239d83', fd=64
I/ViewRootImpl@f6adc07PopupWindow:66d2488: setView = android.widget.PopupWindow$PopupDecorView@3f40134 TM=true
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x97a8b5d / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/ViewRootImpl@f6adc07PopupWindow:66d2488: Relayout returned: old=(0,43,720,1510) new=(322,75,720,471) req=(398,396)0 dur=19 res=0x100007 s={true 482266378240} ch=true fn=-1
D/AbsListView( 6486): in onLayout changed
I/SurfaceControl( 6486): nativeRelease nativeObject s[482333131616]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482333131616]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482333131520]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482333131520]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482331246624]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482331246624]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482333134496]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482333134496]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482333134016]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482333134016]
I/ViewRootImpl@9ea325bLogActivity: MSG_WINDOW_FOCUS_CHANGED 0 1
I/ViewRootImpl@f6adc07PopupWindow:66d2488: MSG_RESIZED_REPORT: frame=(322,75,720,471) ci=(0,0,0,0) vi=(0,0,0,0) or=1
I/SurfaceControl( 6486): nativeRelease nativeObject s[482333134304]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482333134304]
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x97a8b5d / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435343584]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435343584]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435343488]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435343488]
I/ViewRootImpl@f6adc07PopupWindow:66d2488: Relayout returned: old=(322,75,720,471) new=(322,75,720,471) req=(398,396)0 dur=19 res=0x100001 s={true 482266378240} ch=false fn=3
I/ViewRootImpl@f6adc07PopupWindow:66d2488: MSG_WINDOW_FOCUS_CHANGED 1 1
I/ViewRootImpl@f6adc07PopupWindow:66d2488: ViewPostIme pointer 0
I/ViewRootImpl@f6adc07PopupWindow:66d2488: ViewPostIme pointer 1
D/AbsListView( 6486): onTouchUp() mTouchMode : 0
I/ViewRootImpl@f6adc07PopupWindow:66d2488: dispatchDetachedFromWindow
I/SurfaceControl( 6486): nativeRelease nativeObject s[482331246624]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482331246624]
D/InputTransport( 6486): Input channel destroyed: 'b239d83', fd=64
I/SurfaceControl( 6486): nativeRelease nativeObject s[484980815904]
I/SurfaceControl( 6486): nativeRelease nativeObject e[484980815904]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482333131520]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482333131520]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482333134304]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482333134304]
I/DecorView( 6486): [INFO] isPopOver=false, config=true
I/DecorView( 6486): updateCaptionType >> DecorView@f671e82[], isFloating=false, isApplication=true, hasWindowDecorCaption=false, hasWindowControllerCallback=true
D/DecorView( 6486): setCaptionType = 0, this = DecorView@f671e82[]
D/InputTransport( 6486): Input channel constructed: 'd6d4df8', fd=67
I/ViewRootImpl@9af172cPrefsActivity: setView = com.android.internal.policy.DecorView@f671e82 TM=true
I/ViewRootImpl@9ea325bLogActivity: MSG_WINDOW_FOCUS_CHANGED 0 1
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0xa475f5 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/ViewRootImpl@9af172cPrefsActivity: Relayout returned: old=(0,0,720,1600) new=(0,0,720,1339) req=(720,1600)0 dur=14 res=0x100007 s={true 482265841664} ch=true fn=-1
D/AbsListView( 6486): in onLayout changed
I/ViewRootImpl@9ea325bLogActivity: MSG_WINDOW_FOCUS_CHANGED 0 1
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435343680]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435343680]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435344352]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435344352]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435343776]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435343776]
I/ViewRootImpl@9af172cPrefsActivity: MSG_WINDOW_FOCUS_CHANGED 1 1
D/InputMethodManager( 6486): prepareNavigationBarInfo() DecorView@f671e82[PrefsActivity]
D/InputMethodManager( 6486): getNavigationBarColor() -855310
D/InputMethodManager( 6486): prepareNavigationBarInfo() DecorView@f671e82[PrefsActivity]
D/InputMethodManager( 6486): getNavigationBarColor() -855310
V/InputMethodManager( 6486): Starting input: tba=org.jtb.alogcat ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
D/InputMethodManager( 6486): startInputInner - Id : 0
I/InputMethodManager( 6486): startInputInner - mService.startInputOrWindowGainedFocus
D/InputTransport( 6486): Input channel constructed: 'ClientS', fd=74
D/InputTransport( 6486): Input channel destroyed: 'ClientS', fd=62
I/SurfaceControl( 6486): nativeRelease nativeObject s[484980816000]
I/SurfaceControl( 6486): nativeRelease nativeObject e[484980816000]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435343584]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435343584]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435344832]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435344832]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482333131424]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482333131424]
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x5abd0b7 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1826 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x46adfc2 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/ViewRootImpl@9ea325bLogActivity: Relayout returned: old=(0,0,720,1339) new=(0,0,720,1339) req=(720,1339)8 dur=30 res=0x100005 s={false 0} ch=true fn=207
I/ViewRootImpl@9ea325bLogActivity: stopped(true) old=false
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x5abd0b7 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1826 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x46adfc2 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/ViewRootImpl@9ea325bLogActivity: Relayout returned: old=(0,0,720,1339) new=(0,0,720,1339) req=(720,1339)8 dur=8 res=0x100005 s={false 0} ch=false fn=-1
I/ViewRootImpl@9af172cPrefsActivity: ViewPostIme pointer 0
D/AbsListView( 6486): reportScrollStateChange() newState : 1
I/ViewRootImpl@9af172cPrefsActivity: ViewPostIme pointer 1
D/AbsListView( 6486): onTouchUp() mTouchMode : 3
D/AbsListView( 6486): reportScrollStateChange() newState : 0
I/ViewRootImpl@9af172cPrefsActivity: ViewPostIme pointer 0
D/AbsListView( 6486): reportScrollStateChange() newState : 1
I/ViewRootImpl@9af172cPrefsActivity: ViewPostIme pointer 1
D/AbsListView( 6486): onTouchUp() mTouchMode : 3
D/AbsListView( 6486): reportScrollStateChange() newState : 0
I/ViewRootImpl@9af172cPrefsActivity: ViewPostIme key 0
I/ViewRootImpl@9af172cPrefsActivity: ViewPostIme key 1
I/ViewRootImpl@9ea325bLogActivity: stopped(false) old=true
I/ViewRootImpl@9ea325bLogActivity: stopped(false) old=false
D/Toast ( 6486): show: caller = org.jtb.alogcat.LogActivity.reset:244
I/Toast ( 6486): show: focusDisplayId = 0, isFocusInDesktop = false mCustomDisplayId=-1 isDexDualMode=false
I/Toast ( 6486): show: isActivityContext = true
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x46adfc2 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/ViewRootImpl@9ea325bLogActivity: Relayout returned: old=(0,0,720,1339) new=(0,0,720,1339) req=(720,1339)0 dur=35 res=0x100007 s={true 482331262976} ch=true fn=-1
V/ToastPresenter( 6486): Text: Sead in android.widget.ToastPresenter@201d42
D/InputTransport( 6486): Input channel constructed: '675f56b', fd=63
I/ViewRootImpl@c6f4f89Toast: setView = android.widget.LinearLayout@296cb8e TM=true
I/ViewRootImpl@9af172cPrefsActivity: MSG_WINDOW_FOCUS_CHANGED 0 1
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0xa0e1faf / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/ViewRootImpl@c6f4f89Toast: Relayout returned: old=(0,43,720,1510) new=(152,1317,568,1390) req=(416,73)0 dur=11 res=0x7 s={true 482265796608} ch=true fn=-1
I/SurfaceControl( 6486): nativeRelease nativeObject s[482333141696]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482333141696]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482333141600]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482333141600]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482333141504]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482333141504]
I/ViewRootImpl@9ea325bLogActivity: MSG_WINDOW_FOCUS_CHANGED 1 1
D/InputMethodManager( 6486): prepareNavigationBarInfo() DecorView@615a814[LogActivity]
D/InputMethodManager( 6486): getNavigationBarColor() -855310
D/InputMethodManager( 6486): prepareNavigationBarInfo() DecorView@615a814[LogActivity]
D/InputMethodManager( 6486): getNavigationBarColor() -855310
V/InputMethodManager( 6486): Starting input: tba=org.jtb.alogcat ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
D/InputMethodManager( 6486): startInputInner - Id : 0
I/InputMethodManager( 6486): startInputInner - mService.startInputOrWindowGainedFocus
D/InputTransport( 6486): Input channel constructed: 'ClientS', fd=71
D/InputTransport( 6486): Input channel destroyed: 'ClientS', fd=74
I/SurfaceControl( 6486): nativeRelease nativeObject s[482333142560]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482333142560]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435345024]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435345024]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435344928]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435344928]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482333134304]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482333134304]
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x604ffbc / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1826 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0xa475f5 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/ViewRootImpl@9af172cPrefsActivity: Relayout returned: old=(0,0,720,1339) new=(0,0,720,1339) req=(720,1339)8 dur=21 res=0x100005 s={false 0} ch=true fn=63
I/ViewRootImpl@9af172cPrefsActivity: stopped(true) old=false
I/ViewRootImpl@9af172cPrefsActivity: dispatchDetachedFromWindow
D/InputTransport( 6486): Input channel destroyed: 'd6d4df8', fd=67
D/InputMethodManager( 6486): prepareNavigationBarInfo() DecorView@615a814[LogActivity]
D/InputMethodManager( 6486): getNavigationBarColor() -855310
V/InputMethodManager( 6486): Starting input: tba=org.jtb.alogcat ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
D/InputMethodManager( 6486): startInputInner - Id : 0
I/InputMethodManager( 6486): startInputInner - mService.startInputOrWindowGainedFocus
D/InputTransport( 6486): Input channel constructed: 'ClientS', fd=67
D/InputTransport( 6486): Input channel destroyed: 'ClientS', fd=71
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 0
D/AbsListView( 6486): reportScrollStateChange() newState : 1
I/ViewRootImpl@c6f4f89Toast: dispatchDetachedFromWindow
I/SurfaceControl( 6486): nativeRelease nativeObject s[482333131424]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482333131424]
D/InputTransport( 6486): Input channel destroyed: '675f56b', fd=63
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 1
D/AbsListView( 6486): onTouchUp() mTouchMode : 3
D/AbsListView( 6486): reportScrollStateChange() newState : 0
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 0
D/AbsListView( 6486): reportScrollStateChange() newState : 1
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 1
D/AbsListView( 6486): onTouchUp() mTouchMode : 3
D/AbsListView( 6486): reportScrollStateChange() newState : 0
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 0
D/AbsListView( 6486): reportScrollStateChange() newState : 1
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 1
D/AbsListView( 6486): onTouchUp() mTouchMode : 3
D/AbsListView( 6486): reportScrollStateChange() newState : 2
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 0
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 1
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435344832]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435344832]
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x46adfc2 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435343680]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435343680]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435343584]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435343584]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435345120]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435345120]
I/ViewRootImpl@9ea325bLogActivity: Relayout returned: old=(0,0,720,1339) new=(0,0,720,1339) req=(720,1339)0 dur=12 res=0x100001 s={true 482331262976} ch=false fn=195
D/AbsListView( 6486): reportScrollStateChange() newState : 0
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267000096]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267000096]
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x46adfc2 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267000192]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267000192]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267000000]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267000000]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435344832]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435344832]
I/ViewRootImpl@9ea325bLogActivity: Relayout returned: old=(0,0,720,1339) new=(0,0,720,1339) req=(720,1339)0 dur=10 res=0x100001 s={true 482331262976} ch=false fn=204
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 0
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 1
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267001152]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267001152]
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x46adfc2 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267001248]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267001248]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267001056]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267001056]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267000096]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267000096]
I/ViewRootImpl@9ea325bLogActivity: Relayout returned: old=(0,0,720,1339) new=(0,0,720,1339) req=(720,1339)0 dur=7 res=0x100001 s={true 482331262976} ch=false fn=223
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 0
I/ViewRootImpl@9ea325bLogActivity: ViewPostIme pointer 1
D/InputTransport( 6486): Input channel constructed: '341a0d9', fd=63
I/ViewRootImpl@bfe5af2PopupWindow:19c55a7: setView = android.widget.PopupWindow$PopupDecorView@42ea543 TM=true
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x308f7c0 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/ViewRootImpl@bfe5af2PopupWindow:19c55a7: Relayout returned: old=(0,43,720,1510) new=(322,75,720,471) req=(398,396)0 dur=11 res=0x100007 s={true 482455334912} ch=true fn=-1
D/AbsListView( 6486): in onLayout changed
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267000192]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267000192]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482435344832]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482435344832]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267001152]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267001152]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267001632]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267001632]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267001536]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267001536]
I/ViewRootImpl@9ea325bLogActivity: MSG_WINDOW_FOCUS_CHANGED 0 1
I/ViewRootImpl@bfe5af2PopupWindow:19c55a7: MSG_RESIZED_REPORT: frame=(322,75,720,471) ci=(0,0,0,0) vi=(0,0,0,0) or=1
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267001440]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267001440]
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x308f7c0 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267002016]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267002016]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267001920]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267001920]
I/ViewRootImpl@bfe5af2PopupWindow:19c55a7: Relayout returned: old=(322,75,720,471) new=(322,75,720,471) req=(398,396)0 dur=11 res=0x100001 s={true 482455334912} ch=false fn=3
I/ViewRootImpl@bfe5af2PopupWindow:19c55a7: MSG_WINDOW_FOCUS_CHANGED 1 1
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267000192]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267000192]
I/SurfaceControl( 6486): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x308f7c0 / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1836 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267001152]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267001152]
I/SurfaceControl( 6486): nativeRelease nativeObject s[482267001440]
I/SurfaceControl( 6486): nativeRelease nativeObject e[482267001440]
I/ViewRootImpl@bfe5af2PopupWindow:19c55a7: Relayout returned: old=(322,75,720,471) new=(322,75,720,471) req=(398,396)0 dur=8 res=0x100001 s={true 482455334912} ch=false fn=5

生成得id都是偶数

低并发情况下末尾重置为0,不便于取余使用问题,建议做个开关判断一下

parsing doesn't consider negative numbers

using ParseBase58 as an example, values should round-trip properly back to their original value, or error.

ok := "npL6MjP8Qfc"   //0x7fffffffffffffff
bad1 := "npL6MjP8Qfd" //0x7fffffffffffffff + 1 // overflows int64 and becomes negative
bad2 := "JPwcyDCgEuq" //0xffffffffffffffff + 1 // overflows uint64 and wraps back to 1
  • in the case of bad1 it parses "successfully" and returns a negative value, which later panics when Base58() cannot convert it back to a string (it doesn't handle negative cases). It should error on parsing, or negatives should be supported throughout (or the base type should be uint64).
  • in the case of bad2 it parses "successfully" and returns a value of 1, which base58() does not encode back to the original number, obviously. it should probably error because the original number is not valid.

These issues can come up when accepting requests with bad IDs from clients, and they should not be accepted as valid ids.

What will happen if generate more than 4096 in 1 millisecond?

Hi,

What will node.Generate() return if it generated more than 4096 (such as 5000) in 1 millisecond?

Will the squeue number reset to 0? or block?

import (
	"fmt"

	"github.com/bwmarrin/snowflake"
)

func main() {
	node, _ := snowflake.NewNode(0)
	m := make(map[int64]bool)
	timeMap := make(map[int64]bool)
	for i := 0; i < 5000; i++ {
		id := node.Generate()
		timeMap[id.Time()] = true
		if _, ok := m[id.Int64()]; ok {
			fmt.Printf("wrong: same id %d", id)
		}
		m[id.Int64()] = true
	}
	fmt.Printf("%+v", timeMap)
}

Thanks!

Data skew in low-concurrency scenarios

Data skew in low-concurrency scenarios

According to the source code, it will set the step to 0 once the time increased, it will cause a problem when we use the id as the sharding key for sharding strategy.
The code affects

if now == n.time {
		n.step = (n.step + 1) & n.stepMask

		if n.step == 0 {
			for now <= n.time {
				now = time.Since(n.epoch).Nanoseconds() / 1000000
			}
		}
	} else {
		n.step = 0
	}

Consider the following circumstance:

Scenario

  1. table:order_tab_00000000-order_tab_00001000;
  2. An api for user to create new order: create_order;
  3. use the above logic to generate id when QPS is less than 10;

Impact

  1. After calculating with mod all of the result of id generated will be less than 10, which means most of the records will be stored into order_tab_00000000-order_tab_00000009, it caused data skew;

Improve

  1. Make the step round by round, and do not set it to 0;

Code May be referenced

	n.mu.Lock()
	now := time.Since(n.epoch).Nanoseconds() / 1000000
	n.step = (n.step + 1) & n.stepMask
	if now == n.time && n.step == 0 {
		for now <= n.time {
			now = time.Since(n.epoch).Nanoseconds() / 1000000
		}
	}
	n.time = now
	r := ID((now)<<n.timeShift |
		(n.node << n.nodeShift) |
		(n.step),
	)
	n.mu.Unlock()
	return r

Check for clock drift

The current implementation does not check for clock drift when generating snowflakes. This would be fairly easy to implement a basic check, however I think the cleanest way would be to change the Generate() function signature to return an error as well.

I understand this is a breaking API change you may not want. I am wondering if you are open to this change in any form. This could be breaking the API, deploying versioned packages with something like gopkg.in, creating a new API, etc...

Let me know what you think.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.