ವಿತರಣಾ ವ್ಯವಸ್ಥೆಗಳಲ್ಲಿ ಬಳಸುವ ವಿಶಿಷ್ಟ 64-ಬಿಟ್ ಗುರುತಿಸುವಿಕೆಯನ್ನು, ಟ್ವಿಟ್ಟರ್ ಸ್ನೋಫ್ಲೇಕ್ ಐಡಿಗಳನ್ನು ರಚಿಸಿ ಮತ್ತು ವಿಶ್ಲೇಷಿಸಿ. ಈ ಸಾಧನವು ನಿಮಗೆ ಹೊಸ ಸ್ನೋಫ್ಲೇಕ್ ಐಡಿಗಳನ್ನು ರಚಿಸಲು ಮತ್ತು ಅಸ್ತಿತ್ವದಲ್ಲಿರುವ ಐಡಿಗಳನ್ನು ಪಾರ್ಸ್ ಮಾಡಲು ಅನುಮತಿಸುತ್ತದೆ, ಅವುಗಳ ಟೈಮ್ಸ್ಟ್ಯಾಂಪ್, ಯಂತ್ರ ಐಡಿ ಮತ್ತು ಕ್ರಮ ಸಂಖ್ಯೆ ಘಟಕಗಳ ಬಗ್ಗೆ ಮಾಹಿತಿ ನೀಡುತ್ತದೆ.
ಸ್ನೋಫ್ಲೇಕ್ ID ಜನರೇಟರ್ ವಿತರಣಾ ವ್ಯವಸ್ಥೆಗಳಿಗೆ ವಿಶಿಷ್ಟ ಗುರುತಿಗಳನ್ನು ರಚಿಸುತ್ತದೆ, ಇದು ದೊಡ್ಡ ಪ್ರಮಾಣದ ಡೇಟಾ ಪ್ರಕ್ರಿಯೆಗಾಗಿಯೇ ಟ್ವಿಟರ್ ಮೂಲಕ ಅಭಿವೃದ್ಧಿಪಡಿಸಲಾಗಿದೆ. ಈ ಶಕ್ತಿಯುತ ವಿಶಿಷ್ಟ ID ಜನರೇಟರ್ ಟೈಮ್ಸ್ಟ್ಯಾಂಪ್, ಯಂತ್ರ ID ಮತ್ತು ಕ್ರಮ ಸಂಖ್ಯೆಯನ್ನು ಒಳಗೊಂಡ 64-ಬಿಟ್ ಪೂರ್ಣಾಂಕಗಳನ್ನು ಉತ್ಪಾದಿಸುತ್ತದೆ, ಇದು ವಿತರಣಾ ವ್ಯವಸ್ಥೆಗಳಲ್ಲಿ ವಿಶಿಷ್ಟತೆಯನ್ನು ಖಚಿತಪಡಿಸುತ್ತದೆ ಮತ್ತು ಸರ್ವರ್ಗಳ ನಡುವಿನ ಸಹಕಾರವನ್ನು ಅಗತ್ಯವಿಲ್ಲ.
ನಮ್ಮ ಉಚಿತ ಆನ್ಲೈನ್ ಸ್ನೋಫ್ಲೇಕ್ ID ಜನರೇಟರ್ ಸಾಧನವು ನಿಮಗೆ ಸ್ನೋಫ್ಲೇಕ್ IDs ಅನ್ನು ತಕ್ಷಣ ಉತ್ಪಾದಿಸಲು ಮತ್ತು ಪಾರ್ಸ್ ಮಾಡಲು ಅನುಮತಿಸುತ್ತದೆ, ಇದು ಮೈಕ್ರೋಸರ್ವಿಸ್ಗಳು, ವಿತರಣಾ ಡೇಟಾಬೇಸ್ಗಳು ಮತ್ತು ಹೆಚ್ಚಿನ ಥ್ರೂಪುಟ್ ಅಪ್ಲಿಕೇಶನ್ಗಳೊಂದಿಗೆ ಕೆಲಸ ಮಾಡುವ ಅಭಿವೃದ್ಧಿಕಾರರಿಗೆ ಪರಿಪೂರ್ಣವಾಗಿದೆ.
ಸ್ನೋಫ್ಲೇಕ್ IDs 64-ಬಿಟ್ ಪೂರ್ಣಾಂಕಗಳಾಗಿದ್ದು, ವಿಶಿಷ್ಟತೆಯನ್ನು ಖಚಿತಪಡಿಸುವಂತೆ ವಿನ್ಯಾಸಗೊಳಿಸಲಾಗಿದೆ:
ಈ ವಿತರಣಾ ID ರಚನೆ ಪ್ರತಿ ಯಂತ್ರಕ್ಕೆ ಸುಮಾರು 4,096 ವಿಶಿಷ್ಟ IDs ಅನ್ನು ಪ್ರತಿಮಿಲಿಸೆಕೆಂಡಿಗೆ ಉತ್ಪಾದಿಸಲು ಅನುಮತಿಸುತ್ತದೆ, ಇದು ಹೆಚ್ಚಿನ ಥ್ರೂಪುಟ್ ವಿತರಣಾ ವ್ಯವಸ್ಥೆಗಳಿಗೆ ಪರಿಪೂರ್ಣವಾಗಿದೆ.
ವಿಶಿಷ್ಟ ಸ್ನೋಫ್ಲೇಕ್ IDs ಅನ್ನು ಉತ್ಪಾದಿಸಲು ಈ ಸರಳ ಹಂತಗಳನ್ನು ಅನುಸರಿಸಿ:
ಸ್ನೋಫ್ಲೇಕ್ ID ಅನ್ನು ಡಿಕೋಡ್ ಮಾಡಲು, "Parse ID" ಕ್ಷೇತ್ರದಲ್ಲಿ ಅದನ್ನು ನಮೂದಿಸಿ ಮತ್ತು ಟೈಮ್ಸ್ಟ್ಯಾಂಪ್, ಯಂತ್ರ ID ಮತ್ತು ಕ್ರಮ ಘಟಕಗಳನ್ನು ನೋಡಲು "Parse" ಕ್ಲಿಕ್ ಮಾಡಿ.
ಸ್ನೋಫ್ಲೇಕ್ ID ಅಲ್ಗಾರಿದಮ್ ಬಿಟ್ವೈಸ್ ಕಾರ್ಯಾಚರಣೆಗಳನ್ನು ಬಳಸಿಕೊಂಡು ವಿಶಿಷ್ಟ ಗುರುತಿಗಳನ್ನು ನಿರ್ಮಿಸುತ್ತದೆ:
1ID = (timestamp << 22) | (datacenterId << 17) | (workerId << 12) | sequence
2
ಸೂತ್ರದ ಘಟಕಗಳು:
timestamp
: ಎಪೋಕ್ನಿಂದ ಮಿಲಿಸೆಕೆಂಡುಗಳ ಸಂಖ್ಯೆಯುdatacenterId
: ಡೇಟಾ ಕೇಂದ್ರವನ್ನು ಗುರುತಿಸುವ 5-ಬಿಟ್ ಪೂರ್ಣಾಂಕ (0-31)workerId
: ಕಾರ್ಮಿಕ ಯಂತ್ರವನ್ನು ಗುರುತಿಸುವ 5-ಬಿಟ್ ಪೂರ್ಣಾಂಕ (0-31)sequence
: ಪ್ರತಿಮಿಲಿಸೆಕೆಂಡಿಗೆ ಹಲವಾರು IDs ಗೆ 12-ಬಿಟ್ ಪೂರ್ಣಾಂಕ (0-4095)ಸ್ನೋಫ್ಲೇಕ್ ID ಉತ್ಪಾದನಾ ಅಲ್ಗಾರಿದಮ್ ಈ ಖಚಿತ ಹಂತಗಳನ್ನು ಅನುಸರಿಸುತ್ತದೆ:
ಈ ಪ್ರಕ್ರಿಯೆ ಪ್ರತಿ ಯಂತ್ರದಲ್ಲಿ ಏಕಕಾಲದಲ್ಲಿ ಹೆಚ್ಚುತ್ತಿರುವ IDs ಅನ್ನು ಖಚಿತಪಡಿಸುತ್ತದೆ ಮತ್ತು ವಿತರಣಾ ವ್ಯವಸ್ಥೆಗಳಲ್ಲಿ ಜಾಗತಿಕ ವಿಶಿಷ್ಟತೆಯನ್ನು ಕಾಪಾಡುತ್ತದೆ.
ಸ್ನೋಫ್ಲೇಕ್ IDs ವಿವಿಧ ವಿತರಣಾ ಗಣಕಶಾಸ್ತ್ರದ ದೃಶ್ಯಗಳಲ್ಲಿ ಉತ್ತಮವಾಗಿವೆ:
ಸ್ನೋಫ್ಲೇಕ್ IDs ಶಕ್ತಿಯುತವಾಗಿದ್ದರೂ, ಇತರ ವಿಶಿಷ್ಟ ID ಉತ್ಪಾದನಾ ವ್ಯವಸ್ಥೆಗಳು ಒಳಗೊಂಡಿವೆ:
ಸ್ನೋಫ್ಲೇಕ್ ID ಮಿತಿಗಳನ್ನು ಅರ್ಥಮಾಡಿಕೊಳ್ಳುವುದು ಸರಿಯಾದ ಕಾರ್ಯಗತಗೊಳಣೆಗೆ ಸಹಾಯ ಮಾಡುತ್ತದೆ:
ಸ್ನೋಫ್ಲೇಕ್ IDs ಅನ್ನು ಟ್ವಿಟರ್ 2010ರಲ್ಲಿ ವಿತರಣಾ, ಕಾಲ-ವರ್ಗೀಕರಿಸುವ ವಿಶಿಷ್ಟ ಗುರುತಿಗಳನ್ನು ಉತ್ಪಾದಿಸುವ ಸವಾಲುಗಳನ್ನು ಪರಿಹರಿಸಲು ಪರಿಚಯಿಸಲಾಯಿತು. ಟ್ವಿಟರ್ನ ಬಳಕೆದಾರರ ಆಧಾರ ಮತ್ತು ಟ್ವೀಟ್ ಪ್ರಮಾಣವು ಉಲ್ಬಣಗೊಂಡಾಗ, ಪರಂಪರಾ ಆಟೋ-ಇನ್ಕ್ರಿಮೆಂಟಿಂಗ್ IDs ಅವರ ವಿತರಣಾ ವಾಸ್ತುಶಿಲ್ಪಕ್ಕೆ ಸಾಕಷ್ಟು ಆಗಲಿಲ್ಲ.
ಈ ವ್ಯವಸ್ಥೆಯನ್ನು ಇನ್ಸ್ಟಾಗ್ರಾಮ್, ಡಿಸ್ಕಾರ್ಡ್ ಮತ್ತು ವಿತರಣಾ ವ್ಯವಸ್ಥೆಗಳಿಗೆ ಶ್ರೇಣೀಬದ್ಧ ID ಉತ್ಪಾದನೆ ಅಗತ್ಯವಿರುವ ಅನೇಕ ಇತರ ವೇದಿಕೆಗಳಂತಹ ಪ್ರಮುಖ ತಂತ್ರಜ್ಞಾನ ಕಂಪನಿಗಳು ಸ್ವೀಕರಿಸಿವೆ.
ನಿಮ್ಮ ಇಚ್ಛಿತ ಪ್ರೋಗ್ರಾಮಿಂಗ್ ಭಾಷೆಯಲ್ಲಿ ಸ್ನೋಫ್ಲೇಕ್ ID ಉತ್ಪಾದನೆಯನ್ನು ಕಾರ್ಯಗತಗೊಳಿಸಿ:
1class SnowflakeGenerator {
2 constructor(epoch = 1288834974657, datacenterIdBits = 5, workerIdBits = 5, sequenceBits = 12) {
3 this.epoch = BigInt(epoch);
4 this.datacenterIdBits = datacenterIdBits;
5 this.workerIdBits = workerIdBits;
6 this.sequenceBits = sequenceBits;
7 this.maxDatacenterId = -1n ^ (-1n << BigInt(datacenterIdBits));
8 this.maxWorkerId = -1n ^ (-1n << BigInt(workerIdBits));
9 this.sequenceMask = -1n ^ (-1n << BigInt(sequenceBits));
10 this.workerIdShift = BigInt(sequenceBits);
11 this.datacenterIdShift = BigInt(sequenceBits + workerIdBits);
12 this.timestampLeftShift = BigInt(sequenceBits + workerIdBits + datacenterIdBits);
13 this.sequence = 0n;
14 this.lastTimestamp = -1n;
15 }
16
17 nextId(datacenterId, workerId) {
18 let timestamp = this.currentTimestamp();
19
20 if (timestamp < this.lastTimestamp) {
21 throw new Error('Clock moved backwards. Refusing to generate id');
22 }
23
24 if (timestamp === this.lastTimestamp) {
25 this.sequence = (this.sequence + 1n) & this.sequenceMask;
26 if (this.sequence === 0n) {
27 timestamp = this.tilNextMillis(this.lastTimestamp);
28 }
29 } else {
30 this.sequence = 0n;
31 }
32
33 this.lastTimestamp = timestamp;
34
35 return ((timestamp - this.epoch) << this.timestampLeftShift) |
36 (BigInt(datacenterId) << this.datacenterIdShift) |
37 (BigInt(workerId) << this.workerIdShift) |
38 this.sequence;
39 }
40
41 tilNextMillis(lastTimestamp) {
42 let timestamp = this.currentTimestamp();
43 while (timestamp <= lastTimestamp) {
44 timestamp = this.currentTimestamp();
45 }
46 return timestamp;
47 }
48
49 currentTimestamp() {
50 return BigInt(Date.now());
51 }
52}
53
54// Usage
55const generator = new SnowflakeGenerator();
56const id = generator.nextId(1, 1);
57console.log(`Generated Snowflake ID: ${id}`);
58
1import time
2import threading
3
4class SnowflakeGenerator:
5 def __init__(self, datacenter_id, worker_id, sequence=0):
6 self.datacenter_id = datacenter_id
7 self.worker_id = worker_id
8 self.sequence = sequence
9
10 self.last_timestamp = -1
11 self.epoch = 1288834974657
12
13 self.datacenter_id_bits = 5
14 self.worker_id_bits = 5
15 self.sequence_bits = 12
16
17 self.max_datacenter_id = -1 ^ (-1 << self.datacenter_id_bits)
18 self.max_worker_id = -1 ^ (-1 << self.worker_id_bits)
19
20 self.worker_id_shift = self.sequence_bits
21 self.datacenter_id_shift = self.sequence_bits + self.worker_id_bits
22 self.timestamp_left_shift = self.sequence_bits + self.worker_id_bits + self.datacenter_id_bits
23 self.sequence_mask = -1 ^ (-1 << self.sequence_bits)
24
25 self._lock = threading.Lock()
26
27 def _til_next_millis(self, last_timestamp):
28 timestamp = self._get_timestamp()
29 while timestamp <= last_timestamp:
30 timestamp = self._get_timestamp()
31 return timestamp
32
33 def _get_timestamp(self):
34 return int(time.time() * 1000)
35
36 def next_id(self):
37 with self._lock:
38 timestamp = self._get_timestamp()
39
40 if timestamp < self.last_timestamp:
41 raise ValueError("Clock moved backwards. Refusing to generate id")
42
43 if timestamp == self.last_timestamp:
44 self.sequence = (self.sequence + 1) & self.sequence_mask
45 if self.sequence == 0:
46 timestamp = self._til_next_millis(self.last_timestamp)
47 else:
48 self.sequence = 0
49
50 self.last_timestamp = timestamp
51
52 return ((timestamp - self.epoch) << self.timestamp_left_shift) | \
53 (self.datacenter_id << self.datacenter_id_shift) | \
54 (self.worker_id << self.worker_id_shift) | \
55 self.sequence
56
57## Usage
58generator = SnowflakeGenerator(datacenter_id=1, worker_id=1)
59snowflake_id = generator.next_id()
60print(f"Generated Snowflake ID: {snowflake_id}")
61
1import java.util.concurrent.locks.Lock;
2import java.util.concurrent.locks.ReentrantLock;
3
4public class SnowflakeGenerator {
5 private final long epoch;
6 private final long datacenterIdBits;
7 private final long workerIdBits;
8 private final long sequenceBits;
9 private final long maxDatacenterId;
10 private final long maxWorkerId;
11 private final long workerIdShift;
12 private final long datacenterIdShift;
13 private final long timestampLeftShift;
14 private final long sequenceMask;
15
16 private long datacenterId;
17 private long workerId;
18 private long sequence = 0L;
19 private long lastTimestamp = -1L;
20
21 private final Lock lock = new ReentrantLock();
22
23 public SnowflakeGenerator(long datacenterId, long workerId) {
24 this.epoch = 1288834974657L;
25 this.datacenterIdBits = 5L;
26 this.workerIdBits = 5L;
27 this.sequenceBits = 12L;
28
29 this.maxDatacenterId = ~(-1L << datacenterIdBits);
30 this.maxWorkerId = ~(-1L << workerIdBits);
31
32 this.workerIdShift = sequenceBits;
33 this.datacenterIdShift = sequenceBits + workerIdBits;
34 this.timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
35 this.sequenceMask = ~(-1L << sequenceBits);
36
37 if (datacenterId > maxDatacenterId || datacenterId < 0) {
38 throw new IllegalArgumentException("datacenterId can't be greater than maxDatacenterId or less than 0");
39 }
40 if (workerId > maxWorkerId || workerId < 0) {
41 throw new IllegalArgumentException("workerId can't be greater than maxWorkerId or less than 0");
42 }
43 this.datacenterId = datacenterId;
44 this.workerId = workerId;
45 }
46
47 public long nextId() {
48 lock.lock();
49 try {
50 long timestamp = timeGen();
51 if (timestamp < lastTimestamp) {
52 throw new RuntimeException("Clock moved backwards. Refusing to generate id");
53 }
54
55 if (lastTimestamp == timestamp) {
56 sequence = (sequence + 1) & sequenceMask;
57 if (sequence == 0) {
58 timestamp = tilNextMillis(lastTimestamp);
59 }
60 } else {
61 sequence = 0L;
62 }
63
64 lastTimestamp = timestamp;
65
66 return ((timestamp - epoch) << timestampLeftShift) |
67 (datacenterId << datacenterIdShift) |
68 (workerId << workerIdShift) |
69 sequence;
70 } finally {
71 lock.unlock();
72 }
73 }
74
75 private long tilNextMillis(long lastTimestamp) {
76 long timestamp = timeGen();
77 while (timestamp <= lastTimestamp) {
78 timestamp = timeGen();
79 }
80 return timestamp;
81 }
82
83 private long timeGen() {
84 return System.currentTimeMillis();
85 }
86
87 public static void main(String[] args) {
88 SnowflakeGenerator generator = new SnowflakeGenerator(1, 1);
89 long id = generator.nextId();
90 System.out.println("Generated Snowflake ID: " + id);
91 }
92}
93
require 'time' class SnowflakeGenerator def initialize(datacenter_id, worker_id, sequence = 0) @
ನಿಮ್ಮ ಕೆಲಸದ ಹಂತಕ್ಕೆ ಉಪಯೋಗಿಸಬಹುದಾದ ಹೆಚ್ಚು ಉಪಕರಣಗಳನ್ನು ಹುಡುಕಿ ಹೊಸ ಉಪಕರಣಗಳನ್ನು ಕಂಡುಹಿಡಿಯಿರಿ