Xmpp Vs Websocket(Xmpp Vs Websocket)
我即将开发一个即时聊天的网站。 我知道它可以使用xmpp或websocket协议实现。 我也知道xmpp协议是在1999年开发的,我想今天应该是成熟的。另一方面,websocket协议是在2011年开发的。
- 如果xmpp处理实时对话,那么需要websocket?
- 两种协议之间的主要区别是什么?
- 我应该什么时候选择其中一个?
I'm about to develop a website that has near real time chat. I know that it can be implemented using xmpp or websocket protocols. I know also that the xmpp protocol has been developed in 1999 , and I guess it should be mature nowadays .On the other hand , the websocket protocol has been developed in 2011.
- What was the need for websocket if xmpp was good in handling real time conversations?
- What are the major differences between the 2 protocols?
- And when should I choose one of them over the other?
原文:https://stackoverflow.com/questions/26549010
最满意答案
当速度至关重要时,SQL case语句甚至可能是最快的(我将运行测试)但是为了可维护性,将普通值返回到表示层(或某些业务层)是最佳选择。
[update]运行了一些快速而肮脏的测试(下面的代码),发现C#代码变体比SQL case变体略快。 结论:返回“原始”数据并在表示层中对其进行操作既更快又更易于维护。
-Edoode
我在下面查询了196288行。
StringBuilder result = new StringBuilder(); using (SqlConnection conn = new SqlConnection(Settings.Default.Conn)) { conn.Open(); string cmd = "select [state], case [state] when 'ca' then 'california' else [state] end from member"; SqlCommand command = new SqlCommand(cmd, conn); using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection)) { while (reader.Read()) { result.AppendLine(reader.GetString(1)); } } }
C#变种:
StringBuilder result = new StringBuilder(); using (SqlConnection conn = new SqlConnection(Settings.Default.Conn)) { conn.Open(); string cmd = "select [state] from member"; SqlCommand command = new SqlCommand(cmd, conn); using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection)) { while (reader.Read()) { result.AppendLine(reader.GetString(0) == "ca" ? "california" : reader.GetString(0)); } }
}
When speed is of the essence, the SQL case statements might even be the fastest (I'll run a test) but for maintainability, returning the plain values to the presentation layer (or some business layer thingy) is the best option.
[update] ran some quick and dirty tests (code below) and found the C# code variant slightly faster than the SQL case variant. Conclusion: returning the 'raw' data and manipulating it in the presentation layer is both quicker and more maintainable.
-Edoode
I retrieved 196288 rows with queries below.
StringBuilder result = new StringBuilder(); using (SqlConnection conn = new SqlConnection(Settings.Default.Conn)) { conn.Open(); string cmd = "select [state], case [state] when 'ca' then 'california' else [state] end from member"; SqlCommand command = new SqlCommand(cmd, conn); using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection)) { while (reader.Read()) { result.AppendLine(reader.GetString(1)); } } }
C# variant:
StringBuilder result = new StringBuilder(); using (SqlConnection conn = new SqlConnection(Settings.Default.Conn)) { conn.Open(); string cmd = "select [state] from member"; SqlCommand command = new SqlCommand(cmd, conn); using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection)) { while (reader.Read()) { result.AppendLine(reader.GetString(0) == "ca" ? "california" : reader.GetString(0)); } }
}
相关问答
更多-
哪个条件导致行在连接中匹配并不重要。 在连接中使用case表达式有合理的理由,但我认为你只是想or你的条件,然后使用case表达式输出匹配的排名原因。 SELECT *, CASE WHEN
THEN 1 WHEN THEN 2 END as match_code FROM T LEFT OUTER JOIN J ON or 我不知道从Excel中有关“嵌套INDEX / MATCH”的图片。 如果我在 ... -
SQL CASE语句与编程语言中的条件语句(SQL CASE Statement Versus Conditional Statements In Programming Language)[2022-11-28]
当速度至关重要时,SQL case语句甚至可能是最快的(我将运行测试)但是为了可维护性,将普通值返回到表示层(或某些业务层)是最佳选择。 [update]运行了一些快速而肮脏的测试(下面的代码),发现C#代码变体比SQL case变体略快。 结论:返回“原始”数据并在表示层中对其进行操作既更快又更易于维护。 -Edoode 我在下面查询了196288行。 StringBuilder result = new StringBuilder(); using (SqlConnection conn = new S ... -
如果可以假设在相对较短的时间范围内需要多个条件,则可维护性。 几乎是我能想出来的唯一原因;) Maintainability if one can assume tha more than one condition will be needed over a relatively short timeframe. Pretty much the only reason I can come up with ;)
-
sql - 带有CASE语句的条件WHERE子句的问题(sql - problems with conditional WHERE clause with CASE statement)[2023-07-10]
一些注意事项:不确定为什么需要PL / SQL,这似乎是你应该能够在标准SQL中做的事情。 在CASE语句中,您使用:=在一个地方,即PL / SQL赋值运算符 - 您可能希望测试它是否相等。 最后,您不需要CASE构造 - 您的WHERE子句可以这样陈述: ... where (pi_region_id = 52) or (pi_region_id = 51 and i.hrcc_id is null) or (pi_region_id != 51 and i.hrcc_id = pi_region ... -
你真的不需要这种情况,它只会使你的查询变得复杂。 您可以像使用AND / OR一样简单地完成 SELECT DISTINCT PatientID, PatientAge, ProcedureCode, CodeDescription, ServiceDate, RenderingProvider, VisitType FROM ServiceDetail WHERE (ProcedureCode = '1234' and ServiceDate ...
-
你需要一个复合语句 : create function ... begin if (custid = 0) then return select customerid from customer; else return select customerid from orderdone; end if; end You'll need a compound statement: create function ... begin if (custid = 0) then ...
-
使用union all : with Test_tbl as ( select * from Test_Persons_A where upper(:TEST_TBL) = 'TEST_PERSONS_A' union all select * from Test_Persons_B where UPPER(:TEST_TBL) = 'TEST_PERSONS_B' ) 这假设表具有相同顺序的相同列。 如果它们 ...
-
试一试:您必须根据您的要求制定两个单独的条件并记住开始时间,您只能启动CASE作为WHERE a = CASE而不是WHERE CASE ...THEN a = b+c ...或者在这种情况下,我会建议使用动态查询,根据不同的条件很容易操作查询 WHERE convert(varchar,dt_start,103) = CASE WHEN Substring(datename(dw,getdate()),1,3) = 'mon' THEN convert(varchar,datea ...
-
是的,案例陈述的顺序很重要。 第一个匹配的行将是返回的行。 所以,这句话: (CASE WHEN phone = '(202) 555-5555' AND last_name = 'Smith' and first_name = 'John' THEN 1 WHEN phone = '(202) 555-5555' AND last_name = 'Smith' THEN 2 WHEN phone = '(202) 555-5555' THEN 3 END) 可以返回1,2或3( ...
-
据推测,这是你正在努力理解的部分: select deptno, sum(case when jobname = 'Analyst' then 1 else 0 end) as numAnalysts from employees group by deptno 这是一个简单的聚合查询。 查询的作用是: 查看employees每一行 如果jobname是'Analyst'则赋值为1 (这是case语句. Otherwise, assign a value of 0`。 按部门 ...